How to generate a picking|warehouse|product list besides an invoice

   —   
Currently on the configuration tab of the ecommerce section, you can generate an invoice, however, sometimes you could need also to ‘add’ a picking/packing list, so as an example be able to duplicate the invoice but remove any pricing information so it could be used internally for warehouse picking and packing.
1. Firstly you may need to add a custom field to 'COM_Order' table in: 'CMS Site Manager -> Development -> System tables'. E.g.: OrderPackageList.

2. You need to create method which will make up the Package list table. You can find the data table in 'this.ShoppingCartInfoObj.ShoppingCartContentTable' object. It will look like:

string GetPackageList(DataTable table)
{
//return HTML code for your package list
//available data columns in datatable are: "SKUID", "SKUName", "SKUUnits" and the others: "SKUPrice", "UnitDiscount", "Tax", "SubTotal", "SubTotalDefaultCurrency", "ErrorMessage", "CartItemID", "CartItemGuid", "CartItemParentGuid"
}

Please find example code of GetProductList method below (this method is already used within Kentico to retrieve Product list).

3. Please use and call this method in:
~CMSEcommerce\ShoppingCart\ShoppingCartPreview.ascx - used when saving an order on Live site and
~CMSEcommerce\ShoppingCart\ShoppingCartContent.ascx - used when saving an order in CMS Desk

Following code block must be pasted to 'ProcessStep' method before the order information object (oi) is saved to database (somewhere around the line 170 in ELSE condition):

string list = GetPackageList(this.ShoppingCartInfoObj.ShoppingCartContentTable);
oi.SetValue("OrderPackageList", list);


4. Now it's your order saved in the 'OrderPackageList' field as a HTML code. You can display it on some blank page and print it as you wish (be carefull about security policy).

5. Or, instead of step 4, you can display your Package list on a new tab within Order details in E-commerce module. It's a little bit tricky, but how to achieve this is described below.

- Create new form control (e.g. MyControl) which will contain button and label. You will show the Package list HTML table by pressing the button. This control needs to be placed in '/CMSFormControls' folder. Please see: devnet.kentico.com/docs/devguide/developing_form_controls.htm

- Now please register it within other Form Controls in: 'CMS Site Manager -> Development -> Form Controls -> New form control'. Check 'Use control for long text:' and 'Show control in system tables:'.

- Go to system tables and edit 'COM_Order' table. Select your 'OrderPackageList' field and choose 'Long text' as an Attibute type and 'MyControl' as a Field type.

- This is it. At the end you should be able to display Product list of the appropriate Order in the 'Custom fields' tab.


Example GetProductList method (replaces ##PRODUCTLIST## macro):

public static string GetProductList(DataTable dt, CurrencyInfo currency, bool renderDiscount)
{
if ((dt != null) && (dt.Rows.Count > 0))
{
StringBuilder sb = new StringBuilder();

// Header
sb.Append(" <table width=\"100%\" style=\"text-align: right\" cellspacing=\"0\" cellpadding=\"2\" class=\"productsList\">");
sb.Append(" <thead><tr><th colspan=\"6\" class=\"headerBorder\">&nbsp;</tr><tr>");
sb.Append(" <th style=\"text-align: left;padding-left:2px\">");
sb.Append(ResHelper.GetString("InvoiceTemplate.SKUName"));
sb.Append(" </th>");
sb.Append(" <th>");
sb.Append(ResHelper.GetString("InvoiceTemplate.SKUUnits"));
sb.Append(" </th>");
sb.Append(" <th>");
sb.Append(ResHelper.GetString("InvoiceTemplate.SKUPrice"));
sb.Append(" </th>");
if (renderDiscount)
{
sb.Append(" <th>");
sb.Append(ResHelper.GetString("InvoiceTemplate.UnitDiscount"));
sb.Append(" </th>");
}
sb.Append(" <th>");
sb.Append(ResHelper.GetString("InvoiceTemplate.Tax"));
sb.Append(" </th>");
sb.Append(" <th>");
sb.Append(ResHelper.GetString("InvoiceTemplate.Subtotal"));
sb.Append(" </th>");
sb.Append("</tr></thead><tbody>");

double value = 0.0;

// Add the items
foreach (DataRow dr in dt.Rows)
{
string name
ResHelper.LocalizeString(Convert.ToString(DataHelper.GetDataRowValue(dr, "SKUName")));

// If it is a product option
if (ValidationHelper.GetGuid(DataHelper.GetDataRowValue(dr, "CartItemParentGuid"), Guid.Empty) != Guid.Empty)
{
name = "&nbsp;&nbsp;- " + name;
}

sb.Append("<tr>");
sb.Append(" <td style=\"text-align: left\">");
sb.Append(name);
sb.Append(" </td>");
sb.Append(" <td>");
sb.Append(Convert.ToString(DataHelper.GetDataRowValue(dr, "SKUUnits")));
sb.Append(" </td>");
sb.Append(" <td>");
value = ValidationHelper.GetDouble(DataHelper.GetDataRowValue(dr, "SKUPrice"), 0);
sb.Append(Ecommerce.CurrencyInfoProvider.GetFormatedValue(value, currency));
sb.Append(" </td>");
if (renderDiscount)
{
sb.Append(" <td>");
value = ValidationHelper.GetDouble(DataHelper.GetDataRowValue(dr, "UnitDiscount"), 0);
sb.Append(Ecommerce.CurrencyInfoProvider.GetFormatedValue(value, currency));
sb.Append(" </td>");
}
sb.Append(" <td>");
value = ValidationHelper.GetDouble(DataHelper.GetDataRowValue(dr, "Tax"), 0);
sb.Append(Ecommerce.CurrencyInfoProvider.GetFormatedValue(value, currency));
sb.Append(" </td>");
sb.Append(" <td>");
value = ValidationHelper.GetDouble(DataHelper.GetDataRowValue(dr, "Subtotal"), 0);
sb.Append(Ecommerce.CurrencyInfoProvider.GetFormatedValue(value, currency));
sb.Append(" </td>");
sb.Append("</tr>");
}
sb.Append(" </tbody><tfoot>");
sb.Append(" <tr>");
sb.Append(" <td colspan=\"6\" class=\"bottomBorder\">&nbsp;");
sb.Append(" </td>");
sb.Append(" </tr>");
sb.Append(" </tfoot>");
sb.Append("</table> \n");

return sb.ToString();
}
else
{
return null;
}
}


See also:


Applies to: Kentico CMS 3.1a
Share this article on   LinkedIn

Juraj Ondrus

Hi, I am the Technical support leader at Kentico. I'm here to help you use Kentico and get as much as possible out of it.