Optimize Code for Multiple Anchor Recommendations

Passing multiple products anchors to Commerce Cloud Einstein enables you to support product recommendations from the items in a shoppers cart.

Using customer-specific items, Einstein recommends products tailored to the individual shopper that weren't suggested based on standard product recommendation methods. Some development work is required to process multiple product anchors. Personal implementation can vary substantially, but the API calls remain generally the same.

  1. Locate the shipments loop in cart.isml and implement the code as outlined below.
    Note: You can implement this method wherever you want to pass multiple anchors to the Commerce Cloud Einstein recommender.
    <iscomment> LOOP TO SEPARATE DIFFERENT SHIPMENTS ex: Gift Registry Shipments Etc.</iscomment> 
    <isloop items="${pdict.CurrentForms.cart.shipments}" var="Shipment" status="loopstate">
      // Add the following three lines:
        <isscript>
            var productCollection : dw.util.Collection = new dw.util.ArrayList(); 
        </isscript>
    <isloop items="${Shipment    .items}" alias="FormLi" status="loopstate"> 
        <isset name="lineItem" value="${FormLi.object}" scope="page" />
      // Add the following four lines: 
        <isscript>
            if (lineItem.catalogProduct) {
            productCollection.add(lineItem.product); }
        </isscript> 
    </isloop>
  2. Replace the existing recommendations slot with the new Einstein powered recommendation slot.
    <div class="cart-recommendations">
      // Add the following two lines:
        <isslot id="cart-multi3-product-collection" description="Multi for Cart page 3 - global - productCollection" 
            context="global" context-object="${productCollection}"/>
    </div>
    
X Privacy Update: We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used. By continuing to use this site you are giving us your consent to do this. Privacy Policy.