You are here:
Optimize Code for Multiple Anchor Recommendations in B2C Commerce Einstein
Pass multiple product anchors to B2C Commerce Einstein to provide product recommendations based on customer-specific items.

Use more general search terms.
Select fewer filters to broaden your search.
Pass multiple product anchors to B2C Commerce Einstein to provide product recommendations based on customer-specific items.
| Available in: B2C Commerce |
We recommend passing the basket object as a context-object in the isslot tag. But if there are added criteria for filtering out the products, we recommend that you use the approach described here to assemble a collection of products for the context-object.
Some development work is required to process multiple product anchors. Personal implementation can vary substantially, but API calls remain generally the same.
To pass multiple product anchors to Einstein from a shopper’s cart:
cart.isml.
<iscomment> LOOP TO SEPARATE DIFFERENT SHIPMENTS ex: Gift Registry Shipments Etc.</iscomment>
<isscript>
var ArrayList = require('dw/util/ArrayList');
var productCollection = new ArrayList();
for (var itemIndex in pdict.Basket.productLineItems) {
var lineItem = pdict.Basket.productLineItems[itemIndex];
if (lineItem.catalogProduct) {
productCollection.add(lineItem.product);
}
}
</isscript>
<isslot id="cart-footer" description="Footer for Cart page" context="global"/>
<isslot id="slot-cart-reco-einstein" context="global" context-object="${productCollection}"
description="Einstein Recommendations on cart page"/>

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.