Advertisement
valeraplusplus

shop2.product._reload

Mar 11th, 2025
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shop2.product._reload = function (node) {
  2.         var $node = $(node);
  3.         var kinds = shop2.product.getNodeData(node, 'kinds', true);
  4.         var paramName = shop2.product.getNodeData(node, 'name');
  5.         var paramValue = shop2.product.getNodeData(node, 'value');
  6.         var $form = $node.closest('form');
  7.         var form = $form.get(0);
  8.         var meta;
  9.         var kind_id;
  10.         var product_id;
  11.         var keys = {};
  12.         var params = {};
  13.         var is_param_select = false;
  14.        
  15.         window.gr_reloaded_product_node = $node.parents('.shop2-product-item');
  16.         window.gr_reloaded_product_index = $node.parents('.shop2-product-item').index();
  17.        
  18.         if (kinds && $.type(paramName) !== 'undefined' && $.type(paramValue) !== 'undefined' && form) {
  19.             meta = $form.find('input[name=meta]').val();
  20.             product_id = $form.find('input[name=product_id]').val();
  21.             $form.find('[name=submit]').prop('disabled', true);
  22.             $form.find('select.shop2-cf>option, li.shop2-cf, li.shop2-color-ext-selected, ul.shop2-color-ext-list>li').each(function () {
  23.                 var name = $(this).data('name');
  24.                 if (name) {
  25.                     keys[name] = true;
  26.                 }
  27.             });
  28.  
  29.            
  30.             if( shop2.productRefs ){
  31.                 let url = '';
  32.                 if( $form.find('.gr-product-name').length ){
  33.                     url = $form.find('.gr-product-name a').attr('href');
  34.                 }
  35.                 else if( $form.find('.gr-quick-more-btn') ){
  36.                     url = $form.find('.gr-quick-more-btn').attr('href');
  37.                 }
  38.                 $.get(url, function(data) {
  39.    
  40.                     var text = data ;
  41.                     const regex = /shop2\.init\(\s*({.*?"productRefs"\s*:\s*{.*?})\s*\)/s;
  42.                     const match = text.match(regex);
  43.                     if (match) {
  44.                         const productRefs = JSON.parse(match[1]); // Парсим JSON
  45.                         console.log(productRefs.productRefs); // Доступ к productRefs
  46.                    
  47.                         shop2.productRefs = productRefs.productRefs;
  48.                         kind_id = shop2.product.findKindId(product_id, kinds, paramName, paramValue, meta, keys, $node);
  49.                     }
  50.                    
  51.                 })
  52.             }else{
  53.                 kind_id = shop2.product.findKindId(product_id, kinds, paramName, paramValue, meta, keys, $node);   
  54.             }
  55.             setTimeout(function(){
  56.                 if (!kind_id) {
  57.                     kind_id = $form.find('[name=kind_id]').val();
  58.                     is_param_select = true;
  59.                 }
  60.                 // select
  61.                 $form.find('.js-calc-custom-fields.additional-cart-params').each(function () {
  62.                     var ref_code = $(this).attr('name');
  63.                     params[ref_code] = $(this).find('option:selected').data('item-id');
  64.                 });
  65.                 // colore ref
  66.                 $form.find('.js-calc-custom-fields.shop2-color-ext-selected').each(function () {
  67.                     var ref_code = $(this).data('name');
  68.                     params[ref_code] = $(this).data('item-id');
  69.                 });
  70.                 // Selected params
  71.                 if (is_param_select) {
  72.                     shop2.product.getProductListItem(product_id, kind_id, function (d, status) {
  73.                         if (status === 'success') {
  74.                             var body = $.trim(d.data.body);
  75.                             var product_price = $(".product-price", body).html();
  76.                             var product_actions = $(".shop2-product-actions", body).html();
  77.                             $form.find('.product-price').html(product_price);
  78.                             $form.find('.shop2-product-actions').html(product_actions);
  79.                             shop2.trigger('afterProductReloaded');
  80.                             shop2.queue.heights();
  81.                         }
  82.                     }, params);
  83.                 } else {
  84.                     if (shop2.mode === 'product') {
  85.                         if (shop2.uri) {
  86.                             document.location = shop2.uri + '/product/' + kind_id;
  87.                         } else {
  88.                             document.location = document.location.href.replace(/\/product\/.+/, '/product/' + kind_id);
  89.                         }
  90.                     } else {
  91.                         shop2.product.getProductListItem(product_id, kind_id, function (d, status) {
  92.                             var cont, newCont, body;
  93.                             if (status === 'success') {
  94.                                 shop2.trigger('afterProductReloaded');
  95.                                 cont = $node.closest('.shop2-product-item');
  96.                                 cont.hide();
  97.                                 body = $.trim(d.data.body);
  98.                                 newCont = $(body).insertBefore(cont);
  99.                                 cont.remove();
  100.                                 shop2.queue.heights();
  101.                             }
  102.                         }, params);
  103.                     }
  104.                 }
  105.             },1000)
  106.         }
  107.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement