Hi Ritu
SerializableCart inherits from ICart and IOrderGroup. So if you have an instance of IOrderGroup, you can get the CustomerId from it.
In which context do you need the CustomerId, while only getting the IOrderForm?
In Commerce 13, a new property is added for IOrderForm (ParentOrderGroup) which you can use to get the parent IOrderGroup, and then get the CustomerId. That'd be the nicest way to do it
Thanks for your responses Stefan and Quan!
However, I don't get IOrderGroup for a SerializedCart. I'm in the context of OrderFormCalculator, where I overrode the DefaultOrderFormCalculator to add custom logic to CalculateTaxTotal() method. This takes IOrderForm as parameter. IOrderForm (for SerializedCart) has an _parent on it, which is of type Internal.SerializableCart and not IOrderGroup. Plus, since its internal, I can't quite access it from IOrderForm. And since this calculator is called internally from Epi, when we call SaveCart, i can't control parameters either, or pass anything else here.
I tried overriding DefaultOrderGroupCalculator, so i can have the IOrderGroup as parameter and fetch CustomerId from it. However, for serializableCart, this never gets hit, even though i've confirmed it was initialized correctly.
What am i doing wrong here?
Unfortunately, the site went live a couple months ago and i don't really think upgrading to Commerce 13 is an option at this time. Is there any other way to achieve this in Commerce 12?
Regards
Ritu
As Stefan said, a SerializableCart is an IOrderGroup:
public class SerializableCart : ICart, IOrderGroup, IExtendedProperties, IDeepCloneable, IOrderGroupCalculatedAmount
If the DefaultOrderGroupCalculator doesn't get called when you like then you can call the it yourself before using any totals and move away from Episerver's default implementations, but the bottom line is that Quan is right - it will most likely be less work for you to actually do the upgrade to Commerce 13.
Unless you have built using legacy functions the move from 12 to 13 isn't such a big step at all:
https://world.episerver.com/documentation/upgrading/episerver-commerce/commerce-13/breaking-changes-commerce-13/
Thanks Erik!
Your workaround of manually calling the OrderGroupCalculatoe actually did the trick for me. It did hit my code logic. And I'm able to see tax calculations as and when expected.
I'm running into another issue w.r.t the final totals I see on the cart vs the final totals I see on the Purchase Order, but not sure if its related to this. I'll troubleshoot on my end and get back here if I need more insight.
Thanks for now!
Hi
I need to fetch the CustomerId from SerializedCart IOrderForm, but don't see it as a property on it and don't see a way to access the parent of this IOrderForm either. But it is a field on SerializableCart table in DB. Can someone please advice if this is feasible?
Also, noticed that if cart is a Serialized Cart, then there is no IOrderGroup to be fetched from it. Is that correct? I tried overriding the DefaultOrderGroupCalculator for a Serialized Cart, but since it takes IOrderGroup as parameter, it never got hit.
The documentation doesn't have much to go with here.
Please advice.
Regards
Ritu