Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Einstein API to support product sets #962

Merged
merged 4 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 10 additions & 2 deletions packages/template-retail-react-app/app/commerce-api/einstein.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

@vcua-mobify vcua-mobify Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for product sets we can avoid having a separate case and let any product within the set that doesn't have variants fall through to the else block.

That's because I'm not sure if it's relevant for us to be sending 'sku' if it is the same as the regular 'id'.

Also, are there any changes we need to make in einstein.test.js?

Otherwise, the changes look good to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The einstein test file only tests for whether the event sends the expected api request. I don't think any changes need to be made since there are no new events.

altId: '',
altIdType: ''
}
} 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
// 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down