Try our conversational search powered by Generative AI!

Is there a way to fetch CustomerId or parent from SerializedCart's OrderForm?

Vote:
 

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

#216257
Edited, Jan 31, 2020 1:57
Vote:
 

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?

#216258
Jan 31, 2020 6:54
Vote:
 

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

#216259
Jan 31, 2020 7:03
Vote:
 

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

#216275
Jan 31, 2020 14:02
Vote:
 

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/

#216279
Jan 31, 2020 16:07
Vote:
 

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!

#216284
Jan 31, 2020 20:12
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.