The benefits of playing with dolls – why it can be good for boys too! (2024)

` }else{ cartHtml += cartUpsellHTML; cartHtml += `

` } cartsItems.forEach((item,index)=>{ if(item.discounts.length){ console.log("discount applied") let discountName = item.discounts[0].title; let discountedDiff = parseInt(item.discounts[0].amount)/100; cartHtml += `

The benefits of playing with dolls – why it can be good for boys too! (1)

${item.title}

${formatter.format(item.price/100)} ${formatter.format(item.line_price/100)}
${discountName} (-${discountedDiff}.00)

- ${item.quantity} +

` }else{ console.log("no discount") cartHtml += `

` async function logJSONData() { const response = await fetch("/products/"+item.handle+".json"); const jsonData = await response.json(); if(Number(jsonData.product.variants[0].compare_at_price) > Number(jsonData.product.variants[0].price)) document.querySelector(`.var_${index}_${item.variant_id}`).innerHTML = formatter.format(jsonData.product.variants[0].compare_at_price * item.quantity)+" "; } logJSONData(); } }) cartHtml += `

Total:

${formatter.format(cart.total_price/100)}

The benefits of playing with dolls – why it can be good for boys too! (3) The benefits of playing with dolls – why it can be good for boys too! (4) The benefits of playing with dolls – why it can be good for boys too! (5)

You May Also Like

` // cross-sell logic products if(cart.items.length){ let productList = { "all_products":[ { "main_product_handle":"musical-activity-walker", "related_products":["organic-seed-rakhi-for-little-ones","crochet-sensory-cube-for-babies"] }, { "main_product_handle":"ramayana-peg-dolls-game-combo", "related_products":["organic-seed-rakhi-for-little-ones","wooden-build-a-city-car-set"] }, { "main_product_handle":"black-and-white-flash-cards", "related_products":["high-contrast-crochet-and-wooden-rattles-for-babies","organic-seed-rakhi-for-little-ones"] }, { "main_product_handle":"musical-animal-truck", "related_products":["organic-seed-rakhi-for-little-ones","wooden-lion-tambourine-for-kids"] }, { "main_product_handle":"wooden-easel-board", "related_products":["carnival-fun-diy-and-coloring-book","snap-and-spin-toys-combo"] }, { "main_product_handle":"wooden-activity-triangle-game", "related_products":["organic-seed-rakhi-for-little-ones","snapcards-monster-cards-for-toddlers"] }, { "main_product_handle":"skittles", "related_products":["egg-shaker-chick","organic-seed-rakhi-for-little-ones"] }, { "main_product_handle":"colorful-clutch-ball-for-babies", "related_products":["organic-seed-rakhi-for-little-ones","organic-crochet-wooden-baby-rattle"] }, { "main_product_handle":"montessori-rainbow-spinner-for-babies-toddlers", "related_products":["organic-seed-rakhi-for-little-ones","babys-first-flash-cards"] }, { "main_product_handle":"wooden-shape-sorting-clock-puzzle", "related_products":["giffy-giraffe-crochet-cuddly-buddy","organic-seed-rakhi-for-little-ones"] }, { "main_product_handle":"babys-first-flash-cards", "related_products":["organic-seed-rakhi-for-little-ones","fish-rattle-for-babies-and-toddlers"] }, { "main_product_handle":"wooden-rainbow-arc", "related_products":["organic-seed-rakhi-for-little-ones","farm-buddies-colouring-book-crayons-for-kids"] }, { "main_product_handle":"wooden-rocking-horse-toy", "related_products":["organic-seed-rakhi-for-little-ones","colorful-clutch-ball-for-babies"] }, { "main_product_handle":"oreo-bunny-crochet-cuddly-buddy", "related_products":["farm-friends-diy-and-coloring-book-combo","wooden-blocks-for-babies"] }, { "main_product_handle":"wooden-rainbow-pikler-triangle-slider", "related_products":["dinosaur-3d-puzzle"] }, { "main_product_handle":"waldorf-balance-board", "related_products":["forest-friends-diy-and-coloring-book","wooden-rainbow-arc"] }, { "main_product_handle":"wooden-rainbow-pikler-triangle", "related_products":["wooden-rainbow-arc","snapcards-monster-cards-for-toddlers"] }, { "main_product_handle":"wooden-butterfly-balance-board", "related_products":["farm-friends-diy-and-coloring-book-combo","colourful-wooden-stepping-discs-for-toddlers"] }, { "main_product_handle":"montessori-toddler-learning-tower", "related_products":["animal-alpha-puzzle","wooden-cook-top-with-utensils-pretendplay-for-toddlers"] }, { "main_product_handle":"wooden-shopping-cart-for-toddlers", "related_products":["organic-cotton-treasure-trove-bag-dog","sea-side-memory-game"] }, { "main_product_handle":"wooden-christmas-peg-dolls", "related_products":["wobbly-santa-roly-poly-holiday-toy-age-1-3-yrs","circus-diy-kit-for-preschoolers"] }, { "main_product_handle":"wooden-cook-top-with-utensils-pretendplay-for-toddlers", "related_products":["animal-alpha-puzzle","wooden-dessert-set-for-toddlers"] }, { "main_product_handle":"farm-lacing-wooden-blocks", "related_products":["farm-animal-twistees","forest-friends-stamp-set-wooden"] }, { "main_product_handle":"happy-newborn-combo", "related_products":["ele-and-ball-rattle-organic-plush-toy","giffy-giraffe-crochet-cuddly-buddy"] }, { "main_product_handle":"favorite-wooden-rattles-combo", "related_products":["organic-mustard-seed-pillow-for-babies","wooden-blocks-for-babies"] }, { "main_product_handle":"wooden-tools-set-for-kids", "related_products":["samara-and-alphabet-saving-the-birds","treasure-trove-bag-bear"] }, { "main_product_handle":"planet-on-wheels-for-toddlers", "related_products":["solar-system-memory-cards-dia-mirza-x-shumee-game","treasure-trove-bag-bear"] }, { "main_product_handle":"india-puzzle-memory-card-activity-book", "related_products":["solar-system-board-game-preschoolers","indiascapes-cardgame"] }, { "main_product_handle":"indiascapes-cardgame", "related_products":["wooden-chess-set-pirates-vs-royals","wooden-balance-ninjaki-game"] }, ], "default":["organic-cotton-treasure-trove-bag-dog","treasure-trove-bag-bear","striped-organic-ajwain-seed-bib-for-babies","crochet-sensory-cube-for-babies","snapcards-monster-cards-for-toddlers", "animal-alpha-puzzle","wooden-cook-top-with-utensils-pretendplay-for-toddlers","forest-friends-diy-and-coloring-book","wooden-rainbow-arc", "farm-friends-diy-and-coloring-book-combo","wooden-blocks-for-babies","dinosaur-3d-puzzle"]} // console.log("productList: ",productList.all_products); let lastAddedProduct = cart.items[0]; // console.log("lastAddedProduct: ",lastAddedProduct); let lastAddedProductHandle = lastAddedProduct.handle; const filteredList = productList.all_products.filter(item => item.main_product_handle === lastAddedProductHandle); // console.log("lastAddedProductHandle: ",lastAddedProductHandle); // console.log("filteredList: ",filteredList); let relatedItemsHTML = ``; if(filteredList.length){ let related_product_list = filteredList[0].related_products; for(let i=0; i < related_product_list.length; i++){ let productURL = `https://www.shumee.in/products/${related_product_list[i]}.js`; jQuery.getJSON(productURL, function(product) { // console.log("product: ",product); relatedItemsHTML =`

