Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Add new item to shopping cart via API with same SKUID View modes: 
User avatar
Certified Developer 10
Certified Developer 10
neuman-ncompany - 7/29/2010 4:45:41 AM
   
Add new item to shopping cart via API with same SKUID
Hi,
I need to add new line to shopping Cart via API. We have custom fields in ecommerce.shoppingcartitem. When I add SKU and it is in Cart, it only adds quantity and overwrite custom fields, instead of add new line with new custom fields value. Is it possible to avoid this ?

Thanks, Přemek

User avatar
Kentico MVP
Kentico MVP
Andrew Thompson - Get Started - 8/4/2010 9:56:47 PM
   
RE:Add new item to shopping cart via API with same SKUID
Hi Přemek,

I had a similar problem. Kentico only checks if a line item is unique based on whether it has the same SKUID and the same product options as another line item, but if the cart item's custom data is different, it doesn't care and just increments the quantity anyway. We solved it by writing a custom method to replace AddShoppingCartItem(), in order to strictly add a single quantity line item to the cart regardless of existing skuids. This site does not use product options, so it's quite simple, but if your site does use product options you'll need to work with them too and it gets a bit more complicated.

Put something like this in your CMSCustom.cs file and see how it goes!
(Maybe add some exception handling and commenting of course...)


private static ShoppingCartItemInfo AddSingleShoppingCartItem(int skuid, ShoppingCartInfo cart)
{
ShoppingCartItemInfo info = new ShoppingCartItemInfo();
info.SKUID = skuid;
info.CartItemUnits = 1;
info.CartItemParentGUID = Guid.Empty;
info.ShoppingCartID = cart.ShoppingCartID;
info.SKUObj = SKUInfoProvider.GetSKUInfo(skuid);
cart.CartItems.Add(info);

cart.ShoppingCartContentTable = null;
cart.ShoppingCartTaxTable = null;
cart.ClearShoppingCartHashtables();
return info;
}


Cheers

Andrew Thompson
Get Started