Hi,
The mappings are defined in the folder
~\CMSModules\Ecommerce\Development\DocumentTypes\ in
DocumentType_Edit_Ecommerce.aspx and (the mappings themselves) in
DocumentType_Edit_Ecommerce.aspx.cs.
We've prepared modified files with mapping of any DocumentType field to SKUNumber (Product Number), please find the code sources below and replace the old code in the same location in your webproject folder. I'd recommend making backup of the original files. Attached files were modified from Kentico CMS 4.0 version files.
DocumentType_Edit_Ecommerce.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DocumentType_Edit_Ecommerce.aspx.cs"
Inherits="CMSModules_Ecommerce_Development_DocumentTypes_DocumentType_Edit_Ecommerce"
Theme="Default" MasterPageFile="~/CMSMasterPages/UI/TabLevel1.master" Title="Document Type Edit - Ecommerce" %>
<asp:Content ID="cntBody" runat="server" ContentPlaceHolderID="plcContent">
<asp:Label runat="server" ID="lblInfo" CssClass="InfoLabel" EnableViewState="false"
Visible="false" />
<asp:Label runat="server" ID="lblError" CssClass="ErrorLabel" EnableViewState="false"
Visible="false" />
<asp:Label runat="server" ID="lblTitle" CssClass="InfoLabel" EnableViewState="false" />
<table>
<tr>
<td class="FieldLabel">
<asp:Label runat="server" ID="lblName" EnableViewState="false" /></td>
<td>
<asp:DropDownList ID="drpName" runat="server" CssClass="DropDownField" /></td>
</tr>
<tr>
<td class="FieldLabel">
<asp:Label runat="server" ID="lblImage" EnableViewState="false" /></td>
<td>
<asp:DropDownList ID="drpImage" runat="server" CssClass="DropDownField" /></td>
</tr>
<tr>
<td class="FieldLabel">
<asp:Label runat="server" ID="lblWeight" EnableViewState="false" /></td>
<td>
<asp:DropDownList ID="drpWeight" runat="server" CssClass="DropDownField" /></td>
</tr>
<tr>
<td class="FieldLabel">
<asp:Label runat="server" ID="lblHeight" EnableViewState="false" /></td>
<td>
<asp:DropDownList ID="drpHeight" runat="server" CssClass="DropDownField" /></td>
</tr>
<tr>
<td class="FieldLabel">
<asp:Label runat="server" ID="lblWidth" EnableViewState="false" /></td>
<td>
<asp:DropDownList ID="drpWidth" runat="server" CssClass="DropDownField" /></td>
</tr>
<tr>
<td class="FieldLabel">
<asp:Label runat="server" ID="lblDepth" EnableViewState="false" /></td>
<td>
<asp:DropDownList ID="drpDepth" runat="server" CssClass="DropDownField" /></td>
</tr>
<tr>
<td class="FieldLabel">
<asp:Label runat="server" ID="lblPrice" EnableViewState="false" /></td>
<td>
<asp:DropDownList ID="drpPrice" runat="server" CssClass="DropDownField" /></td>
</tr>
<tr>
<td class="FieldLabel">
<asp:Label runat="server" ID="lblDescription" EnableViewState="false" /></td>
<td>
<asp:DropDownList ID="drpDescription" runat="server" CssClass="DropDownField" /></td>
</tr>
<tr>
<td class="FieldLabel">
<asp:Label runat="server" ID="lblNumber" EnableViewState="false" /></td>
<td>
<asp:DropDownList ID="drpNumber" runat="server" CssClass="DropDownField" /></td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="FieldLabel" colspan="2">
<asp:CheckBox ID="chkGenerateSKU" runat="server" CssClass="CheckBoxMovedLeft" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="FieldLabel">
<asp:Label runat="server" ID="lblDepartments" EnableViewState="false" /></td>
<td>
<asp:DropDownList ID="drpDepartments" runat="server" CssClass="DropDownField" DataTextField="DepartmentDisplayName"
DataValueField="DepartmentID">
</asp:DropDownList></td>
</tr>
<tr>
<td>
</td>
<td>
<br />
<asp:Button runat="server" ID="btnOK" OnClick="btnOK_Click" CssClass="ContentButton"
EnableViewState="false" /></td>
</tr>
</table>
<asp:Literal ID="ltlScrpt" runat="server" EnableViewState="false" />
</asp:Content>
DocumentType_Edit_Ecommerce.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.GlobalHelper;
using CMS.FormEngine;
using CMS.SettingsProvider;
using CMS.Ecommerce;
using CMS.SiteProvider;
public partial class CMSModules_Ecommerce_Development_DocumentTypes_DocumentType_Edit_Ecommerce : CMSEcommercePage
{
int docTypeId = 0;
DataClassInfo dci = null;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.RequireSite = false;
}
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text = ResHelper.GetString("DocType.Ecommerce.lblName");
lblWeight.Text = ResHelper.GetString("DocType.Ecommerce.lblWeight");
lblHeight.Text = ResHelper.GetString("DocType.Ecommerce.lblHeight");
lblWidth.Text = ResHelper.GetString("DocType.Ecommerce.lblWidth");
lblDepth.Text = ResHelper.GetString("DocType.Ecommerce.lblDepth");
lblImage.Text = ResHelper.GetString("DocType.Ecommerce.lblImage");
lblPrice.Text = ResHelper.GetString("DocType.Ecommerce.lblPrice");
lblDescription.Text = ResHelper.GetString("DocType.Ecommerce.lblDescription");
btnOK.Text = ResHelper.GetString("General.OK");
lblTitle.Text = ResHelper.GetString("DocType.Ecommerce.lblTitle");
chkGenerateSKU.Text = ResHelper.GetString("DocType.Ecommerce.lblGenerateSKU");
lblDepartments.Text = ResHelper.GetString("DocType.Ecommerce.lblDepartments");
lblNumber.Text = "SKUNumber source";
docTypeId = ValidationHelper.GetInteger(Request.QueryString["documenttypeid"], 0);
dci = DataClassInfoProvider.GetDataClass(docTypeId);
if (!RequestHelper.IsPostBack())
{
// Load departments
drpDepartments.DataSource = DepartmentInfoProvider.GetDepartments(null, "DepartmentDisplayName");
drpDepartments.DataBind();
drpDepartments.Items.Insert(0, "");
FillDropDownLists();
SelectMappings();
if (dci != null)
{
// Create automatically
chkGenerateSKU.Checked = dci.ClassCreateSKU;
// Try to select specified department
ListItem li = drpDepartments.Items.FindByValue((dci.ClassSKUDefaultDepartmentID).ToString());
if (li != null)
{
li.Selected = true;
}
}
}
}
protected void btnOK_Click(object sender, EventArgs e)
{
// Validate form
string errorMessage = ValidateForm();
if (errorMessage == "")
{
dci = DataClassInfoProvider.GetDataClass(docTypeId);
if (dci != null)
{
//string mappings = null;
string key = "";
#region "Set mappings"
key = "SKUImagePath";
if (drpImage.SelectedIndex > 0)
{
dci.SKUMappings[key] = drpImage.SelectedValue;
}
else if (dci.SKUMappings.Contains(key))
{
dci.SKUMappings.Remove(key);
}
key = "SKUName";
if (drpName.SelectedIndex > 0)
{
dci.SKUMappings[key] = drpName.SelectedValue;
}
else if (dci.SKUMappings.Contains(key))
{
dci.SKUMappings.Remove(key);
}
key = "SKUWeight";
if (drpWeight.SelectedIndex > 0)
{
dci.SKUMappings[key] = drpWeight.SelectedValue;
}
else if (dci.SKUMappings.Contains(key))
{
dci.SKUMappings.Remove(key);
}
key = "SKUHeight";
if (drpHeight.SelectedIndex > 0)
{
dci.SKUMappings[key] = drpHeight.SelectedValue;
}
else if (dci.SKUMappings.Contains(key))
{
dci.SKUMappings.Remove(key);
}
key = "SKUWidth";
if (drpWidth.SelectedIndex > 0)
{
dci.SKUMappings[key] = drpWidth.SelectedValue;
}
else if (dci.SKUMappings.Contains(key))
{
dci.SKUMappings.Remove(key);
}
key = "SKUDepth";
if (drpDepth.SelectedIndex > 0)
{
dci.SKUMappings[key] = drpDepth.SelectedValue;
}
else if (dci.SKUMappings.Contains(key))
{
dci.SKUMappings.Remove(key);
}
key = "SKUPrice";
if (drpPrice.SelectedIndex > 0)
{
dci.SKUMappings[key] = drpPrice.SelectedValue;
}
else if (dci.SKUMappings.Contains(key))
{
dci.SKUMappings.Remove(key);
}
key = "SKUDescription";
if (drpDescription.SelectedIndex > 0)
{
dci.SKUMappings[key] = drpDescription.SelectedValue;
}
else if (dci.SKUMappings.Contains(key))
{
dci.SKUMappings.Remove(key);
}
key = "SKUNumber";
if (drpNumber.SelectedIndex > 0)
{
dci.SKUMappings[key] = drpNumber.SelectedValue;
}
else if (dci.SKUMappings.Contains(key))
{
dci.SKUMappings.Remove(key);
}
#endregion
dci.ClassSKUDefaultDepartmentID = ValidationHelper.GetInteger(drpDepartments.SelectedValue, 0);
dci.ClassCreateSKU = chkGenerateSKU.Checked;
try
{
// Save changed to database
DataClassInfoProvider.SetDataClass(dci);
lblInfo.Visible = true;
lblInfo.Text = ResHelper.GetString("General.ChangesSaved");
}
catch (Exception ex)
{
errorMessage = ex.Message;
}
}
}
// Show error message
if (errorMessage != "")
{
lblError.Visible = true;
lblError.Text = errorMessage;
}
}
/// <summary>
/// Validates form and returns error message when occures.
/// </summary>
protected string ValidateForm()
{
string errorMessage = "";
if (chkGenerateSKU.Checked)
{
// Product name and Product price fields must be mapped
if ((drpName.SelectedValue == "") || (drpPrice.SelectedValue == ""))
{
errorMessage = ResHelper.GetString("DocType.Ecommerce.MappingMissing");
}
if (errorMessage == "")
{
// Check department
if (ValidationHelper.GetInteger(drpDepartments.SelectedValue, 0) == 0)
{
errorMessage = ResHelper.GetString("DocType.Ecommerce.DepartmentEmpty");
}
}
}
return errorMessage;
}
/// <summary>
/// Selects specified mappings in dropdownlists
/// </summary>
protected void SelectMappings()
{
if (dci != null)
{
drpName.SelectedValue = ValidationHelper.GetString(dci.SKUMappings["SKUName"], "0");
drpImage.SelectedValue = ValidationHelper.GetString(dci.SKUMappings["SKUImagePath"], "0");
drpWeight.SelectedValue = ValidationHelper.GetString(dci.SKUMappings["SKUWeight"], "0");
drpHeight.SelectedValue = ValidationHelper.GetString(dci.SKUMappings["SKUHeight"], "0");
drpWidth.SelectedValue = ValidationHelper.GetString(dci.SKUMappings["SKUWidth"], "0");
drpDepth.SelectedValue = ValidationHelper.GetString(dci.SKUMappings["SKUDepth"], "0");
drpPrice.SelectedValue = ValidationHelper.GetString(dci.SKUMappings["SKUPrice"], "0");
drpDescription.SelectedValue = ValidationHelper.GetString(dci.SKUMappings["SKUDescription"], "0");
drpNumber.SelectedValue = ValidationHelper.GetString(dci.SKUMappings["SKUNumber"], "0");
}
}
/// <summary>
/// Fills dropdownlists with data.
/// </summary>
protected void FillDropDownLists()
{
FormFieldInfo[] fields = null;
if (dci != null)
{
FormInfo fi = new FormInfo();
fi.LoadXmlDefinition(dci.ClassFormDefinition);
fields = fi.GetFields(true, true);
}
// Insert '( none )' item into all dropdownlists
string noneString = ResHelper.GetString("general.selectnone");
drpImage.Items.Add(new ListItem(noneString, ""));
drpHeight.Items.Add(new ListItem(noneString, ""));
drpDepth.Items.Add(new ListItem(noneString, ""));
drpWeight.Items.Add(new ListItem(noneString, ""));
drpWidth.Items.Add(new ListItem(noneString, ""));
drpName.Items.Add(new ListItem(noneString, ""));
drpPrice.Items.Add(new ListItem(noneString, ""));
drpDescription.Items.Add(new ListItem(noneString, ""));
drpNumber.Items.Add(new ListItem(noneString, ""));
// Insert 'Document name' item into all dropdownlists
string docNameValue = "DocumentName";
drpImage.Items.Add(new ListItem(docNameValue, docNameValue));
drpHeight.Items.Add(new ListItem(docNameValue, docNameValue));
drpDepth.Items.Add(new ListItem(docNameValue, docNameValue));
drpWeight.Items.Add(new ListItem(docNameValue, docNameValue));
drpWidth.Items.Add(new ListItem(docNameValue, docNameValue));
drpName.Items.Add(new ListItem(docNameValue, docNameValue));
drpPrice.Items.Add(new ListItem(docNameValue, docNameValue));
drpDescription.Items.Add(new ListItem(docNameValue, docNameValue));
drpNumber.Items.Add(new ListItem(docNameValue, docNameValue));
// Fill dropdownlists with data
if (fields != null)
{
foreach (FormFieldInfo ffi in fields)
{
if (ffi.Name.ToLower() != "documentname")
{
drpImage.Items.Add(new ListItem(ffi.Name, ffi.Name));
drpHeight.Items.Add(new ListItem(ffi.Name, ffi.Name));
drpDepth.Items.Add(new ListItem(ffi.Name, ffi.Name));
drpWeight.Items.Add(new ListItem(ffi.Name, ffi.Name));
drpWidth.Items.Add(new ListItem(ffi.Name, ffi.Name));
drpName.Items.Add(new ListItem(ffi.Name, ffi.Name));
drpPrice.Items.Add(new ListItem(ffi.Name, ffi.Name));
drpDescription.Items.Add(new ListItem(ffi.Name, ffi.Name));
drpNumber.Items.Add(new ListItem(ffi.Name, ffi.Name));
}
}
}
}
}
You could see that the mapping itself is done at line #171 and there are several lines with drpNumber dropdownlist (and the corresponding label) added. This way you could add more mappings if you need.
Please note that the label next to the dropdown list is hard-coded in the codebehind file (lblNumber.Text = "SKUNumber source";), so to be able to change the string from usual place (.resx file), you could create a resource string and use it like in other labels.
Hope this is what you needed.
Best regards,
Zdenek C.