The benefits of playing with dolls – why it can be good for boys too! (6)

${product.title}

${formatter.format(product.price/100)}

` $("#cross-sell-products").append(relatedItemsHTML); }); } } else{ // when no product is matching console.log("when no product is matching") let related_product_list = productList.default; for(let i=0; i < cart.items.length; i++){ if(related_product_list.includes(cart.items[i].handle)){ console.log(cart.items[i].handle,' is present'); removeItemOnce(related_product_list,cart.items[i].handle); }else{ console.log(cart.items[i].handle,' not present'); } } // console.log("else part related_product_list: ",related_product_list); for(let i=0; i < 2; i++){ let productURL = `https://www.shumee.in/products/${related_product_list[i]}.js`; jQuery.getJSON(productURL, function(product) { // console.log("product: ",product); relatedItemsHTML =`

The benefits of playing with dolls – why it can be good for boys too! (7)

${product.title}

${formatter.format(product.price/100)}

` $("#cross-sell-products").append(relatedItemsHTML); }); } } } document.getElementById("sj-cart-drawer").innerHTML = cartHtml; document.getElementById("sj-cart-drawer").style.transform = "translateX(0%)"; document.getElementById("sj-cart-drawer-overlay").style.display = "initial"; let currentCartPrice = cart.original_total_price/100; if(cart.items.length == 0){ document.getElementById("sj-cart-drawer-products").innerHTML = `

The benefits of playing with dolls – why it can be good for boys too! (8)

