Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var __isp_options = {
  2.     isp_serp_callback: function() {
  3.         if (typeof cart_items === 'undefined') {
  4.             var cart_items = [];
  5.             $jquery_isp.ajax({
  6.                 type: 'GET',
  7.                 url: '/cart.js',
  8.                 dataType: 'json',
  9.                 async: false,
  10.                 success: function (data) {
  11.                     for (var i = 0; i < data.items.length; i++) {
  12.                         var id = data.items[i].product_id;
  13.                         var var_id = data.items[i].variant_id;
  14.                         cart_items.push({id: id, var_id: var_id});
  15.                     }
  16.                 }
  17.             });
  18.         }
  19.  
  20.         if (window.location.pathname.indexOf("/collections/sale") != -1) {
  21.             $(".isp_facet_title_name").each(function (index) {
  22.                 console.log("This text", $(this).text());
  23.                 if ("Sale" == $(this).text()) {
  24.                     $(".isp_single_facet_wrapper").eq(index).remove()
  25.                 }
  26.             });
  27.         }
  28.  
  29.       $jquery_isp('.isp_grid_product:not(.isp_grid_product_skeleton)').each(function() {
  30.             var id = $jquery_isp(this).attr('product_id');
  31.             $jquery_isp(this).attr('id', 'grid-item-' + id);
  32.             $jquery_isp(this).addClass('product-item');
  33.  
  34.               // Fix Flow compare_at localizations
  35.             $jquery_isp(this).find('.isp_compare_at_price').attr('flow-selector','prices.compare_at.label');
  36.             if (ISP_PRODUCTS[id]) {
  37.                 var variants = ISP_PRODUCTS[id].vra;
  38.                 /**
  39.                  * Create "Add to Bag" select button
  40.                  */
  41.  
  42.                 if(variants.length <= 1){
  43.                     var variant = variants[0],
  44.                         size = variant[1].find(function (element) { return element[0] === "Size" })[1][0],
  45.                         sellable = variants[0][1].find(function (element) { return element[0] === "Sellable" })[1][0];
  46.                         variant_id = variant[0];
  47.                     var one_size_form = '<form action="/cart/add" method="post" class="variants add-to-cart-form product-info-json product-atc info" id="product-actions-' + id + '" enctype="multipart/form-data">' +
  48.                         '<input type="hidden" name="id" value="'+variant_id+'">' +
  49.                         '</form>';
  50.                     this.insertAdjacentHTML('beforeend', one_size_form);
  51.  
  52.                     var add_to_cart_button = ''
  53.  
  54.                     if(sellable) {
  55.                         if ($jquery_isp(this).find('.product-atc-label').length === 0) {
  56.                             add_to_cart_button = '<div class="product-atc-label women">'+
  57.                                 '<span class="main-option-title left-side"><div></div></span>'+
  58.                                 '<span class="atc-label">Add to bag</span>'+
  59.                                 '<span class="main-option-title"><div></div></span>'+
  60.                             '</div>'+
  61.                             '<input type="button" class="product-main-option" data-main-option-text="' + size + '" data-option-name="Size" data-variant-id="' + variant_id + '" id="product-'+id+'-variantid" name="id" value="' + variant_id + '">';
  62.                         }
  63.                     } else {
  64.                         add_to_cart_button = '<a class="btn notify-me not-available os" href="#" data-notifyme-btn="">Notify Me When Available</a>';
  65.                     }
  66.                     this.querySelector('.add-to-cart-form').insertAdjacentHTML('beforeend', add_to_cart_button);
  67.  
  68.  
  69.                 } else {
  70.                     if ($jquery_isp(this).find('.product-atc').length === 0) {
  71.                         var add_to_bag_select = '<form action="/cart/add" method="post" class="variants add-to-cart-form product-info-json product-atc info" id="product-actions-' + id + '" enctype="multipart/form-data">' +
  72.                                                     '<a class="btn dropdown product-atc-label women" data-show-sizes="">' +
  73.                                                         '<span class="main-option-title left-side"><div></div></span>' +
  74.                                                         '<span class="atc-label">Add to bag</span>' +
  75.                                                         '<span class="main-option-title"><div></div></span>' +
  76.                                                     '</a>' +
  77.                                                     '<div class="product-main-options" style="display: none; width: 100%;">' +
  78.                                                         '<input type="hidden" name="id" value="">' +
  79.                                                         '<div class="product-main-options__wrapper">' +
  80.                                                             '<div class="product-main-options__size" aria-live="polite">Select Size</div>' +
  81.                                                             '<a class="product-main-options__close" aria-label="Close Size Window" data-close-size>' +
  82.                                                                 '<span class="lnr animation lnr-cross make-gray" aria-hidden="true"></span>' +
  83.                                                             '</a>' +
  84.                                                             '<div class="product-main-options__content">' +
  85.                                                                 '<ul class="product-main-option__list"></ul>' +
  86.                                                                 '<button class="btn dropdown women" data-add-to-cart="" name="add" style="display: none;"></button>' +
  87.                                                                 '<a class="btn notify-me" data-notifyme-btn style="display: none;">Notify Me When Available</a>' +
  88.                                                                 '<a class="product-main-options__size-guide" data-size-guide style="display: block;">Size Guide</a>' +
  89.                                                             '</div>' +
  90.                                                         '</div>' +
  91.                                                     '</div>' +
  92.                                                 '</form>';
  93.                         this.insertAdjacentHTML('beforeend', add_to_bag_select);
  94.                     }
  95.                 }
  96.  
  97.  
  98.  
  99.                 /**
  100.                  * Notify Me
  101.                  */
  102.                 // if ($jquery_isp(this).find('.notifyme-item').length === 0) {
  103.                 //     var title = ISP_PRODUCTS[id].l;
  104.                 //     var image = ISP_PRODUCTS[id].image;
  105.                 //     var image_400 = ISP_PRODUCTS[id].image.replace('600', '400');
  106.                 //     var image_200 = ISP_PRODUCTS[id].image.replace('600', '200');
  107.                 //     var notify_me = '<section id="notifyme-item-' + id + '" data-notifyme-form="" class="notifyme-item" data-section-id="notifyme-item-' + id + '" data-section-type="notifyme-item" data-product-detail="" data-notifyme="true">' +
  108.                 //                         '<form class="notifyme-form" id="notifyme-form-' + id + '">' +
  109.                 //                             /*'<input type="hidden" name="gender" id="gender-' + id + '" value="women">' +*/
  110.                 //                             '<input type="hidden" name="source" id="source-' + id + '" value="BIS_Collection">' +
  111.                 //                             '<div class="notifyme--top notifyme--top__default">' +
  112.                 //                                 '<h2>We can email you when its back!</h2>' +
  113.                 //                                 '<a href="#" class="notifyme--form__close" aria-label="Close Size Window" data-close="">' +
  114.                 //                                     '<span class="lnr animation lnr-cross make-gray" aria-hidden="true"></span>' +
  115.                 //                                 '</a>' +
  116.                 //                             '</div>' +
  117.                 //                             '<div class="notifyme--top notifyme--top__thanks">' +
  118.                 //                                 '<h2>Perfect!</h2>' +
  119.                 //                                 '<a href="#" class="notifyme--form__close" aria-label="Close Size Window" data-close="">' +
  120.                 //                                     '<span class="lnr animation lnr-cross make-gray" aria-hidden="true"></span>' +
  121.                 //                                 '</a>' +
  122.                 //                             '</div>' +
  123.                 //                             '<a href="#" class="back-to-sizes" data-back-to-sizes="grid-item-' + id + '">&lt; back to sizes</a>' +
  124.                 //                             '<div class="notifyme--product">' +
  125.                 //                                 '<div class="image" id="image-' + id + '">' +
  126.                 //                                     '<div class="mediabox lazyloaded" data-expand="-1">' +
  127.                 //                                         '<img class="mediabox-img lazyautosizes lazyloaded" data-sizes="auto" data-src="' + image + '" data-srcset="' + image_200 + ' 200w,' + image_400 + ' 400w" src="' + image + '" alt="' + title + '" srcset="' + image_200 + ' 200w,' + image_400 + ' 400w">' +
  128.                 //                                     '</div>' +
  129.                 //                                 '</div>' +
  130.                 //                                 '<div class="product-info">' +
  131.                 //                                     '<div class="notifyme--copy">' +
  132.                 //                                         '<p>Register so we can email you as soon as your size becomes available!</p>' +
  133.                 //                                     '</div>' +
  134.                 //                                     '<div class="product-info--name">' + title + '</div>' +
  135.                 //                                     '<span class="product-info--size">Size:</span><span class="product-info--selected">M</span>' +
  136.                 //                                     '<div class="options animation clearfix "> ' +
  137.                 //                                         '<label id="selector-label" for="product-select-' + id + '" class="single offscreen" aria-label="Select Size">Select Size:</label>' +
  138.                 //                                         '<select class="select-variant" id="product-select-' + id + '"></select>' +
  139.                 //                                         '<input type="hidden" name="id" id="product-' + id + '-variant" value="12472888098925">' +
  140.                 //                                     '</div>' +
  141.                 //                                 '</div>' +
  142.                 //                                 '<div class="thank-you">' +
  143.                 //                                     '<p>We\'ll email you at <span data-email=""></span> when the item is back in stock!</p>' +
  144.                 //                                 '</div>' +
  145.                 //                             '</div>' +
  146.                 //                             '<div class="notifyme--form">' +
  147.                 //                                 '<input type="email" data-notify-email="" id="email" name="email" placeholder="Enter your email address">' +
  148.                 //                                 '<div class="email-error">Please enter a valid email address</div>' +
  149.                 //                                     '<button type="submit" class="btn notify-me-submit" data-notifyme-btn>Notify Me <span class="fa fa-envelope-o" aria-label="hidden"></span></button>' +
  150.                 //                                     '<label for="subscribe-notify-' + id + '">' +
  151.                 //                                         '<input type="checkbox" name="subscribe" data-subscribe="" id="subscribe-notify-' + id + '" checked="">Get Email Updates' +
  152.                 //                                     '</label>' +
  153.                 //                                     '<p class="notifyme--notice"><i>Yes, I would like to be notified by email about this product, and to receive emails from Fashion Nova with the latest deals, sales, and updates. I agree to Fashion Nova’s <a href="/pages/terms-of-service" target="_blank">Terms of Service</a> and <a href="/pages/privacy-policy" target="_blank">Privacy Policy.</a></i></p>' +
  154.                 //                             '</div>' +
  155.                 //                             '<a href="#" data-close="" class="btn close-modal">Continue Shopping</a>' +
  156.                 //                         '</form>' +
  157.                 //                     '</section>';
  158.                 //     this.insertAdjacentHTML('beforeend', notify_me);
  159.                 // }
  160.  
  161.                 /**
  162.                  * Add variant sizes
  163.                  */
  164.                 var size_list = [];
  165.                 var size_options = [];
  166.  
  167.                 for (var i = 0; i < cart_items.length; i++) {
  168.                     if (cart_items[i].id == id) {
  169.                         var cart_item_variant = variants.find(function (element) { return element[0] === cart_items[i].var_id }) ? variants.find(function (element) { return element[0] === cart_items[i].var_id })[1] : [];
  170.                         if (cart_item_variant.length > 0) {
  171.                             var size = cart_item_variant.find(function (element) { return element[0] === "Size" }) ? cart_item_variant.find(function (element) { return element[0] === "Size" })[1][0] : '';
  172.                             if (size) {
  173.                                 $jquery_isp('[product_id="' + id + '"] .product-atc-label').addClass('option-selected in-cart');
  174.                                 $jquery_isp('[product_id="' + id + '"] .atc-label').html('In your bag!');
  175.                                 $jquery_isp('[product_id="' + id + '"] .main-option-title > div').html(size);
  176.                             }
  177.                         }
  178.                     }
  179.                 }
  180.                 if(variants.length > 1){
  181.                     for (var i = 0; i < variants.length; i++) {
  182.                         var vra_id = variants[i][0];
  183.                         if (variants[i][1].find(function(element) { return element[0] === "Size" }) && $jquery_isp('[data-variant-id="' + vra_id + '"]').length == 0) {
  184.                             var size = variants[i][1].find(function (element) { return element[0] === "Size" })[1][0];
  185.                             var sellable = variants[i][1].find(function (element) { return element[0] === "Sellable" })[1][0];
  186.                             var size_li = sellable ? '<li><a data-variant-id="' + vra_id + '" data-main-option-text="' + size + '" data-size>' + size + '</a></li>'
  187.                                                 : '<li><a data-variant-id="' + vra_id + '" data-main-option-text="' + size + '" data-sold-out>' + size + '<span class="sold-out-msg">Sold Out - <span class="sold-out-msg sold-out-msg__notify">Notify Me</span></span></a></li>';
  188.                             size_list.push(size_li);
  189.                         }
  190.                     }
  191.                     this.querySelector(".product-main-option__list").insertAdjacentHTML('beforeend', size_list.join(''));
  192.                 }
  193.                 /**
  194.                  * Product Size Guide
  195.                  */
  196.                 if ($jquery_isp(this).find('.product-size-guide').length === 0 && $jquery_isp(this).find('.add-to-cart-form').length > 0) {
  197.                     var size_guide = '<section class="product-size-guide">\
  198.                                        <div class="product-size-guide__header">Size Guide</div>\
  199.                                        <a href="#" class="product-main-options__close" aria-label="Close Size Guide Window" data-close-size-guide>\
  200.                                            <span class="lnr animation lnr-cross make-gray" aria-hidden="true"></span>\
  201.                                        </a>\
  202.                                        <a href="#" class="back-to-sizes" data-back-to-sizes="grid-item-' + id + '">< back to sizes</a>\
  203.                                        <a href="#" class="btn btn-size-guide active" data-guide-type="womens">Womens</a><a href="#" class="btn btn-size-guide" data-guide-type="mens">Mens</a>\
  204.                                        <div class="product-size-guide--content product-size-guide__womens active"></div>\
  205.                                        <div class="product-size-guide--content product-size-guide__mens"></div>\
  206.                                    </section>';
  207.                     $jquery_isp(this).find('.add-to-cart-form')[0].insertAdjacentHTML('beforeend', size_guide);
  208.                 }
  209.  
  210.                 try {
  211.                     addToCartButton($jquery_isp('[product_id="' + id + '"]'));
  212.                 }
  213.                 catch(e)  {
  214.                     console.log(e)
  215.                 }
  216.             }
  217.  
  218.       });
  219.  
  220.  
  221.       // Trigger Flow Localization
  222.         try {
  223.             Flow.variants.localize({
  224.                 force:true,
  225.                 container: document.querySelector('#isp_search_results_container')
  226.             });
  227.         } catch (error) {
  228.             console.error('Could not localize variant: ' + error);
  229.         }
  230.  
  231.     },
  232.     isp_serp_no_results_callback: function () {
  233.         location.replace('https://www.fashionnova.com/pages/no-results-page');
  234.     }
  235. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement