Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shop2.product._reload = function (node) {
- var $node = $(node);
- var kinds = shop2.product.getNodeData(node, 'kinds', true);
- var paramName = shop2.product.getNodeData(node, 'name');
- var paramValue = shop2.product.getNodeData(node, 'value');
- var $form = $node.closest('form');
- var form = $form.get(0);
- var meta;
- var kind_id;
- var product_id;
- var keys = {};
- var params = {};
- var is_param_select = false;
- window.gr_reloaded_product_node = $node.parents('.shop2-product-item');
- window.gr_reloaded_product_index = $node.parents('.shop2-product-item').index();
- if (kinds && $.type(paramName) !== 'undefined' && $.type(paramValue) !== 'undefined' && form) {
- meta = $form.find('input[name=meta]').val();
- product_id = $form.find('input[name=product_id]').val();
- $form.find('[name=submit]').prop('disabled', true);
- $form.find('select.shop2-cf>option, li.shop2-cf, li.shop2-color-ext-selected, ul.shop2-color-ext-list>li').each(function () {
- var name = $(this).data('name');
- if (name) {
- keys[name] = true;
- }
- });
- if( shop2.productRefs ){
- let url = '';
- if( $form.find('.gr-product-name').length ){
- url = $form.find('.gr-product-name a').attr('href');
- }
- else if( $form.find('.gr-quick-more-btn') ){
- url = $form.find('.gr-quick-more-btn').attr('href');
- }
- $.get(url, function(data) {
- var text = data ;
- const regex = /shop2\.init\(\s*({.*?"productRefs"\s*:\s*{.*?})\s*\)/s;
- const match = text.match(regex);
- if (match) {
- const productRefs = JSON.parse(match[1]); // Парсим JSON
- console.log(productRefs.productRefs); // Доступ к productRefs
- shop2.productRefs = productRefs.productRefs;
- kind_id = shop2.product.findKindId(product_id, kinds, paramName, paramValue, meta, keys, $node);
- }
- })
- }else{
- kind_id = shop2.product.findKindId(product_id, kinds, paramName, paramValue, meta, keys, $node);
- }
- setTimeout(function(){
- if (!kind_id) {
- kind_id = $form.find('[name=kind_id]').val();
- is_param_select = true;
- }
- // select
- $form.find('.js-calc-custom-fields.additional-cart-params').each(function () {
- var ref_code = $(this).attr('name');
- params[ref_code] = $(this).find('option:selected').data('item-id');
- });
- // colore ref
- $form.find('.js-calc-custom-fields.shop2-color-ext-selected').each(function () {
- var ref_code = $(this).data('name');
- params[ref_code] = $(this).data('item-id');
- });
- // Selected params
- if (is_param_select) {
- shop2.product.getProductListItem(product_id, kind_id, function (d, status) {
- if (status === 'success') {
- var body = $.trim(d.data.body);
- var product_price = $(".product-price", body).html();
- var product_actions = $(".shop2-product-actions", body).html();
- $form.find('.product-price').html(product_price);
- $form.find('.shop2-product-actions').html(product_actions);
- shop2.trigger('afterProductReloaded');
- shop2.queue.heights();
- }
- }, params);
- } else {
- if (shop2.mode === 'product') {
- if (shop2.uri) {
- document.location = shop2.uri + '/product/' + kind_id;
- } else {
- document.location = document.location.href.replace(/\/product\/.+/, '/product/' + kind_id);
- }
- } else {
- shop2.product.getProductListItem(product_id, kind_id, function (d, status) {
- var cont, newCont, body;
- if (status === 'success') {
- shop2.trigger('afterProductReloaded');
- cont = $node.closest('.shop2-product-item');
- cont.hide();
- body = $.trim(d.data.body);
- newCont = $(body).insertBefore(cont);
- cont.remove();
- shop2.queue.heights();
- }
- }, params);
- }
- }
- },1000)
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement