Items)' + '
' + '
'; } else { bocNewCartContainer.innerHTML = '
' + '
' + '
' + '
'; } // Appending new cart container oldCartcontainer.querySelector(".products-region") && bocNewCartContainer.querySelector(".boc_product_div").appendChild(oldCartcontainer.querySelector(".products-region")); oldCartcontainer.querySelector(".shoppingCart-promotion-section") && bocNewCartContainer.querySelector(".boc_checkout_div").appendChild(oldCartcontainer.querySelector(".shoppingCart-promotion-section")); oldCartcontainer.insertAdjacentElement("afterbegin", bocNewCartContainer); // console.log(document.querySelector(".boc_checkout_div")); // Product div heading var productSubheader = bocBasketPageRevamp.createElem("div", "boc_product_subheader"); productSubheader.innerHTML = '
Full Quantity
' + '
Return
' + '
Total Price
'; bocNewCartContainer.querySelector(".boc_product_div .gas-products-heading") && bocNewCartContainer.querySelector(".boc_product_div .gas-products-heading").appendChild(productSubheader.cloneNode(true)); bocNewCartContainer.querySelector(".boc_product_div .equipments-products-heading") && bocNewCartContainer.querySelector(".boc_product_div .equipments-products-heading").appendChild(productSubheader.cloneNode(true)); bocNewCartContainer.querySelector(".boc_product_div .eLearning-products-heading") && bocNewCartContainer.querySelector(".boc_product_div .eLearning-products-heading").appendChild(productSubheader.cloneNode(true)); bocNewCartContainer.querySelector(".boc_product_div .eLearning-products-heading>h1").innerText = "Services"; }, hideQuants: function() { bocBasketPageRevamp.waitForElement([".data-quantity-section", ".data-return-section"], function() { // console.log("Quants are hiddnen!"); document.querySelectorAll(".data-quantity-section").forEach(function(item) { item.classList.add("hide_boc"); }); document.querySelectorAll(".data-return-section").forEach(function(item) { item.classList.add("hide_boc"); }); }); }, clickDltBtn: function() { bocBasketPageRevamp.waitForElement(".productView .detete", function() { document.querySelectorAll(".productView .detete").forEach(function(elem) { elem.addEventListener("click", function() { // console.log("Delete clicked !"); (function() { var send = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function() { this.addEventListener('load', function(e) { if (this.responseURL.match(/shop\/MiniShopCartView/i)) { setTimeout(() => { // If there are items in the basket if (document.querySelector(".badge.data-order-item-count")) { var itemQuants = document.querySelector(".badge.data-order-item-count").innerText; // console.log("itemQuants", typeof itemQuants, itemQuants); itemQuants = parseInt(itemQuants); document.querySelector(".boc_product_header span").innerText = itemQuants; if (parseInt(itemQuants) > 1) { document.querySelector(".boc_item_text").innerText = "Items"; } else { document.querySelector(".boc_item_text").innerText = "Item"; } // Calling Product and checkout view function bocBasketPageRevamp.productViewFunc(); bocBasketPageRevamp.checkoutViewFunc(); } else { // If there is no item in the basket document.querySelector(".boc_delivery_costs").style.display = "none"; document.querySelector(".boc_product_header").style.display = "none"; document.querySelector(".row.shoppingCart-title-marketingSpot").style.display = "block"; document.querySelector(".row.shoppingCart-title-marketingSpot").after(document.querySelector(".boc_quick_add")); document.querySelector(".boc_quick_add").after(document.querySelector(".quickadd-region")); document.querySelector(".boc_quick_add").addEventListener("click", function() { document.querySelector(".quickadd-region").style.display = "block"; window.location.reload(); }); } }, 500); } }); return send.apply(this, arguments); }; })(); }); }); }); }, productViewFunc: function() { // console.log("productViewFunc called----"); // Quantity and return change and part number STATIC div var quantityChange = bocBasketPageRevamp.createElem("div", "boc_quantity_change"); var returnChange = bocBasketPageRevamp.createElem("div", "boc_return_change"); var quantsNum; var returnNum; quantityChange.innerHTML = '
' + quantsNum + '
' + 'Change'; returnChange.innerHTML = '
' + returnNum + '
' + 'Change'; var partNumberText = bocBasketPageRevamp.createElem("p", "boc_part_number_text"); partNumberText.innerText = "Part Number"; // Product view dynamic changes bocBasketPageRevamp.waitForElement(".boc_product_div .productView", function() { document.querySelectorAll(".boc_product_div .productView").forEach(function(elem) { // console.log("Element", elem); if (!(elem.querySelector(".boc_quantity_change"))) { // part number elem.querySelector(".description .name").after(elem.querySelector(".part-number")); elem.querySelector(".part-number>b").before(partNumberText.cloneNode(true)); // quantity & return change elem.querySelector(".data-quantity-section") && elem.querySelector(".data-quantity-section").after(quantityChange.cloneNode(true)); elem.querySelector(".data-return-section") && elem.querySelector(".data-return-section").after(returnChange.cloneNode(true)); // quantity & return no. quantsNum = elem.querySelector(".data-quantity-section input") && elem.querySelector(".data-quantity-section input").value; returnNum = elem.querySelector(".data-return-section input") && elem.querySelector(".data-return-section input").value; if (quantsNum == null) { elem.querySelector(".boc_quantity_change").style.visibility = "hidden"; elem.querySelector(".boc_quantity_change p").innerText = ""; } else { elem.querySelector(".boc_quantity_change p").innerText = quantsNum; } if (returnNum == null) { elem.querySelector(".boc_return_change").style.visibility = "hidden"; elem.querySelector(".boc_return_change p").innerText = ""; } else { elem.querySelector(".boc_return_change p").innerText = returnNum; } //"change" anchor click elem.querySelectorAll(".boc_quantity_change_anchor").forEach(function(quantityItem) { quantityItem.addEventListener("click", function() { // console.log("Quantity clicked !", quantityItem); elem.querySelector(".data-quantity-section").style.display = "flex"; quantityItem.parentNode.style.display = "none"; }); }); elem.querySelectorAll(".boc_return_change_anchor").forEach(function(quantityItem) { quantityItem.addEventListener("click", function() { // console.log("Return clicked !", quantityItem); elem.querySelector(".data-return-section").style.display = "flex"; quantityItem.parentNode.style.display = "none"; }); }); } }); }); }, checkoutViewFunc: function() { if (!(document.querySelector(".boc_promo_apply"))) { // console.log("Checkout Redesign"); // Checkout Button if (!(document.querySelector("button.boc_checkout_btn"))) { var bocCheckoutBtn = bocBasketPageRevamp.createElem("button", "boc_checkout_btn"); bocCheckoutBtn.innerText = "Checkout Securely"; document.querySelector(".product-totals.summary-region").after(bocCheckoutBtn); } document.querySelector(".boc_checkout_btn").addEventListener("click", function() { document.querySelector("#checkoutButtonShoppingCart").click(); }); // Delivery message var checkoutText = bocBasketPageRevamp.createElem("p", "boc_checkout_text"); checkoutText.innerText = "Delivery charges are calculated in checkout"; document.querySelector(".boc_checkout_div .summary-region .border-over-subtotal").after(checkoutText); // Promo code portion var promoApply = bocBasketPageRevamp.createElem("div", "boc_promo_apply"); promoApply.innerHTML = '
Promotional Code (Optional)
' + 'Apply'; document.querySelector(".boc_checkout_div .shoppingCart-promotion-section .summary-region .border-over-subtotal").before(promoApply); var promoInput = bocBasketPageRevamp.createElem("div", "boc_promo_input"); promoInput.innerHTML = '
'+ '
' + '
'; document.querySelector(".boc_promo_apply").after(promoInput); document.querySelector(".linkTermCond").innerHTML = $(".promotion-code>h2").html(); // Click on promo apply document.querySelector(".promo_apply").addEventListener("click", function() { document.querySelector(".boc_promo_input").classList.add("boc_promo_area"); document.querySelector(".boc_promo_apply").classList.add("boc_display_hide"); }); // Error Text var promoEmpty = bocBasketPageRevamp.createElem("p", "boc_promo_empty"); promoEmpty.innerText = "Please enter promo code"; document.querySelector(".boc_promo_input").after(promoEmpty); } }, promoFunc: function() { // Promo code submit bocBasketPageRevamp.waitForElement(".promo_submit", function() { document.querySelector(".promo_submit").addEventListener("click", function() { var promoValue = document.querySelector(".promo_input") && document.querySelector(".promo_input").value; if (promoValue == "") { document.querySelector(".boc_promo_input").classList.add("linkTermCond"); document.querySelector(".boc_promo_empty").style.display = "block"; } else { // console.log("Promo code entered ---", promoValue); document.querySelector(".promotion-code-section.promotion-region .promotion-code-input").value = promoValue; document.querySelector(".promotion-code-section.promotion-region .promotion-code-submit").click(); } }); }); }, promoAPIcall: function() { // Promo code API call (function() { var send = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function() { this.addEventListener('load', function(e) { if (this.responseURL.match(/shop\/ApplyRemovePromotion/i)) { // console.log(JSON.parse(this.responseText)); // console.log(JSON.parse(this.responseText).promoErrorKey); // Delivery message (Error msg) if (!(document.querySelector(".boc_checkout_text"))) { var checkoutText = bocBasketPageRevamp.createElem("p", "boc_checkout_text"); checkoutText.innerText = "Delivery charges are calculated in checkout"; document.querySelector(".boc_checkout_div .summary-region .border-over-subtotal").after(checkoutText); } if (JSON.parse(this.responseText).promoErrorKey) { // unsuccessful promo code // Promo Input var promoInput = bocBasketPageRevamp.createElem("div", "boc_promo_input"); promoInput.innerHTML = '
'+ '
' + '
'; document.querySelector(".boc_checkout_div .shoppingCart-promotion-section .summary-region .border-over-subtotal").before(promoInput); document.querySelector(".boc_promo_input").style.display = "flex"; document.querySelector(".linkTermCond").innerHTML = $(".promotion-code>h2").html(); // Promo Error Code if (!(document.querySelector(".boc_promo_error")) && JSON.parse(this.responseText).promoErrorKey == "ERR_PROMOTION_CODE_DUPLICATED") { var promoError = bocBasketPageRevamp.createElem("p", "boc_promo_error"); promoError.innerText = document.querySelector(".promotion-code-section.promotion-region .error-message-noPanel") && document.querySelector(".promotion-code-section.promotion-region .promotion-text").innerText; document.querySelector(".boc_promo_input").after(promoError); document.querySelector(".boc_promo_error").style.display = "block"; } else if (!(document.querySelector(".boc_promo_error"))) { var promoError = bocBasketPageRevamp.createElem("p", "boc_promo_error"); promoError.innerText = document.querySelector(".promotion-code-section.promotion-region .error-message-noPanel") && document.querySelector(".promotion-code-section.promotion-region .error-message-noPanel").innerText; document.querySelector(".boc_promo_input").after(promoError); document.querySelector(".boc_promo_error").style.display = "block"; } } else { // success messege with promo code // console.log("Success promo code"); if (!(document.querySelector(".row.promo-code-applied-row"))) { //Saving promo code to local storage var promoCode = JSON.parse(this.responseText).promoCode[0]; var promoStorage = promoCode; localStorage.setItem("promoCode", JSON.stringify(promoStorage)); var promoSuccess = bocBasketPageRevamp.createElem("p", "boc_promo_success"); promoSuccess.innerHTML = 'Promotion Applied (before VAT):
' + promoCode + '' + ''; bocBasketPageRevamp.waitForElement("span.promo-code-applied", function() { if (!(document.querySelector(".boc_promo_success"))) { document.querySelector(".promo-code-applied").after(promoSuccess); document.querySelector(".boc_promo_apply").classList.add("boc_display_hide"); $(".product > .row").eq(2).insertBefore(".row.promo-code-applied-row"); } }); document.querySelector(".boc_quick_add").style.display = "flex"; if(!JSON.parse(this.responseText).promoErrorKey ){ setTimeout(function(){ if($(".boc_promo_error").length < 1){ var promoInput = bocBasketPageRevamp.createElem("div", "boc_promo_input"); promoInput.innerHTML = '
'+ '
' + '
'; document.querySelector(".boc_checkout_div .shoppingCart-promotion-section .summary-region .border-over-subtotal").before(promoInput); document.querySelector(".boc_promo_input").style.display = "flex"; document.querySelector(".linkTermCond").innerHTML = $(".promotion-code>h2").html(); var promoError = bocBasketPageRevamp.createElem("p", "boc_promo_error"); var textdisplayerrorMSg = document.querySelector(".promotion-code-section.promotion-region .promotion-text").innerText; var textdisplayerrorMSgconact = textdisplayerrorMSg.replace(/\t|\n/g, ''); promoError.innerText = textdisplayerrorMSgconact; document.querySelector(".boc_promo_input").after(promoError); document.querySelector(".boc_promo_error").style.display = "block"; } },800); } } } bocBasketPageRevamp.promoFunc(); } }); return send.apply(this, arguments); }; })(); }, promoDltClick: function() { // promo delete click bocBasketPageRevamp.waitForElement(".boc_promo_anchor", function() { document.querySelector(".boc_promo_anchor").addEventListener("click", function() { console.log("Promo delete clicked !!!!!!!"); document.querySelector(".row.promo-code-applied-row .promotion-delete>img").click(); (function() { var send = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function() { this.addEventListener('load', function(e) { if (this.responseURL.match(/shop\/MiniShopCartView/i)) { // Promo Input var promoInput = bocBasketPageRevamp.createElem("div", "boc_promo_input"); promoInput.innerHTML = '
'+ '
' + '
'; document.querySelector(".boc_checkout_div .shoppingCart-promotion-section .summary-region .border-over-subtotal").before(promoInput); document.querySelector(".boc_promo_input").style.display = "none"; document.querySelector(".boc_promo_apply").style.display = "flex"; document.querySelector(".boc_quick_add").style.display = "flex"; document.querySelector(".linkTermCond").innerHTML = $(".promotion-code>h2").html(); } }); return send.apply(this, arguments); }; })(); }); }); }, quickAddFunc: function() { // console.log("Quick add function called---"); document.querySelector(".boc_product_div").appendChild(document.querySelector(".quickadd-region")); if (!(document.querySelector(".boc_quick_add"))) { var quickAddApply = bocBasketPageRevamp.createElem("div", "boc_quick_add"); quickAddApply.innerHTML = '
Quick Add More Products
' + 'Expand'; document.querySelector(".quickadd-region").before(quickAddApply); //quick add expand click document.querySelector(".quick_add_expand").addEventListener("click", function() { document.querySelector(".quickadd-region #shoppingCartQuickAddSection").style.display = "block"; document.querySelector(".boc_quick_add").style.display = "none"; }); } // Quick add to cart API call (function() { var send = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function() { this.addEventListener('load', function(e) { if (this.responseURL.match(/shop\/addItem/i)) { console.log("Quick Add Item"); document.querySelector(".boc_quick_add").style.display = "flex"; setTimeout(() => { bocBasketPageRevamp.waitForElement(".badge.data-order-item-count", function() { var itemQuants = document.querySelector(".badge.data-order-item-count").innerText; console.log("itemQuants", typeof itemQuants, itemQuants); itemQuants = parseInt(itemQuants); document.querySelector(".boc_product_header span").innerText = itemQuants; document.querySelector("span.boc_item_text").innerText = "Items"; }); }, 3000); } }); return send.apply(this, arguments); }; })(); // Quick add Error API call (function() { var send = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function() { this.addEventListener('load', function(e) { if (this.responseURL.match(/shop\/QuickAddGetProductDetails/i)) { console.log(JSON.parse(this.responseText).errors); if (JSON.parse(this.responseText).errors) { console.log("Got error in Quick add!"); document.querySelector(".boc_quick_add").style.display = "flex"; document.querySelector(".quick_add_expand").click(); bocBasketPageRevamp.checkoutViewFunc(); bocBasketPageRevamp.promoFunc(); bocBasketPageRevamp.promoAPIcall(); bocBasketPageRevamp.promoDltClick(); bocBasketPageRevamp.retriveSuccessPromo(); } else { bocBasketPageRevamp.tweakTwo(); } } }); return send.apply(this, arguments); }; })(); }, additionalCostDiv: function() { var deliveryCosts = bocBasketPageRevamp.createElem("a", "boc_delivery_costs"); deliveryCosts.innerText = "Delivery costs and charges"; document.querySelector(".boc_checkout_div>.shoppingCart-promotion-section>.product-totals>div").after(deliveryCosts); document.querySelector(".boc_delivery_costs").addEventListener("click", function() { document.querySelector(".cached-espot a").click(); }); }, shopingwishlistDivs:function(){ //link for favtore whistlist order var shopingWishListDiv = bocBasketPageRevamp.createElem("div", "boc_shoping_wishlist_div"); shopingWishListDiv.innerHTML = ` Save basket as a favourite`; document.querySelector(".shoppingCart-promotion-section > .product-totals ").after(shopingWishListDiv); // link for recurring order var shopingWishListRecurringDiv = bocBasketPageRevamp.createElem("div", "boc_shoping_wishlistrecurring_div"); shopingWishListRecurringDiv.innerHTML = ` Schedule order `; document.querySelector(".shoppingCart-promotion-section > .boc_shoping_wishlist_div ").after(shopingWishListRecurringDiv); }, retriveSuccessPromo: function() { console.log("Inside Retrive Success Promo ------"); var retrivePromo = localStorage.getItem("promoCode"); if (retrivePromo) { retrivePromo = retrivePromo.replace(/"/g, ""); } console.log(retrivePromo); var promoSuccess = bocBasketPageRevamp.createElem("p", "boc_promo_success"); promoSuccess.innerHTML = 'Promotion Applied (before VAT):
' + retrivePromo + '' + ''; bocBasketPageRevamp.waitForElement("span.promo-code-applied", function() { console.log("Inside wait..."); if (!(document.querySelector(".boc_promo_success"))) { console.log("Add Promo ---"); document.querySelector("span.promo-code-applied").after(promoSuccess); document.querySelector(".boc_promo_apply") && document.querySelector(".boc_promo_apply").classList.add("boc_display_hide"); } }); $(".product > .row").eq(2).insertBefore(".row.promo-code-applied-row"); }, tweakOne: function() { document.querySelectorAll("img[alt='update image']").forEach(function(element) { element.addEventListener("click", function() { console.log(" change, delete clicked !!!"); bocBasketPageRevamp.tweakTwo(); }); }); }, tweakTwo: function() { console.log("Inside Tweak 2"); console.log(document.querySelector(".row.promo-code-applied-row")); if (document.querySelector(".row.promo-code-applied-row")) { document.querySelector("body").classList.add("hide_for_sec"); if (document.querySelector("#overlay").classList.contains("boc_overlay_hide")) { document.querySelector("#overlay").classList.remove("boc_overlay_hide"); }; document.querySelector("#overlay").classList.add("boc_overlay_show"); (function() { var send = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function() { this.addEventListener('load', function(e) { if (this.responseURL.match(/shop\/MiniShopCartView/i)) { console.log("Got it .."); document.querySelector("body").classList.remove("hide_for_sec"); document.querySelector("#overlay").classList.remove("boc_overlay_show"); document.querySelector("#overlay").classList.add("boc_overlay_hide"); bocBasketPageRevamp.retriveSuccessPromo(); } }); return send.apply(this, arguments); }; })(); } }, DesktopgoalJS: function() { document.querySelector("body").addEventListener("click", function(e) { }); }, waitForElement: function(selector, callback) { var isString = typeof selector === "string"; (function pollForSelector() { if (isString && document.querySelector(selector)) { callback(); } else if ( !isString && selector.length > 0 && selector.every(function(element) { return document.querySelector(element); }) ) { callback(); } else { setTimeout(pollForSelector, 25); } })(); }, createElem: function(elementType, className) { var element = document.createElement(elementType); element.classList.add(className); return element; }, }; (function pollForBocBasketPageRevamp() { if (document.querySelector(".container-fluid.container-fluid-shopping-cart")) { try { console.log("BOC:Basket page Redesign - Variation- A: 17"); bocBasketPageRevamp.init(); } catch (error) { console.log(error); } } else { setTimeout(pollForBocBasketPageRevamp, 25); } })(); $(document).ready(function (event) { $(document).on("click",'#shoppingCartQuickAddToCartBtn','#shoppingCartQuickAddPartNumber', function () { if(parseInt($(".data-order-item-count").text()) > 0 || parseInt($(".data-order-item-count").text()) == 1){ window.location.reload(); } }); $(document).on('click change keyup paste mouseup focus keypress blur', '#shoppingCartQuickAddToCartBtn','#shoppingCartQuickAddPartNumber', function (event) { if(!document.querySelector(".badge.data-order-item-count")){ document.querySelector(".products-region").style.display = "none"; document.querySelector(".row.shoppingCart-promotion-section").style.display = "none"; $( document ).ajaxComplete(function( event, xhr, settings ) { document.querySelector(".products-region").style.display = "none"; document.querySelector(".row.shoppingCart-promotion-section").style.display = "none"; if ( settings.url == "/shop/MiniShopCartView?catalogId=3074457345616677919&langId=101&storeId=715839134&storeId=715839134"){ document.querySelector(".products-region").style.display = "none"; document.querySelector(".row.shoppingCart-promotion-section").style.display = "none"; setTimeout(function(){ if($(".badge.data-order-item-count").is(":visible")){ var itemQuants = $(".badge.data-order-item-count").html(); if(itemQuants == '1'){ location.reload(); }else if(itemQuants > '1'){ location.reload(); }else{ document.querySelector(".products-region").style.display = "block"; document.querySelector(".row.shoppingCart-promotion-section").style.display = "flex"; } } },500); }else{ // document.querySelector(".products-region").style.display = "block"; // document.querySelector(".row.shoppingCart-promotion-section").style.display = "flex"; } }); }else{ document.querySelector(".products-region").style.display = "block"; document.querySelector(".row.shoppingCart-promotion-section").style.display = "flex"; } }); }); }})();