Try our conversational search powered by Generative AI!

Trying to understand when CartPrepareWorkflow is needed


Hi, I'm unsure of when CartPrepareWorkflow is needed....

I am using IOrderRepository.  I get a cart, add an item to it, and accept the changes:

            var cart = _orderRepository.Load(customerId, Cart.DefaultName).First();

            // i need to run CartPrepareWorkflow here???

            var updatedCart = _orderRepository.Load(customerId, Cart.DefaultName).First();

Will "updatedCart" contain the true updated cart?  Or must I run CartPrepareWorkflow ?

Edited, Oct 24, 2016 22:38


CartPrepare only needs to be run when customers already reach checkout page. It will calculate the taxes.

For normal cases like the customer adds an item to cart, you can run just CartValidate workflow



Oct 24, 2016 23:42

Thank you Quan,

But specifically, in my code above -

- will "updatedCart" contain an up-to-date cart? 

(it was my belief that each time I retrieve a cart from IOrderRepository it would be up-to-date... but, am I wrong?  Do I actually have to run CartValidate workflow AFTER retrieving cart form IorderRepository to ensure that taxes, etc, are up-to-date?)

Oct 24, 2016 23:50


You should run the workflow before saving the cart, not after loading it. <= this might not be true. The cart should be validated after loading, to make sure that any updated items or prices will be reflected. I even find it better for performance. Will blog about it soon.

In your case, if you want taxes to be included, then you should run CartPrepare. If you only want to apply promotions, then CartValidate is enough.


Edited, Oct 25, 2016 7:16

Thanks again,

So if I don't run cartValidate before saving, the cart will potentially save incorrect / outdated data??

Nov 01, 2016 19:55

In a way, yes, the cart then might contain out-of-stock items, or no longer valid discounts, etc 

Nov 02, 2016 7:05

If I Delete a Payment and then Save the Payment, do I have to Validate & Save the cart too?

Nov 02, 2016 22:34

If the payment was a part of the OrderForm (it was in OrderForm.Payments) then yes, you should save the cart. Which workflow to run is a question - I don't really know - it depends a lot on your implementation - for example in some sites when you to choose to certain payments you have to pay more money. But to be safe, it would not hurt if you run the CartPrepare workflow to make sure everything is correct.

Nov 03, 2016 8:37

In order to understand the Cartworkflow, I highly recommend you to read the documentation thoroughly. EPi has very decent documentation for workflow activities, and once you understand what happened in each activity, you should be easily figuring out which one you need to apply for your solution. 


Calculates shopping cart totals, including discounts, and validates if a product is available. This activity flow is executed every time the cart view page is loaded.


Associates line items with shipments in the OrderForm object (allows split shipment), calculates shipment prices, tax totals, order total. Shipments require a custom shipping provider. The flow uses interfaces that your shipment and tax providers implement.

This activity flow is executed just prior to completing the order. Its calculations ensure that the cart includes all relevant discounts and ancillary costs, such as taxes and shipping charges.


Validates order total, process payment (again, requires custom payment provider). This flow is executed upon submission of the cart for processing.


Nov 04, 2016 1:14
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.