Site structure
Version 2.x > Site structure > Access to shopping cart from ASHX handler View modes: 
User avatar
Member
Member
awalters-designkitchen - 8/20/2008 10:34:46 AM
   
Access to shopping cart from ASHX handler
Hello,

Could somebody please tell me how to do this? When i use CMS.Ecommerce.ShoppingCartInfo cart = CMSContext.CurrentShoppingCart; in a normal code-behind page, it works fine. When i use the same code in the ASHX handler, it returns null.

Thanks!!

User avatar
Kentico Developer
Kentico Developer
kentico_zbysekn - 8/20/2008 11:46:12 AM
   
RE:Access to shopping cart from ASHX handler
Hello,

Thank you for your message.
You can use these methods of class CMS.CMSEcommerce.ShoppingCartInfoProvider:
ShoppingCartInfo GetShoppingCartInfo( int shoppingCartId )
ShoppingCartInfo GetShoppingCartInfo( Guid shoppingCartGUID )

You will simply pass parameter to your Ajax script with value for example shoppingCartId and you can use GetShoppingCartInfo method to access its content.
You can find more in API reference (http://www.kentico.com/downloads/kenticocms_api.zip).

Please let me know if I can be of any further assistance.

Best Regards,
Zbysek Nemec

User avatar
Member
Member
awalters-designkitchen - 8/20/2008 1:52:18 PM
   
RE:Access to shopping cart from ASHX handler
Yes, i've tried this only to find that it doesn't seem to be the same cart as CMSContext.CurrentShoppingCart...despite using the GUID frmo CMSContext.CurrentShoppingCart. Any changes i make to a cart pulled down with GetShoppingCartInfo( Guid shoppingCartGUID ) using the CurrentShoppingCart GUID do not reflect in the CMSContext.CurrentShoppingCart. Even if i do something like ShoppingCartInfoProvider.SetShoppingCartInfo(cart); after making changes.

HOW CAN I ACCESS CMSCONTEXT.CURRENTSHOPPINGCART in an ASHX FILE (HANDLER)??? PLEASE HELP!!

THANKS!!!

User avatar
Kentico Developer
Kentico Developer
kentico_zbysekn - 8/21/2008 6:57:27 AM
   
RE:Access to shopping cart from ASHX handler
Hello,

You can access your shopping cart this way:
CMS.Ecommerce.ShoppingCartInfo cart = CMSContext.CurrentShoppingCart;

Then you will send its ID as parameter to your script.

Finally you need to create new guid and set its value and access your Shopping cart via it:
Guid strCartGUID = sendedGUID;
ShoppingCartInfo cart = ShoppingCartInfoProvider.GetShoppingCartInfo(strCartGUID);

Please let me know if I can be of any further assistance.

Best Regards,
Zbysek Nemec

User avatar
Member
Member
awalters-designkitchen - 8/21/2008 8:50:31 AM
   
RE:Access to shopping cart from ASHX handler
Ok, i've been working on this for over a day now and tried nearly everything i can find in the API and still seem to be missing something.

I was able to get access to the CMSContext.CurrentShoppingCart from the .ashx handler by including the SessionState namespace. However, the same issues persist. Changes i make to the cart from the Handler are not reflected in the CMSContext.CurrentShoppingCart on other pages.

Through debugging, i can tell that the CMSContext.CurrentShoppingCart has one less CartItem after i remove an SKU (which i've tried doing several different ways). I've tried ShoppingCartInfoProvider.SetShoppingCartItems(CMSContext.CurrentShoppingCart.ShoppingCartID, CMSContext.CurrentShoppingCart.CartItems); thinking it would force the DB updates, as well as resetting CMSContext.CurrentShoppingCart w/ CMSContext.CurrentShoppingCart = ShoppingCartInfoProvider.GetShoppingCartInfo(CMSContext.CurrentShoppingCart.ShoppingCartGUID); in an attempt to make sure CurrentShoppingCart reflects the changes, but nothing seems to take.

When i go back to the page w/ the ShoppingCart web part, all the items remain, even after refreshing.

What's more frustrating, is that if i try running the handler to remove another item, the handler shows that the previous item has been removed! So it seeeeeems like it's working, but there must be something i'm not doing to get these changes reflected in the Kentico shopping cart code.

Thanks in advance,

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 8/22/2008 3:58:15 AM
   
RE:Access to shopping cart from ASHX handler
Hello,

we have several discussions with our developers and we find a theoretic resolution.

You could create a global Hash table, which would be managed by the ASHX handler. There would be stored the information about the cart and an indicator whether the information is actual or not. The indicator would be set to false by the ASHX handler after changing of cart.
The ASPX page checks this table on its initialisation and looks up whether the information is actual or not. If the indicator is false, it throw up the actual cart and read its data from the database.

I hope this will be helpful for you.

Best regards,
Helena Grulichova