Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

v1.0.24
- Added compatibility of add_to_cart_stape event with Swissuplab theme
- Fixed issue with the overridden price formatter pattern
- added caching of cookie domain when generating _sbp cookie

v1.0.23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ define([
*/
function prepareItems() {
const cartData = customerData.get('cart')();
const priceFormat = Object.assign(quote.getPriceFormat(), {'pattern': '%s'});
const priceFormat = Object.assign({...quote.getPriceFormat()}, {'pattern': '%s'});
return quote.getItems().map(function(itemDetails) {
cartData.items.find
const cartItem = _.find(cartData.items, function(cartItem) {
Expand Down
73 changes: 38 additions & 35 deletions view/frontend/web/js/datalayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ define([
&& JSON.stringify(values.sort()) === JSON.stringify(productInfo.optionValues.sort());
}

return item.product_id == productInfo.id;
return item.product_id == productInfo.id || productInfo.id == item?.child_product_id;
});
}

Expand All @@ -65,42 +65,45 @@ define([
dataLayer.push(config.data);
}
cartData.subscribe(function(data) {
const itemDetails = findItem(lastAddedProduct())
if (wasAddToCartCalled) {
dataLayer.push({ecommerce: null});
window.dataLayer.push({
event: 'add_to_cart_stape',
ecomm_pagetype: 'product',
ecommerce: {
currency: config?.data?.ecommerce?.currency,
items: [
{
'item_name': itemDetails.product_name,
'item_id': itemDetails.product_id,
'item_sku': itemDetails.product_sku,
'item_category': itemDetails.category,
'price': itemDetails.product_price_value,
'quantity': itemDetails.qty,
'variation_id': itemDetails.child_product_id ? itemDetails.child_product_id : undefined
}
]
}
});
const itemDetails = findItem(lastAddedProduct());
try {
if (wasAddToCartCalled && itemDetails) {
dataLayer.push({ecommerce: null});
window.dataLayer.push({
event: 'add_to_cart_stape',
ecomm_pagetype: 'product',
ecommerce: {
currency: config?.data?.ecommerce?.currency,
items: [
{
'item_name': itemDetails.product_name,
'item_id': itemDetails.product_id,
'item_sku': itemDetails.product_sku,
'item_category': itemDetails.category,
'price': itemDetails.product_price_value,
'quantity': itemDetails.qty,
'variation_id': itemDetails.child_product_id ? itemDetails.child_product_id : undefined
}
]
}
});
}

if (data?.stape_gtm_events?.remove_from_cart_stape) {
dataLayer.push({ecommerce: null});
window.dataLayer.push({
event: 'remove_from_cart_stape',
ecomm_pagetype: 'basket',
ecommerce: {
currency: config?.data?.ecommerce?.currency,
items: data?.stape_gtm_events?.remove_from_cart_stape?.items,
}
})
}
} catch(err) {
console.error(err);
}

if (data?.stape_gtm_events?.remove_from_cart_stape) {
dataLayer.push({ecommerce: null});
window.dataLayer.push({
event: 'remove_from_cart_stape',
ecomm_pagetype: 'basket',
ecommerce: {
currency: config?.data?.ecommerce?.currency,
items: data?.stape_gtm_events?.remove_from_cart_stape?.items,
}
})
}


wasAddToCartCalled = false;
lastAddedProduct(null);
});
Expand Down
Loading