Hello.
At first, we will support this in upcoming version 6.0, so there will be no need of customization then.
Currently, you would need to customize it to reach this behavior. You can develop a custom shopping cart step, according to link you already know, or modify existing step, add this TextBox into given template and ensure logic in code-behind. For example, you can add it into existing
\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCartContent.ascx step.
Currently, you can see „Units“ TextBox in “Add some products to the shopping cart“ step, allowing you to add number of items and update shopping cart. You can do something similar, just for another TextBox, called e.g. „Custom text. “
It will behave as „Units“ TextBox and it will save value, inserted within, into a
OrderItemCustomData of given
OrderItemInfo object.
This can be ensured in
ShoppingCartContent.ascx.cs, in
btnUpdate method, and you can take an inspiration from following code (used for other TextBox – Units):
// Get number of units
int itemUnits = ValidationHelper.GetInteger(((TextBox)(row.Cells[6].Controls[1])).Text.Trim(), 0);
if ((itemUnits > 0) && (cartItem.CartItemUnits != itemUnits))
{
// Update units of the parent product
cartItem.CartItemUnits = itemUnits;
if (!this.ShoppingCartControl.IsInternalOrder)
{
ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(cartItem);
}
}
You will have
string variable, instead of
integer, and you will use „GetString“ method instead of „GetInteger, “ like
string sCustomText = ValidationHelper.GetString(((TextBox)(row.Cells[6].Controls[1])).Text.Trim(), 0);
Also, you need to use proper cell number (not 6), so you will need to debug it to see what is the correct number of the given cell.
Also, you need to update given
OrderItemCustomData instead of
cartItem.CartItemUnits.
Second thing is how to show what has been added. You can put it into invoice via macro, or you can add additional column into given template. This can be done on ShoppingCartContent.ascx directly, where template is defined.
You can add a new template like:
<asp:TemplateField HeaderStyle-Wrap="false">
<ItemStyle HorizontalAlign="Right" />
<HeaderStyle HorizontalAlign="Right" Width="80" />
<ItemTemplate>
<asp:Label ID="lblCustomText" runat="server" Text='<%# MyCustomData()%>' EnableViewState="false" />
</ItemTemplate>
</asp:TemplateField>
Where
MyCustomData is method, defined in your code-behind, which will return proper value from
OrderItemCustomData. You can define this method in code-behind like:
protected static string MyCustomData(object parameter)
{
// return ... ;
}
You can take an inspiration from
IsProductOption method.
Please note this customization is up to you, as it is not currently supported in standard solution. Other option is to wait for version 6.0, like I mentioned. Thank you.
Best Regards,
Radek Macalik