How to get abandoned shopping cart data in email template.

harshal bundelkhandi asked on May 4, 2020 05:08

Hi Support,

I am planning to set reminder email to the customer about abandoned shopping cart items in my mvc 12 sp application.For the shopping cart items i am using macro expression to get list of products to get in email templates. in the email template i am inserting below macro expression.but it is not working.any idea how to get abandoned shopping cart items. i have tried below shopping cart macro expression as well.i am able to find the transformation for dancing goat site as well.

https://docs.kentico.com/k12sp/on-line-marketing-features/configuring-and-customizing-your-on-line-marketing-features/configuring-marketing-automation/walkthrough-sending-an-automated-reminder-of-an-abandoned-shopping-cart#WalkthroughSendinganautomatedreminderofanabandonedshoppingcart-Creatingascheduledtaskformarkingshoppingcartsasabandoned

{% foreach(item in ContentTable) { %}

          <tr>
            <td style="text-align: left;">{%(item.IsProductOption) ? "&nbsp;&nbsp;&nbsp;" : ""%}{% Localize(item.SKUName)|(encode)true %}
              {% (item.CartItemText != "") ? " '" + item.CartItemText + "' " : "" |(encode)true %}
              {% item.SKUNumber|(encode)true |(identity)GlobalAdministrator %}</td>
            <td style="text-align: right; vertical-align: top;">{%(item.IsProductOption && !item.IsAccessoryProduct) ? "" : item.Units %}</td>
            <td style="text-align: right; vertical-align: top;">{%(item.IsProductOption && !item.IsAccessoryProduct) ? "" : (item.UnitPrice - item.UnitTotalDiscount).Format(Currency.CurrencyFormatString)|(encode)true %}</td>
            <td style="text-align: right; vertical-align: top;">{%(item.IsProductOption && !item.IsAccessoryProduct) ? "" : item.TotalPrice.Format(Currency.CurrencyFormatString)|(encode)true %}</td>
          </tr>
          {% } #%}

Thanks, Harshal

Correct Answer

Dmitry Bastron answered on May 4, 2020 11:10

This appears to be an error in the documentation: this transformation doesn't exist in Dancing Goat MVC site. But if you install Portal Engine site - you will see it. Typically, transformations are created in some container page type (even though doc says it's Portal Engine, it still can be used in MVC for email templates). Applying transformations is not mandatory, it is just another way of doing foreach cycle. And another good thing is that you can reuse this code if you need to (for example if you have multiple shopping cart related emails).

To the code, DancingGoat.Transformations.AbandonedCartProducts contains the following code:

<div id="item">
  <a href="http://{%CurrentSite.SiteDomainName + GetProductUrl(SKU.SKUID)#%}">
    <img width="300px" src="{%GetAbsoluteUrlBySiteID(IfEmpty(SKU.SKUImagePath, SKU.Parent.SKUImagePath, SKU.SKUImagePath), CurrentSite.SiteID)#%}" />
  </a>
  <p>{% FormatPriceForCart(UnitPrice, ShoppingCartID)%}</p>
  <p>{% SKU.SKUName #%}</p>
</div>

So what you can do:

  • create your own container page type, e.g. YourSite.Transformations
  • under Transformation tab create new AbandonedCartProducts transformation and paste you code there (similar to the code above)
  • in the email template use your transformation name instead of DancingGoat, i.e. YourSite.Transformations.AbandonedCartProducts
0 votesVote for this answer Unmark Correct answer

Recent Answers


Dmitry Bastron answered on May 4, 2020 10:35

Hi Harshal,

Check your trigger for marketing automation: is it Activity - Shopping cart abandoned? How do you populate ContentTable variable in your code? It should be done similar to the example from the link you posted: ShoppingCartProducts(ActivityValue). ActivityValue should be the ID of your abandoned shopping cart.

0 votesVote for this answer Mark as a Correct answer

harshal bundelkhandi answered on May 4, 2020 10:51

Hi Dmitry, Thank you for your reply. Yes marketing trigger is correct. I just wanted to know where the transformation is configured. as per below example mentioned.

"DancingGoat.Transformations.AbandonedCartProducts" I have created email template in global site object as a email type Automation. below code is not working . here is my code:

{%// Gets the site object on which the "Shopping cart abandoned" activity occurred

site = System.GetObject("cms.site", Activity.ActivitySiteID);

// Returns the URL of the shopping cart page with the restored content of the abandoned shopping cart "http://" + site.SiteDomainName + ShoppingCartURL(site.SiteName,Activity.ActivityValue)#%}

{% // Gets a list of the items (products) in the abandoned shopping carts and displays them using the specified transformation ShoppingCartProducts(Activity.ActivityValue).ApplyTransformation("DancingGoatMvc.Cafe.Emailtemplate")|(encode)false #%}

    {% Activity.ActivityValue #%}

Another macro expression are working fine. i have issue with Current contact abandoned shopping cart item. need to sent with transformation.

0 votesVote for this answer Mark as a Correct answer

harshal bundelkhandi answered on May 4, 2020 20:40

Hi Dmitry,

As you suggested for the transformation.i have created the transformation. it is working now. now i am getting issue for macros "Activity value". not able to get shopping cart GUID. it is giving null.can you suggest me how can i get ActivityValue

ShoppingCartProducts(ActivityValue)

by below way i am getting the value. {%ShoppingCartProducts(ContactManagementContext.CurrentContact.Activities.Where("ActivityType='ShoppingCartAbandoned'").TopN(1).OrderBy("ActivityID").ActivityType.ActivityValue).ApplyTransformation("Ecommerce.Transformations.AbandonedCartProducts")|(encode)false #%}

Thanks, Harshal

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 4, 2020 23:13

Dear Harshal,

Hmm, it should be easier, this macro should return a collection of shopping cart items (ActivityValue will be resolved into shopping cart guide automatically in marketing automation if trigger is set to activity - shopping cart abandoned):

{% ShoppingCartProducts(ActivityValue) %)

So that you can event do a foreach cycle without transformation (or apply transformation if you need to):

{% foreach (cartItem in ShoppingCartProducts(ActivityValue) { %)
    <p>{% FormatPriceForCart(cartItem.UnitPrice, cartItem.ShoppingCartID)%}</p>
    <p>{% cartItem.SKU.SKUName #%}</p>
{% } %}
0 votesVote for this answer Mark as a Correct answer

harshal bundelkhandi answered on May 5, 2020 11:35

Hi Dmitry, As per the documentation & you have suggested. i have setup the automation process.

now current marketing automation process is like below:

scheduleTask will run task --->It will check the shopping cart which are going to be set in abandoned in com_Activity DB table.

Trigger will run the Step sent email.

Still it is not getting shopping cart Activity value in the email template.

Is there any way to get shopping cart Activity value in the email template.

Thanks, Harshal

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 5, 2020 11:54

Can you check in the database that your activities have actual values? Run this select and look at the ActivityValue column, does it contain cart GUID?

select *
from OM_Activity
where activitytype = 'ShoppingCartAbandoned'
0 votesVote for this answer Mark as a Correct answer

harshal bundelkhandi answered on May 5, 2020 12:20

Hi Dmitry,

From above query Column "ActivityValue" contains the GUID.

i have one more question for contact it is containing more than one abandoned shopping cart in the DB table. Contact contains more than one shopping cart in the table "OM_Activity"

Thanks, Harshal

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 5, 2020 12:48

Can you post a screenshot of your Marketing Automation process with the details of email step? And also full text of email template (you can remove all branding and unnecessary content markup leaving only parts with macroses). That would be easier to help you.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.