API
Version 7.x > API > Difference Between ContentTable and CartItems View modes: 
User avatar
Member
Member
bryanallott - 3/18/2013 10:17:50 AM
   
Difference Between ContentTable and CartItems
I have noted this thread http://devnet.kentico.com/Forums.aspx?forumid=68&threadid=34456 which talks about using CartItems instead of the ContentTable for the ShoppingCart object...

Is it safe to do so in the context of having custom providers (in my case, for ShoppingCart, Shipping and Discount)?

And then secondly, what is the difference between the two (CartItems and ContentTable) since, for example:
If i bind a repeater to the ShoppingCart.ContentTable, I get a different value for the "Units" field on a single cart item than what is set in code or in the database. It seems to be cached somwhere?

*Background: i have a cart page where I update the quantity on a postback and in the database or if I query on CartItems, I get, for example, the expected value of 2. I am setting the item:
ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);

where cartItem.CartItemUnits = 2. The databasse reflects this update correctly, but the ContenTable still sees Units as 1? Do I need to refresh the ContentTable?

User avatar
Member
Member
bryanallott - 3/20/2013 3:08:11 AM
   
RE:Difference Between ContentTable and CartItems
fyi
ShoppingCart.RemoveShoppingCartItem(cartItemGuid);

seems to invalidate the internal table and redo the calculations while
ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);
doesn't.

An explicit call to:
ShoppingCart.InvalidateCalculations();

after SetShoppingCartItemInfo synchronises the ContentTable.

The confusing part is that the built-in shoppingcartcontent page doesn't do an explicit invalidate() but is bound to a grid, not a repeater...

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/3/2013 8:21:08 AM
   
RE:Difference Between ContentTable and CartItems
Hi,

Simply said, the ContentTable is the calculated result of the CartItems with respect to discounts, taxes and other stuff. It is cached, or in other words, when it's first used and not yet cached, it is calculated and cached, and any later access then uses the cached data, until the calculation is not invalidated.

Your observations are right, if you work in context of the ShoppingCart, the method invokes ContentTable invalidation, however updating the ShoppingCartItemInfo using the provider itself requires additional separate call of the calculations invalidation. That's the current design.

I've asked our developer to comment on the mentioned "confusing part", so I'll add an update soon.

Should you need any additional details in the meantime, please feel free to ask.

Regards,
Zdenek

User avatar
Member
Member
bryanallott - 4/3/2013 9:10:22 AM
   
RE:Difference Between ContentTable and CartItems
Thanks, Zdenek. That makes sense. I'll keep an eye open for the update then. Much obliged!

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/4/2013 7:05:33 AM
   
RE:Difference Between ContentTable and CartItems
Fine,
So to continue with explaining the difference in ShoppingCartContent:
In this control the updates to the items work (invoke recalculation), because when you update, add or remove any item, it calls something like either:
ShoppingCart.RemoveShoppingCartItem(cartItemGuid);
or
ShoppingCart.SetShoppingCartItem(cartItemParams);
or
ShoppingCartInfoProvider.EmptyShoppingCart(ShoppingCart);

which all are methods, that internally call invalidation of the ContentTable.

With using directly the ShoppingCartItemInfoProvider methods, you use API of the lower level than you need.

Hope this makes sense.
Should you need any additional details, please feel free to ask.

Regards,
Zdenek