2020-01-04 17:26:30 +10:00
|
|
|
function deleteFromCart(t){$.ajax({method:"POST",url:"/product/removefromcart",data:{productId:t.attr("data-id")}}).done(function(t){showNotification(t.message,"success"),updateCartDiv()}).fail(function(t){showNotification(t.responseJSON.message,"danger")})}function cartUpdate(t){$(t).val()>0?""!==$(t).val()&&updateCart(t):$(t).val(1)}function updateCart(t){$.ajax({method:"POST",url:"/product/updatecart",data:{productId:t.attr("data-id"),quantity:t.val()}}).done(function(t){updateCartDiv()}).fail(function(t){showNotification(t.responseJSON.message,"danger",!0)})}function getSelectedOptions(){var t={};return $(".product-opt").each(function(){var a=$(this).val().trim(),e=$(this).attr("data-label"),n=$(this).attr("name"),o=$(this).attr("type");o||(t[n]={label:e,name:n,value:a}),"radio"===o&&(t[n]={label:e,name:n,value:$('input[name="'+n+'"]:checked').val()}),"checkbox"===o&&(t[n]={label:e,name:n,value:$('input[name="'+$(this).attr("name")+'"]').is(":checked")})}),t}function updateCartDiv(){$.ajax({method:"GET",url:"/checkout/cartdata"}).done(function(t){var a=t.cart,e=t.session,n="",o=numeral(e.totalCartAmount).format("0.00"),i=numeral(e.totalCartShipping).format("0.00"),r=`${e.shippingMessage} :<strong id="shipping-amount">${t.currencySymbol}${i}</strong>`;0===e.totalCartShipping&&(r=`<span id="shipping-amount">${e.shippingMessage}</span>`),a?($("#cart-empty").empty(),Object.keys(a).forEach(function(e){var o=a[e],i=numeral(o.totalItemPrice).format("0.00"),r="",s=1;Object.keys(o.options).forEach(function(t){var a=o.options[t];s===Object.keys(o.options).length?r+=`<strong>${upperFirst(a.name)}</strong>: ${a.value}`:r+=`<strong>${upperFirst(a.name)}</strong>: ${a.value} / `,s++});var c=`<img class="img-fluid" src="/uploads/placeholder.png" alt="${o.title} product image"></img>`;o.productImage&&(c=`<img class="img-fluid" src="${o.productImage}" alt="${o.title} product image"></img>`),n+=`\n <div class="d-flex flex-row bottom-pad-15">\n <div class="col-4 col-md-3">\n ${c}\n </div>\n <div class="col-12 col-md-7">\n <div class="row h-200">\n <div class="col-sm-12 text-left no-pad-left">\n <h6><a href="/product/${o.link}">${o.title}</a></h6>\n </div>\n <div class="col-sm-12 text-left no-pad-left">\n ${r}\n </div>\n <div class="col-md-8 no-pad-left">\n <div class="input-group">\n <div class="input-group-prepend">\n <button class="btn btn-outline-primary btn-qty-minus" type="button">-</button>\n </div>\n <input type="number" class="form-control cart-product-quantity text-center" id="${e}-qty" data-id="${e}" maxlength="2" value="${o.quantity}">\n <div class="input-group-append">\n <button class="btn btn-outline-primary btn-qty-add" type="button">+</button>\n </div>\n </div>\n </div>\n <div class="col-md-4 text-right">\n <button class="btn btn-outline-danger btn-delete-from-cart" data-id="${e}" type="button"><i class="far fa-trash-alt" data-id="${e}" aria-hidden="true"></i></button>\n </div>\n </div>\n </div>\n <div class="col-12 col-md-2 align-self-center text-right no-pad-right">\n <strong class="my-auto">${t.currencySymbol}${i}</strong>\n </div>\n </div>`}),$(".cartBodyWrapper").html(n),$("#cart-count").text(e.totalCartItems)):$(".cartBodyWrapper").html("");var s=`\n <div clas
|