Trying to understand when CartPrepareWorkflow is needed

Vote:
 

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();
            cart.AddLineItem(lineItem);
            cart.AcceptChanges();

            // ...do 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 ?


#164419
Edited, Oct 24, 2016 22:38
Vote:
 

Hi,

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

Regards,

/Q

#164420
Oct 24, 2016 23:42
Vote:
 

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?)

#164421
Oct 24, 2016 23:50
Vote:
 

Hi,

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.

/Q

#165546
Edited, Oct 25, 2016 7:16
Vote:
 

Thanks again,

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

#171105
Nov 01, 2016 19:55
Vote:
 

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

#171144
Nov 02, 2016 7:05
Vote:
 

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

#171219
Nov 02, 2016 22:34
Vote:
 

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.

#171227
Nov 03, 2016 8:37
Vote:
 

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. 

CartValidateActivityFlow

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.

CartPrepareActivityFlow

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.

CartCheckoutActivityFlow

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

Ref: http://world.episerver.com/documentation/developer-guides/commerce/workflows-and-activities/

#171259
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.