Skip to content

Commit 806e25b

Browse files
committed
Send all products in cart as context
1 parent 13fc0ca commit 806e25b

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

examples/cart-shelf.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,20 @@
517517
})
518518
})
519519
.then(function (ctx) {
520-
var items = (ctx.orderForm.items || []).map(function (it) {
521-
return String(it.productId)
522-
})
523-
var productIds = Array.from(new Set(items.filter(Boolean)))
520+
// Use every item in the orderForm as product context for the recommendations
521+
// request. We filter out items without a productId first to avoid the
522+
// String(undefined) === "undefined" pitfall, then dedupe to keep a single
523+
// entry per product even when multiple SKUs of the same product are in the cart.
524+
var orderFormItems = ctx.orderForm.items || []
525+
var productIds = Array.from(
526+
new Set(
527+
orderFormItems
528+
.map(function (it) {
529+
return it && it.productId ? String(it.productId) : ''
530+
})
531+
.filter(Boolean)
532+
)
533+
)
524534
return fetchRecommendations(account, ctx.userId, campaignVrn, productIds)
525535
.then(function (data) {
526536
return {

0 commit comments

Comments
 (0)