top of page

Cart to Order Data Mapping

Writer's picture: Shane SmythShane Smyth

A common question that I get while answering community questions about Salesforce B2B Commerce Cloud is "How do I map my custom fields / objects associated with the cart record over to the order summary records?". This is a fairly common question because almost every commerce site has a bit of customization, after all, that's the power of the Salesforce platform!


We'll start with the first concept, mapping custom fields on the existing objects onto the order summary. In a upcoming post, we'll cover the concept of mapping custom objects once an order is placed.


Mapping Cart Fields to Order Fields in Salesforce B2B Commerce Cloud


Let's start by setting up an example that we'll follow through the lifecycle.


Scenario:

Imagine you're working on building a commerce storefront and you identify there is a requirement that you need to order the carts items when you show the cart to the customer.

Cart Page Sort Order

This is pretty common in manufacturing and other highly technical industries, customers want to be able to manually sort their carts and this sort order needs to be retained and also maintained throughout the order when it's submitted into ERP.


How would you accomplish this?

Well right out of the gate we can identify a few things that are important:

  1. This isn't something that can be accomplished out of the box

  2. We likely will need at least one custom field on the cart item in order to save the sort the customer decides on

  3. We want to make sure this sort order makes it way to order as well when the order is submitted into ERP

  4. We are going to need to update a few components in order to visually show


Luckily for us, there is some native functionality that will help us solve #2 and #3! This is where the standard "Map Cart Data to Order Data" comes in. This feature is responsible for mapping custom fields between "common" objects, and supported data types.



There are four conditions that the field must meet in order to be synced over at a high level:

  1. The field must be a supported data type (the full list is included in the documentation link above, but a key note is that lookup fields are not supported)

  2. There must be an exactly matching field on the downstream corresponding objects (more on this in a bit)

  3. The feature must be enabled (this is true by default, unless you've manually turned it off)

  4. The field must map through all necessary objects (more on this in a moment)


Mapped Objects

To provide a bit of a clearer picture then the documentation does, the following table is how the tables will map between a Cart, Order, and Order Summary record.

Even though you may not use the Order objects, it is required to have a matching field on that columns respective object for the field to be correctly mapped to the Order Summary objects.

Cart to Order Sync

Cart

Order

Order Summary

Cart

Order

Order Summary

Cart Item

Order Item

Order Product Summary

Cart Item Price Adjustment

Order Item Adjustment Line Item

Order Product Adjustment Line Summary

Cart Tax

Order Item Tax Line Item

Order Product Tax Line Item Summary

Cart Delivery Group

Order Delivery Group

Order Delivery Group Summary

Web Cart Adjustment Group

Order Adjustment Group

Order Adjustment Group Summary

I've seen many people create a field on the Cart and Order Summary objects that match #1 - #3 criteria mentioned above, but they forget to create the same object on the Order objects which causes the sync not to work.


Put in a visual example, here is the Sort Order example we're about to go over:

Visual of the mapping objects
Mapping will not work.
Visual of the mapping object working.
Mapping will work.

Without the field on the Order Item as well, the mapping will not correctly bring the values onto the Order Product Summary record.



Walkthrough of the Scenario

Now that we have the foundation understood, let's go through our scenario and set it up. What we're going to need is a new number field to store this sort order information. We'd like this to be called 'Sort Order' and have that field be a data type of 'Number'. Again, we want to capture that information when the user is visually changing the sorting in the Cart Page, but we want to make sure that sort order is kept when the order summary is created.


Step 1 - Create the Cart Item Field

Navigate to Setup > Objects > Cart Item.

Create a new fields called 'Sort Order' of type 'Number'. The field should look like this when you're done:

Cart Item Field

Step 2 - Create the Order Item Field

Navigate to Setup > Objects > Cart Item.

Create a new fields called 'Sort Order' of type 'Number'. The field should look like this when you're done:

Order Product Field

Step 3 - Create the Order Product Summary Field

Navigate to Setup > Objects > Cart Item.

Create a new fields called 'Sort Order' of type 'Number'. The field should look like this when you're done:

Order Product Summary Field


Step 4 - Test the mapping

Now that we have all those fields created, we're going to want to generate a new cart. You can do this by logging in as a test user and adding an item to your cart.


If you don't already have a storefront setup, go ahead and navigate over to my getting started video


For this test, you'll need to update the Sort Order values manually since we don't have a custom UI to manage that for us in the experience. Updating the cart item can be accomplished many ways, but once you've done that you should see the values show up on the Cart Items. (I've added the field in this screenshot below to my Cart Items related list to make it easier to see these values)

Cart Item Sort Order

Now place your order in the storefront! This will take your cart, and create a order & order summary record. If you've followed the above steps correctly, you'll find that you now have an order summary with the custom field on the order product summary records!

Order Product Summary Sort Order

If you're looking for more information on how to turn off this functionality you can find that by looking at this documentation article: https://developer.salesforce.com/docs/commerce/salesforce-commerce/guide/b2b-b2c-comm-disable-cart-to-order-mappings-for-custom-fields.html


Congrats! You've now successfully mapped a custom fields across the cart to order life cycle! In one of the coming blogs, we'll cover custom object mapping. This is slightly more difficult because there is not a native service to assist in that mapping process. However, it's a fairly common practice to have a few custom objects associated to your cart process.

Join the Club

Join our email list and never miss a new article or video launch!

Thanks for submitting!

  • Youtube
  • LinkedIn

©2024 by Salesforce Mojo

bottom of page