API
Version 7.x > API > how to drill into Item in shoppingCart View modes: 
User avatar
Member
Member
mac_sh user - 1/23/2013 5:57:29 PM
   
how to drill into Item in shoppingCart
Hi. I have a requirement to determine the 'type' of product being purchased.
What I have done:
Create new DocumentType as a ProductType/Membership. (DT)
Name, Description, SubscriptionType (annual,monthly,weekly)

I need the subscription type for my recurring billing provider.

Created 3 new products in my CMSDesk > Ecommerce > Products.
Each has a different SubscriptionType.

Add 3 items to shopping cart.

On Checkout, I need to be able to split these three items to the appropriate recurring billing profile with my provider. Weekly, Monthly, Annually .


public override void ButtonNextClickAction()
{
//need to determine if we are splitting this order to two different PayPalProfileIDs
DataTable items = ShoppingCart.ContentTable; //the shopping cart items

foreach (DataRow row in items.Rows)
{
SKUInfo item = new SKUInfo(row); //not very useful I am thinking

//this is where things go completely haywire..
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
CMS.DocumentEngine.TreeNode node = tree.SelectSingleNode(321);
if (node != null)
{
string SubType = node.GetValue("SubscriptionType");
}



}

}

Any assistance would be appreciated as this doesn't seem to be covered in the api documents.
mac


User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 1/31/2013 4:58:18 PM
   
RE:how to drill into Item in shoppingCart
Hi Mac.

If I'm getting your setup correctly, the code will be quite easy.
First, if you have the ShoppingCart, you don't have to instantiate SKUInfo objects from the DataRow(s) of the ContentTable, you can simply loop through its CartItems property:
List<ShoppingCartItemInfo> CartItems

Each ShoppingCartItemInfo has the SKUID property and that is used as a foreign key in the TreeNode object - the NodeSKUID.

Therefore, you need to query the tree using one of the overloads of the SelectNodes method (VisualStudio will offer that, alternatively there's API reference or examples in the DevGuide) that accepts where parameter (the where condition), which will be constructed as:
where = "NodeSKUID = " + shoppingCartItem.SKUID;

You can also use the columns parameter to narrow the query to the required ones, maybe just the SubscriptionType column name and the NodeSKUID.
Further note - please obtain the TreeProvider once, not repeatedly in a oop.

Anyway, you should receive a DataSet with a single record (if you don't have more documents mapped with the same product - SKU), so it will be easy to read the SubscriptionType either directly or after instantiating the TreeNode (document) object..

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

Regards,
Zdenek.