Serialize Icart type conversion

Vote:
 

Hi Team,

We are using the legacy cart system and planning to move the serializable cart.

In some places of code, we converted the "ICart" to "Cart" type.

Problem: After we enabled the serialize cart then the conversion is not working and returns null.

Question: Once we move to a serializable cart then only we need to use Icart.Is it right? If not, how to convert serializable Icart to Cart?

        private readonly IOrderGroupFactory _orderFactory;
        private readonly IPromotionService _promotionService;
        private readonly Cart _castCart;

        public ShoppingCartWrapper(ICart shoppingCart)
        {
..
           _castCart = ShoppingCart as Cart;
        }

#260347
Aug 09, 2021 14:42
Vote:
 

Hi Karyan

You should always use ICart in your code (casting to concrete classes are rarely needed). Then migrating to Serialized Cart will work.

Also beware that while MetaFields need to be registered for Cart (the legacy one) and PurchaseOrder, you don't need to do this for Serialized Cart. It will just (attempt to) serialize the properties you add to it.

#260391
Aug 10, 2021 5:47
Karyan - Aug 16, 2021 7:14
Thanks Stefan.
Vote:
 

Once you moved to Serializable cart, you will not able to cast ICart to Cart (Cart is not compatible with SerializableCart). Stefan is right btw - you should be using ICart always. Why do you need Cart?

#260404
Aug 10, 2021 12:57
Karyan - Aug 16, 2021 7:13
Some cart casting codes are used by teammates.
Thanks Quan for the answer.
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.