You May Also Like
`; let target = document.querySelector('.recommendations-wrapper'); // console.log("product is:", product); target.insertAdjacentHTML('beforeend', html); } function addToCart(vId) { $.ajax({ url: "/cart/add.js", dataType: "json", type: "post", data: { quantity: 1, id: vId }, success: function (itemData) { console.log(`${vId} added to cart.`) document.dispatchEvent(new CustomEvent('cart:build')); getCart(function(cartItemIds) { console.log('Cart Items are :', cartItemIds); matchAndHide(cartItemIds); }); } }); } function matchAndHide(arr) { let ids = ["","43613251600546","43613248520354","43613241213090","43611230666914","43256075387042","43256073453730","43256071454882","43256070340770","43256069947554","43256069324962","43256068866210","43256067915938","43256065818786","43726033977506","43726037057698","43726039679138","43726040203426","43726041972898","43726044528802","43726045479074","43907857121442","43934919098530","43934919622818"]; ids.shift(); let idSet = new Set(ids); // console.log('Matched elements are : ',arr,idSet); arr.forEach(element => { if (idSet.has(element)) { // console.log('Match Found!',element); $(`#recom-product-${element}`).hide(); } }); } function getCart(callback) { $.ajax({ type: 'GET', url: '/cart.js', cache: false, dataType: 'json', success: function(cart) { var productIds = []; if (cart && cart.items) { productIds = cart.items.map(function(item) { return item.id.toString(); }); } // Call the callback function with the cart items callback(productIds); } }); } document.addEventListener("DOMContentLoaded", (event) => { let productHandles = ["","noir-club","close-call","black","evoke","mafia-ss-chain","rattle-square-chain","shenron-dragon-bracelet","mini-marble-beads-bracelet","mix-bead-bracelet","hexa-beads-bracelet","7-stone-bracelet","bold-trio-swirl-bracelet","brown-dapper-bracelet","crystal-stone-choker-chain","curb-ss-black-chain","4mac0021-1","solid-block-ss-chain","byzantine-ss-chain","rattle-style-ss-chain","mojave-ss-chain","twisted-cuboids-ss-chain","grey-cuboid-ss-chain","black-cuboid-ss-chain"]; productHandles.shift(); // console.log('product handles are :',productHandles); productHandles.forEach(async function (item){ // console.log('the product is:',await getRecommendedProductUsingHandle(item)); let currentProduct = await getRecommendedProductUsingHandle(item); pushHTML(currentProduct); }); getCart(function(cartItemIds) { // console.log('Cart Items are :', cartItemIds); matchAndHide(cartItemIds); }); });