How to access shopping cart in custom OrderInfoProvider

Andy Bochmann asked on May 18, 2019 05:37

Hello,

Is there a way to access the shopping cart inside a custom OrderInfoProvider class? I've followed the documentation and wrote a custom SetOrderInfoInternal method to set the values of additonal custom fields on an order. The values for those fields are saved as custom fields on the ShoppingCartInfo object.

I'm basically tring to copy custom values from the cart to an order, during order creation.

Thanks, Andy

Recent Answers


Roman Hutnyk answered on May 18, 2019 11:35

I've used var cart = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(order.OrderID); in earlier versions of Kentico, but I believe current API should be the same a similar.

1 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on May 19, 2019 03:26

You can save your custom data into ShoppingCartItemInfo.CartItemCustomData which will become automatically OrderItemInfo.OrderItemCustomData when shopping cart destroyed and order is created.

ShoppingCartItemInfo.CartItemCustomData.SetValue("Name", Value);
ShoppingCartItemInfo.Update()
1 votesVote for this answer Mark as a Correct answer

Andy Bochmann answered on May 20, 2019 23:36 (last edited on May 20, 2019 23:36)

Thank you. Roman, you're right, that doesn't work anymore. It will always return null.

I found another solution, which seems to work fine so far: var cart = ShoppingCartInfoProvider.GetShoppingCartInfo(orderObj.OrderCompletedByUserID, "SITENAME");

I also thought about using the CustomData property instead, however, I like having the fields defined on the class and the option to display those fields in the Kentico backend user interface.

Now I just have to find out how to set those fields when creating an Order directly in Kentico instead of the MVC application.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.