API Questions on Kentico API.
Version 6.x > API > API AddShoppingCartItem v5 not using v6 View modes: 
User avatar
Member
Member
it.thienthan - 3/23/2012 11:27:59 PM
   
API AddShoppingCartItem v5 not using v6
Hello everybody !

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 Developer
Kentico Developer
kentico_ivanat - 3/24/2012 8:54:51 AM
   
RE:API AddShoppingCartItem v5 not using v6
Hi,

how to add a product to the shopping cart in version 6.0 and older is described in this knowledge base article:
How to add products to the shopping cart using API

For older version please take a look at the bottom of the page.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
andy.smith-swgfl.org - 5/10/2012 7:18:20 AM
   
RE:API AddShoppingCartItem v5 not using v6
Hello Ivana,

I am experiencing the same problem. I have a Kentico v5.5 installation that I have tested the code at the link you provided, and it works.
I have applied the same code to a Kentico v6.0 installation and it fails. The method ShoppingCartInfo.AddShoppingCartItem cannot be resolved.

I have checked the libraries referenced are the same (in name) therefore I was wondering if there had been any amendments between dll's for .NET v3.5 and v4.0?

Kind regards,

Andy.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 5/10/2012 8:13:35 AM
   
RE:API AddShoppingCartItem v5 not using v6
Hi,

you can find inspiration for example in the code of method btnAddProduct_Click, in the file:
C:\<project>\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCartContent.ascx.cs


int skuId = 7;
int quant = 1; //quantity
int intOptions = 0;

SKUInfo skuInfo = SKUInfoProvider.GetSKUInfo(skuId);
if (skuInfo != null)
{
ShoppingCartItemParameters cartItemParams = new ShoppingCartItemParameters(skuId, quant, intOptions);

// Add product to the shopping cart
this.ShoppingCartInfoObj.SetShoppingCartItem(cartItemParams);



Best regards,
Ivana Tomanickova