From 78f2eb67069446ccf178550be81443ef720cbe68 Mon Sep 17 00:00:00 2001 From: yunakim714 Date: Thu, 2 Feb 2023 17:00:00 -0500 Subject: [PATCH 1/4] verify viewcategory and viewsearch is working --- .../template-retail-react-app/app/commerce-api/einstein.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/template-retail-react-app/app/commerce-api/einstein.js b/packages/template-retail-react-app/app/commerce-api/einstein.js index bb1389f614..0ca5d71005 100644 --- a/packages/template-retail-react-app/app/commerce-api/einstein.js +++ b/packages/template-retail-react-app/app/commerce-api/einstein.js @@ -57,7 +57,7 @@ class EinsteinAPI { * Given a product or item source, returns the product data that Einstein requires */ _constructEinsteinProduct(product) { - if (product.type && (product.type.master || product.type.variant)) { + if (product.type && (product.type.master || product.type.variant )) { // handle variants for PDP / viewProduct // Assumes product is a Product object from SCAPI Shopper-Products: // https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-products?meta=type%3AProduct @@ -69,7 +69,7 @@ class EinsteinAPI { } } else if ( product.productType && - (product.productType.master || product.productType.variant) + (product.productType.master || product.productType.variant || product.productType.set) ) { // handle variants for PLP / viewCategory & viewSearch // Assumes product is a ProductSearchHit from SCAPI Shopper-Search: From a8b8dd550e11e8ea59e7e2a2f329d2017c752e2c Mon Sep 17 00:00:00 2001 From: yunakim714 Date: Mon, 6 Feb 2023 10:40:06 -0500 Subject: [PATCH 2/4] viewproduct event is sent for every child product --- .../app/commerce-api/einstein.js | 12 ++++++++++-- .../app/pages/product-detail/index.jsx | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/template-retail-react-app/app/commerce-api/einstein.js b/packages/template-retail-react-app/app/commerce-api/einstein.js index 0ca5d71005..032c044075 100644 --- a/packages/template-retail-react-app/app/commerce-api/einstein.js +++ b/packages/template-retail-react-app/app/commerce-api/einstein.js @@ -57,7 +57,7 @@ class EinsteinAPI { * Given a product or item source, returns the product data that Einstein requires */ _constructEinsteinProduct(product) { - if (product.type && (product.type.master || product.type.variant )) { + if (product.type && (product.type.master || product.type.variant)) { // handle variants for PDP / viewProduct // Assumes product is a Product object from SCAPI Shopper-Products: // https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-products?meta=type%3AProduct @@ -67,11 +67,19 @@ class EinsteinAPI { altId: '', altIdType: '' } + } else if (product.type && product.type.set) { + // handle sets for viewProduct + return { + id: product.id, + sku: product.id, + altId: '', + altIdType: '' + } } else if ( product.productType && (product.productType.master || product.productType.variant || product.productType.set) ) { - // handle variants for PLP / viewCategory & viewSearch + // handle variants & sets for PLP / viewCategory & viewSearch // Assumes product is a ProductSearchHit from SCAPI Shopper-Search: // https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-search?meta=type%3AProductSearchHit return { diff --git a/packages/template-retail-react-app/app/pages/product-detail/index.jsx b/packages/template-retail-react-app/app/pages/product-detail/index.jsx index 434c10264b..a46db4087a 100644 --- a/packages/template-retail-react-app/app/pages/product-detail/index.jsx +++ b/packages/template-retail-react-app/app/pages/product-detail/index.jsx @@ -171,7 +171,13 @@ const ProductDetail = ({category, product, isLoading}) => { /**************** Einstein ****************/ useEffect(() => { - if (product) { + if (product && product.type.set) { + einstein.sendViewProduct(product) + const childrenProducts = product.setProducts + childrenProducts.map((child) => { + einstein.sendViewProduct(child) + }) + } else if (product) { einstein.sendViewProduct(product) } }, [product]) From 1a34505cbc0ff610647bd9f6acd6f9a742400014 Mon Sep 17 00:00:00 2001 From: yunakim714 Date: Mon, 6 Feb 2023 10:56:02 -0500 Subject: [PATCH 3/4] addtocart event fires for all children when add set to cart --- .../app/commerce-api/hooks/useBasket.js | 2 +- .../app/pages/product-detail/index.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/template-retail-react-app/app/commerce-api/hooks/useBasket.js b/packages/template-retail-react-app/app/commerce-api/hooks/useBasket.js index 0dd23e1bb1..8e085a21e1 100644 --- a/packages/template-retail-react-app/app/commerce-api/hooks/useBasket.js +++ b/packages/template-retail-react-app/app/commerce-api/hooks/useBasket.js @@ -123,7 +123,7 @@ export default function useBasket(opts = {}) { throw new Error(response) } else { setBasket(response) - einstein.sendAddToCart(item[0]) + item.map((eachItem) => einstein.sendAddToCart(eachItem)) } }, diff --git a/packages/template-retail-react-app/app/pages/product-detail/index.jsx b/packages/template-retail-react-app/app/pages/product-detail/index.jsx index a46db4087a..dc5966ee6a 100644 --- a/packages/template-retail-react-app/app/pages/product-detail/index.jsx +++ b/packages/template-retail-react-app/app/pages/product-detail/index.jsx @@ -176,7 +176,7 @@ const ProductDetail = ({category, product, isLoading}) => { const childrenProducts = product.setProducts childrenProducts.map((child) => { einstein.sendViewProduct(child) - }) + }) } else if (product) { einstein.sendViewProduct(product) } From 649ebf4a66201d78304a413bcdbf840269d8512f Mon Sep 17 00:00:00 2001 From: yunakim714 Date: Tue, 7 Feb 2023 11:04:06 -0500 Subject: [PATCH 4/4] parent set only sends id --- .../app/commerce-api/einstein.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/template-retail-react-app/app/commerce-api/einstein.js b/packages/template-retail-react-app/app/commerce-api/einstein.js index 032c044075..0c9b546c9b 100644 --- a/packages/template-retail-react-app/app/commerce-api/einstein.js +++ b/packages/template-retail-react-app/app/commerce-api/einstein.js @@ -67,14 +67,6 @@ class EinsteinAPI { altId: '', altIdType: '' } - } else if (product.type && product.type.set) { - // handle sets for viewProduct - return { - id: product.id, - sku: product.id, - altId: '', - altIdType: '' - } } else if ( product.productType && (product.productType.master || product.productType.variant || product.productType.set)