Skip to content

Commit

Permalink
fix v2 for add_to_cart/remove + add_to_wishlist
Browse files Browse the repository at this point in the history
  • Loading branch information
joeljxse committed Mar 20, 2024
1 parent b171ccb commit 2e5e918
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
38 changes: 26 additions & 12 deletions src/es/components/controllers/tagManager/TagManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class MigrosProTagManager extends TagManager {
super.connectedCallback()
document.body.addEventListener(this.getAttribute('add-basket') || 'add-basket', this.addBasketListener)
document.body.addEventListener(this.getAttribute('remove-basket') || 'remove-basket', this.removeBasketListener)
// document.body.addEventListener(this.getAttribute('add-wishlist') || 'add-wishlist', this.addWishlistListener)
document.body.addEventListener(this.getAttribute('request-favorite-event-name') || 'request-favorite-event-name', this.addWishlistListener)
document.body.addEventListener(this.getAttribute('list-product') || 'list-product', this.listProductListener)
document.body.addEventListener(this.getAttribute('product-clicked') || 'product-clicked', this.clickProductListener)
document.body.addEventListener(this.getAttribute('product-viewed') || 'product-viewed', this.viewProductListener)
Expand All @@ -64,7 +64,7 @@ export default class MigrosProTagManager extends TagManager {
super.disconnectedCallback()
document.body.removeEventListener(this.getAttribute('add-basket') || 'add-basket', this.addBasketListener)
document.body.removeEventListener(this.getAttribute('remove-basket') || 'remove-basket', this.removeBasketListener)
// document.body.removeEventListener(this.getAttribute('add-wishlist') || 'add-wishlist', this.addWishlistListener)
document.body.removeEventListener(this.getAttribute('request-favorite-event-name') || 'request-favorite-event-name', this.addWishlistListener)
document.body.removeEventListener(this.getAttribute('list-product') || 'list-product', this.listProductListener)
document.body.removeEventListener(this.getAttribute('product-clicked') || 'product-clicked', this.clickProductListener)
document.body.removeEventListener(this.getAttribute('product-viewed') || 'product-viewed', this.viewProductListener)
Expand All @@ -77,13 +77,25 @@ export default class MigrosProTagManager extends TagManager {
basketListener = (event, action) => {
event.detail.tags.forEach((el) => {
let item = this.items?.find((element) => element.item_id === el)
if (!item) { // for product detail page (razor page in backend solution)
item = JSON.parse(localStorage.getItem('productDetailItemObject') || '{}')
}
const schemaItem = this.loop(this.itemSchema, item)
if (action === 'add_to_cart' || action === 'add_to_wishlist') schemaItem.quantity = 1
if (action === 'add_to_cart' || action === 'add_to_wishlist' || action === 'remove_from_cart') schemaItem.quantity = 1

if (item) {
let currentQuantity = parseInt(item['quantity'])
if (currentQuantity) {
// update this.items so that quantity is always correct for delete from cart event
if (action === 'add_to_cart') {
item['quantity'] = currentQuantity + 1
} else if (action === 'remove_from_cart') {
item['quantity'] = currentQuantity - 1
}
// delete from cart is a pseudo event, made to differentiate between only removing 1 from cart or the whole article
if (action === 'pseudoEvent-delete_from_cart') {
schemaItem.quantity = currentQuantity
action = 'remove_from_cart'
}
}

const eventToCart = {
event: action,
ecommerce: {
Expand All @@ -106,8 +118,14 @@ export default class MigrosProTagManager extends TagManager {
this.basketListener(event, 'remove_from_cart')
}

addFavoriteListener = (event) => {
this.basketListener(event, 'add_to_wishlist')
deleteFromOrderListener = (event) => {
this.basketListener(event, 'pseudoEvent-delete_from_cart')
}

addWishlistListener = (event) => {
if (event.detail?.action === 'add') {
this.basketListener(event, 'add_to_wishlist')
}
}

requestListBasketListener = (event) => {
Expand All @@ -122,10 +140,6 @@ export default class MigrosProTagManager extends TagManager {
console.log('submitOrderListener', event)
}

deleteFromOrderListener = (event) => {
this.basketListener(event, 'remove_from_cart')
}

listProductListener = (event) => {
/**
* @typedef {Object} VAT
Expand Down
2 changes: 1 addition & 1 deletion src/es/components/web-components-toolbox
Submodule web-components-toolbox updated 29 files
+1 −0 docs/Template.html
+0 −8 docs/TemplateMiduweb.html
+1 −0 docs/TemplateNoControllers.html
+1 −2 package.json
+0 −22 src/css/style.css
+1 −1 src/es/components/atoms/iconMdx/IconMdx.js
+1 −1 src/es/components/atoms/menuIcon/MenuIcon.js
+1 −1 src/es/components/atoms/oneTrust/OneTrust.js
+1 −1 src/es/components/molecules/checkout/Checkout.js
+1 −1 src/es/components/molecules/details/default-/default-.css
+22 −38 src/es/components/molecules/dialog/Dialog.js
+4 −7 src/es/components/molecules/dialog/left-slide-in-/left-slide-in-.css
+0 −1 src/es/components/molecules/metaHeader/MetaHeader.js
+0 −1 src/es/components/molecules/metaHeader/default-/default-.css
+23 −34 src/es/components/molecules/navigation/migrospro-/migrospro-.css
+2 −10 src/es/components/molecules/productList/ProductList.js
+323 −458 src/es/components/molecules/simpleForm/SimpleForm.js
+11 −16 src/es/components/molecules/simpleForm/default-/conditional.html
+0 −4 src/es/components/molecules/simpleForm/default-/default-.css
+1 −1 src/es/components/organisms/grid/12er-/12er-.css.js
+0 −71 src/es/components/organisms/grid/2columns-content-stage-/2columns-content-stage-.css
+1 −1 src/es/components/organisms/header/default-/default-.css
+1 −0 src/es/components/prototypes/Shadow.js
+1 −1 src/icons/mdx-main-packages-icons-dist-svg/packages/icons/dist/svg/HeartFilled/Size_16x16.svg
+1 −1 src/icons/mdx-main-packages-icons-dist-svg/packages/icons/dist/svg/HeartFilled/Size_24x24.svg
+1 −1 src/icons/mdx-main-packages-icons-dist-svg/packages/icons/dist/svg/HeartFilled/Size_32x32.svg
+1 −1 src/icons/mdx-main-packages-icons-dist-svg/packages/icons/dist/svg/HeartFilled/Size_40x40.svg
+1 −1 src/icons/mdx-main-packages-icons-dist-svg/packages/icons/dist/svg/HeartFilled/Size_48x48.svg
+1 −1 src/icons/mdx-main-packages-icons-dist-svg/packages/icons/dist/svg/HeartFilled/Size_56x56.svg

0 comments on commit 2e5e918

Please sign in to comment.