Update May 2024: Before you implement the below, make sure that the corresponding option is activated in your WebStore (Field API Name: OptionsCartToOrderAutoCustomFieldMapping – you can update this in Developer Console, oddly enough the option is not found in the UI). Thanks to Talita from SF Support!
SELECT Id, Name, OptionsCartToOrderAutoCustomFieldMapping FROM WebStore
As usual, I’m not sure how to feel about Salesforce as a service provider when getting stuck somewhere in the process of delivering customizations. This time it was a mix of really bad documentation, and really good Support engineers. But bottom line – we got it resolved, once again!
You might remember the prequel where quantity discounts were established in Commerce Cloud with help of Custom Metadata, which did not only leave us with a FreeItem__c field on the CartItem, but also with a confused ERP team who receives order data from Salesforce, and now (understandably) wonders where all the free items come from.
So we’ll need to create the same FreeItem__c field on OrderItem first, which then gets picked up by hopefully then less confused ERP engineers.
- Free Item (FreeItem__c) – Checkbox – Indicates whether the underlying Cart Item was a free add-on
At this point, following the official documentation, where it says: “To be mapped successfully, a custom field must exist in the Cart, Order, and OrderSummary objects. It can also optionally exist in the OrderAdjustmentGroup, OrderDeliveryGroup, OrderItem, OrderItemAdjustmentLineItem, and OrderItemTaxLineItem objects.” – will lead to no mapping and a very frustrated developer.
In fact, the same FreeItem__c field needs to be created – needless to say in the same type (checkbox) – not only on CartItem and OrderItem, but also on Cart, Order, OrderSummary (as documented) and – that’s the hidden catch – on OrderProductSummary, so on a total of six objects – successfully tested! The latter four objects might sound (and not only sound) quite counter-intuitive – what’s the point behind marking an entire order as free item – but the ways of the Force are sometimes inscrutable. Proper documentation would mitigate.