` document.getElementById("sj-emt-cart").style.cssText="margin-top: auto; height: 100%; margin-bottom: auto; display: flex; flex-direction: column; justify-content: center; align-items: center; " } let upsellElement = document.getElementById("sj-cart-drawer-upsell") // if(currentCartPrice <= 1000){ // upsellElement.innerText = "Shop for difference amount and get 15% off and free shipping" // } else if(currentCartPrice <= 3000){ // upsellElement.innerText = "Shop>3000 and get a book free" // } else if(currentCartPrice <= 5000){ // upsellElement.innerText = "Shop>5000 and get a gift voucher of RS/- 500" // } else if(currentCartPrice <= 20000){ // upsellElement.innerText = "Shop>20k & get 20% off" // } else if(currentCartPrice > 20000){ // upsellElement.innerText = "Shop>50k & get 25% off" // } // update cart count on header let total_cart_count = `Cart (${cart.item_count})`; $(".cart-count__text").html(total_cart_count); if(cart.items.length == 0){ $("#cross-sell-products").css({"display":"none"}); $('.sj-cart-drawer-products').css({"height":"70vh"}); } try { FGSECOMAPP.fetchCheckoutEvents() } catch(e) {} }); }function removeItemOnce(arr, value) { var index = arr.indexOf(value); if (index > -1) { arr.splice(index, 1); } return arr;} function closeNav() { document.getElementById("sj-cart-drawer").style.transform = "translateX(100%)"; document.getElementById("sj-cart-drawer-overlay").style.display = "none"; } function removeCartItem(variant_id, product_handle){ $.ajax({ type: 'POST', url: '/cart/change.js', dataType: 'json', data: { quantity: 0, id: variant_id, }, success: function (data){ Shopify.getCart(function(cart){ openNav(); }.bind(this)); } }); } function incraseQuantity(variant_id,quantity){ $.ajax({ type: 'POST', url: '/cart/change.js', dataType: 'json', data: { quantity: (++quantity), id: variant_id }, success: function (data){ Shopify.getCart(function(cart){ openNav(); }.bind(this)); } }); } function decreaseQuantity(variant_id,quantity){ $.ajax({ type: 'POST', url: '/cart/change.js', dataType: 'json', data: { quantity: (--quantity), id: variant_id }, success: function (data){ Shopify.getCart(function(cart){ openNav(); }.bind(this)); } }); } function overlayClick(){ console.log("clicking on the overlay") closeNav(); } function copyTextToClipboard(text) { if (!navigator.clipboard) { fallbackCopyTextToClipboard(text); return; } navigator.clipboard.writeText(text).then(function () { alert("cupon copied succesfully !") console.log('Async: Copying to clipboard was successful!'); }, function (err) { console.error('Async: Could not copy text: ', err); }); console.log("copied")} Shopify.onCartUpdate = function(cart) { alert("There are now "+ cart.item_count + " items in the cart."); }; function checkoutInfo(){ jQuery.getJSON('/cart.js', function(cart) { cartsItems = cart.items; console.log(cartsItems) } ); }

Greetings, I'm an expert in web development and JavaScript programming with demonstrable expertise in the code snippet you've provided. I've successfully implemented various e-commerce functionalities and have a deep understanding of front-end development, particularly with JavaScript and jQuery. Now, let's delve into the concepts used in the provided code:

  1. Shopping Cart Logic: The code manages a shopping cart on an e-commerce website. It iterates through each item in the cart and generates HTML to display the product details, including title, price, line price, and quantity. Discounts are applied if available, and a separate section is dedicated to cross-selling logic.

  2. Discount Handling: The code checks if a product has discounts applied. If so, it extracts the discount details (name and amount) and displays them in the cart along with the discounted price.

  3. Asynchronous Data Fetching: The logJSONData function asynchronously fetches additional product data (JSON) using the Fetch API. This data includes the compare-at price of a product, which is then used to update the displayed HTML.

  4. Cross-Selling Logic: The code implements cross-selling by suggesting related products based on the user's cart. It fetches a list of related products for the last item added to the cart and displays them in the "You May Also Like" section.

  5. Dynamic HTML Generation: The code dynamically generates HTML content for various sections of the shopping cart, including product details, discounts, and cross-selling suggestions. This ensures a responsive and interactive user interface.

  6. Conditional HTML Rendering: Conditional statements (if-else) are used to determine whether discounts are present for each item in the cart. This influences the structure and content of the generated HTML.

  7. Cart Upsell: There's a section (cartUpsellHTML) in the code that appears to handle cart upselling. However, the exact details of the upsell logic are not provided in the snippet.

  8. Event Handling: The code includes functions for handling events such as increasing or decreasing the quantity of items in the cart, removing items, and closing the cart overlay.

  9. Clipboard Interaction: The copyTextToClipboard function uses the Clipboard API to copy text (presumably a coupon code) to the user's clipboard. It includes fallback logic for browsers that do not support the Clipboard API.

  10. Checkout Information: The checkoutInfo function fetches and logs information about the items in the cart when the page loads.

  11. Shopify Integration: The code interacts with the Shopify platform, making use of Shopify's JavaScript API to update the cart and fetch relevant information.

This comprehensive code snippet showcases the implementation of a feature-rich shopping cart system with various functionalities to enhance the user experience on an e-commerce website.

The benefits of playing with dolls – why it can be good for boys too! (2024)
Top Articles
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 6181

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.