API
Version 7.x > API > Adding new products using a generic handler View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
lucas-inorbital - 12/17/2013 9:03:24 AM
   
Adding new products using a generic handler
I'm trying to add a new product to the shopping cart through a generic handler (.ashx). The item appears in the cart if i add it through an onclick event on the asp.net button, but item doesn't show up when i add it through the generic handler.

Both cart (through aspx and ashx) have the same ShoppingCartID and GUID, but the items that are stored in the ShoppingCartObject is different. Any help would be greatly appreciated.


var skuId = QueryHelper.GetInteger("id", -1);

if (skuId <= 0)
return;

var product = SKUInfoProvider.GetSKUInfo(skuId);

if (product == null)
return;

// Get current shopping cart
var cart = ECommerceContext.CurrentShoppingCart;

// Ensure cart in database
ShoppingCartInfoProvider.SetShoppingCartInfo(cart);

// Add item to cart object
var param = new ShoppingCartItemParameters(product.SKUID, 1);
ShoppingCartItemInfo cartItem = cart.SetShoppingCartItem(param);

// Save item to database
ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);

User avatar
Certified Developer v7
Certified  Developer v7
lucas-inorbital - 12/17/2013 10:24:27 AM
   
RE:Adding new products using a generic handler
Seems like EcommerceContext.CurrentShoppingCart isn't updated at all.

If i do
ShoppingCartInfoProvider.GetShoppingCartInfo(ECommerceContext.CurrentShoppingCart.ShoppingCartGUID)


I would get the updated items in the shopping cart. Is there a way to force EcommerceContext.CurrentShoppingCart to update?

User avatar
Certified Developer v7
Certified  Developer v7
lucas-inorbital - 12/18/2013 2:49:11 PM
   
RE:Adding new products using a generic handler
Anyone?

User avatar
Certified Developer v7
Certified  Developer v7
lucas-inorbital - 12/19/2013 8:51:50 AM
   
RE:Adding new products using a generic handler
Just got an answer from Kentico team, for anyone who encounters this problem in the future.

Implementing IReadOnlySessionState should resolve that:
using System.Web.SessionState;

public class Handler : IHttpHandler, IReadOnlySessionState
{