Access ShoppingCart in custom IShoppingCartCalculator

Andy Bochmann asked on May 23, 2019 00:28


Is there a way to access the ShoppingCartInfo object inside a custom IShoppingCartCalculator?

I tried using:

var shoppingService = Service.Resolve<IShoppingService>();
var cart = shoppingService.GetCurrentShoppingCart();

which works fine for the MVC site. However, when creating orders though the Kentico backend, I don't get the correct ShoppingCartInfo object back.

I do not see any option to access the shopping carts using the data inside the CalculatorData object. I need to access some fields from the shopping cart, which are not available in the CalculatorData object.

Thanks, Andy

Recent Answers

Andy Bochmann answered on May 23, 2019 00:41

I figured out, that I can use the ShoppingCartCustomData field, which values get passed over to the CalculatorData object.

However, I'm still interested if there's another way, so that I don't have to use the custom data fields, if my ShoppingCartInfo object already contains strongly typed fields.

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on May 23, 2019 12:39

Hi Andy,

Am I correct that you are creating orders directly in Kentico admin area and this info is used for calculation then?

I think you can try this one:

var cart = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(calculationData.Request.OrderId);

But I'm not sure if Kentico creates a shopping cart for directly placed orders in admin, have never tested it myself. If the line of code returns null for me that would be an indicator that Kentico actually doesn't create shopping card for manually created orders, but you can check in the database to be sure.

0 votesVote for this answer Mark as a Correct answer

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