Loading
Feature Disruption - Service Cloud VoiceRead More
Feature degradation | Gmail Email delivery failureRead More
Get Started with B2C Commerce
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Optimize Code for Multiple Anchor Recommendations in B2C Commerce Einstein

          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.

          Required Editions

          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.

          Note
          Note Use this approach wherever you want to pass multiple anchors to the Commerce Cloud Einstein recommender. For example, in the shopper’s cart, product wish list, and order history. Also keep in mind that Einstein uses up to five products from the passed context-object as anchors for the recommendations.

          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:

          1. Locate the following line of code in cart.isml.
            <iscomment> LOOP TO SEPARATE DIFFERENT SHIPMENTS ex: Gift Registry Shipments Etc.</iscomment>
          2. Add the following code after the comment to create a productCollection array that gathers product anchors from the shopper’s cart:
            <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>
          3. Locate the following line of code:
            <isslot id="cart-footer" description="Footer for Cart page" context="global"/>
            
          4. Add the following slot definition after the cart footer line:
            <isslot id="slot-cart-reco-einstein" context="global" context-object="${productCollection}"
                       description="Einstein Recommendations on cart page"/>
            
          5. Save the file.
            Einstein product recommendations appear below the shopper’s cart footer on the page.
           
          Loading
          Salesforce Help | Article