API Questions on Kentico API.
Version 5.x > API > API AddShoppingCartItem v5 not using v6 View modes: 
User avatar
Guest
it.thienthan - 3/22/2012 11:24:27 PM
   
API AddShoppingCartItem v5 not using v6
My function using best on version 3,4,5 but don't using version 6, can you help me.

public static bool AddToShoppingCart(int skuId, int quantity)
{
try
{
// Get current shopping cart
ShoppingCartInfo cart = ECommerceContext.CurrentShoppingCart;
if (cart == null)
{
// If current shopping cart hasn't been created yet -> create new empty one
cart = ShoppingCartInfoProvider.CreateShoppingCartInfo(CMSContext.CurrentSite.SiteID);
// Associate new shopping cart with the current session
ECommerceContext.CurrentShoppingCart = cart;
}
// Ensure shopping cart is saved to DB
if (cart.ShoppingCartID == 0)
{
ShoppingCartInfoProvider.SetShoppingCartInfo(cart);
}
// Add item to the shopping cart
ShoppingCartItemInfo product = cart.AddShoppingCartItem(skuId, quantity, null);
// Update shopping cart item in database
ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(product);
// Update product options in database
foreach (ShoppingCartItemInfo option in product.ProductOptions)
{
ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(option);
}

return true;
}
catch { }
return false;
}

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 3/28/2012 9:37:58 AM
   
RE:API AddShoppingCartItem v5 not using v6
Hi,

How exactly does it "not work"?

Mostly, the AddShoppingCartItem is no longer available, the method
SetShoppingCartItem is used instead.

It also accepts ShoppingCartItemParameters, which basically wrap the skuId, quantity and options...

I would recommend to check the new code in

~\CMSModules\Ecommerce\Controls\ProductOptions\ShoppingCartItemSelector.ascx.cs
method private void AddProductToShoppingCart()

Hope it will help.

Regards,
Zdenek

User avatar
Guest
it.thienthan - 3/28/2012 9:04:14 PM
   
RE:API AddShoppingCartItem v5 not using v6
hji thank men so much, that's good idea.

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 3/28/2012 11:32:15 PM
   
RE:API AddShoppingCartItem v5 not using v6
Hi,

Sure, you're welcome...
Should you have any additional questions (not only) about usage of the Ecommerce API in version 6, please let us know.

Just to summarize some important info:
New customization model in v 6.0 has been introduced and described at
devnet.kentico.com/Blogs/Petr-Vozak/October-2011/E-commerce-6--New-customization-model

List of the API changes can be found in the blog post
devnet.kentico.com/Blogs/Martin-Hejtmanek/November-2011/Changes-in-the-API-from-version-Kentico-CMS-5-5-R2

Regards,
Zdenek