|
31 | 31 | var product_info_url = '<?= /* @noEscape */ $block->getProductInfoUrl() ?>';
|
32 | 32 |
|
33 | 33 | $(document).on('ajax:addToCart', function (event, data) {
|
34 |
| - // check product data from swatch widget |
35 |
| - var swatchData = $('[data-role=swatch-options]').data('mage-SwatchRenderer'); |
36 |
| - if (swatchData) { |
37 |
| - var simpleProductId = swatchData.getProductId(); |
38 |
| - } else { |
39 |
| - // In case product is added from category page get options using added product's id |
40 |
| - // Get id of last added product |
41 |
| - var productId = data.productIds[data.productIds.length - 1]; |
42 |
| - var categorySwatchData = $('[data-role=swatch-option-'+productId+']').data('mage-SwatchRenderer'); |
43 |
| - if (categorySwatchData) { |
44 |
| - var simpleProductId = categorySwatchData.getProductId(); |
| 34 | + if (!data.response.backUrl) { |
| 35 | + // check product data from swatch widget |
| 36 | + var swatchData = $('[data-role=swatch-options]').data('mage-SwatchRenderer'); |
| 37 | + if (swatchData) { |
| 38 | + var simpleProductId = swatchData.getProductId(); |
45 | 39 | } else {
|
46 |
| - // else check product data from configurable options |
47 |
| - var configurableProduct = data.form.data().mageConfigurable; |
48 |
| - if(configurableProduct) { |
49 |
| - var simpleProductId = configurableProduct.simpleProduct; |
| 40 | + // In case product is added from category page get options using added product's id |
| 41 | + // Get id of last added product |
| 42 | + var productId = data.productIds[data.productIds.length - 1]; |
| 43 | + var categorySwatchData = $('[data-role=swatch-option-'+productId+']') |
| 44 | + .data('mage-SwatchRenderer'); |
| 45 | + if (categorySwatchData) { |
| 46 | + var simpleProductId = categorySwatchData.getProductId(); |
| 47 | + } else { |
| 48 | + // else check product data from configurable options |
| 49 | + var configurableProduct = data.form.data().mageConfigurable; |
| 50 | + if(configurableProduct) { |
| 51 | + var simpleProductId = configurableProduct.simpleProduct; |
| 52 | + } |
50 | 53 | }
|
51 | 54 | }
|
| 55 | + // otherwise use the product sku |
| 56 | + var product_sku = data.sku; |
| 57 | + var form_key = jQuery("[name='form_key']").val(); |
| 58 | + $.ajax({ |
| 59 | + url: product_info_url, |
| 60 | + data: { |
| 61 | + product_sku: product_sku, |
| 62 | + product_id: simpleProductId, |
| 63 | + form_key: form_key |
| 64 | + }, |
| 65 | + type: 'post', |
| 66 | + dataType: 'json', |
| 67 | + success: function (res) { |
| 68 | + trackAddToCart( |
| 69 | + [res.id], |
| 70 | + res.name, |
| 71 | + res.content_category, |
| 72 | + res.value, |
| 73 | + res.event_id |
| 74 | + ); |
| 75 | + } |
| 76 | + }); |
52 | 77 | }
|
53 |
| - // otherwise use the product sku |
54 |
| - var product_sku = data.sku; |
55 |
| - var form_key = jQuery("[name='form_key']").val(); |
56 |
| - $.ajax({ |
57 |
| - url: product_info_url, |
58 |
| - data: { |
59 |
| - product_sku: product_sku, |
60 |
| - product_id: simpleProductId, |
61 |
| - form_key: form_key |
62 |
| - }, |
63 |
| - type: 'post', |
64 |
| - dataType: 'json', |
65 |
| - success: function (res) { |
66 |
| - trackAddToCart( |
67 |
| - [res.id], |
68 |
| - res.name, |
69 |
| - res.content_category, |
70 |
| - res.value, |
71 |
| - res.event_id |
72 |
| - ); |
73 |
| - } |
74 |
| - }); |
75 | 78 | });
|
76 | 79 | });
|
77 | 80 | </script>
|
|
0 commit comments