API Questions on Kentico API.
Version 5.x > API > How to read shopping cart items from custom step? View modes: 
User avatar
Member
Member
Real Salmon - 11/16/2011 3:45:52 PM
   
How to read shopping cart items from custom step?
Hello -

I have developed several custom steps for an enhanced checkout process (Kentico 5.5r2). On one of these steps I need to iterate through the shopping cart items in order to get information about each item that has been added. I am having trouble figuring out how to do this.

In particular, I am interested in the quantity of a particular item that has been added, but I would need to check other properties as well.


e.g. (psuedo code!!)


foreach (CartItem item in ShoppingCart.Items)
{
if (item.quantity > 10)
{
// do something . . .
}

if (item.veryInterestingProperty == "lolz")
{
// do some other thing . . .
}
}


Thanks for any help!

User avatar
Member
Member
kentico_michal - 11/17/2011 1:07:37 PM
   
RE:How to read shopping cart items from custom step?
Hello,

Please take a look at following code that shows how you can loop through all items that has been added to shopping cart and how you can access default properties as well as custom properties:

foreach (ShoppingCartItemInfo item in ShoppingCartInfoObj.CartItems)
{
int quantity = item.CartItemUnits;
string veryInterestingProperty = ValidationHelper.GetString(item.GetValue("veryInterestingProperty"), String.Empty);
}


I hope this will help you.

Best regards,
Michal Legen

User avatar
Member
Member
Real Salmon - 11/17/2011 3:46:55 PM
   
RE:How to read shopping cart items from custom step?
As usual, Kentico support never leaves me wanting!

That is exactly what I needed, Michal. Thanks very much for the help!