How can I extend a shopping cart’s content table?

HelenaG Grulichova asked on May 3, 2012 08:53

How can I extend a shopping cart’s content table?

Correct Answer

HelenaG Grulichova answered on May 3, 2012 08:53

Kentico CMS provides a new customization model that allows you to modify each available provider very easily. For example, if you need to extend the shopping cart's content table and include a custom field that you have defined in the Site manager -> Development -> System tables -> edit COM_SKU table, all you need to do is to override the CreateContentTableInternal and CreateContentRowInternal methods of the ShoppingCartInfoProvider class.

First, you need to call their base versions and then modify the returned DataTable (in the CreateContentTableInternal ) and DataRow (in the CreateContentRowInternal) as is demonstrated here:

protected override DataTable CreateContentTableInternal()
{
DataTable dt = base.CreateContentTableInternal();
dt.Columns.Add(new DataColumn("<column name>", typeof(<type>)));
return dt;
}

protected override DataRow CreateContentRowInternal(ShoppingCartItemInfo item, DataTable table)
{
DataRow row = base.CreateContentRowInternal(item, table);
row["<column name>"] = item.SKUObj.GetValue("<SKU field name>");
return row;
}


Then you can, for example, reference the custom field in the transformation, applied to the content table, by doing this: 

{% ContentTable.ApplyTransform(String transformationName, String contentBeforeTransformationName, String contentAfterTransformationName) #% }


Links to other resources: E-commerce 6: New customization model, Transformations in macro expressions
 
-ml-
0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.