Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Map document field 'Product Code' to product property 'Product Number' View modes: 
User avatar
Member
Member
sandip.patil-acapteam - 6/19/2009 7:03:59 AM
   
Map document field 'Product Code' to product property 'Product Number'
Hi
I have document field 'Product Code' in my document type.I want to map this with product property 'Product Number' to avoid confusion during the product creation.

Also i wan to hide Manufacturer,Suplier and whole package attributes in product tab because this is useless for me(we our self manufacture and sell and product is online course )


Help....

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 6/29/2009 2:07:55 AM
   
RE:Map document field 'Product Code' to product property 'Product Number'
Hello,

Could you please describe further, what do you mean by "I want to map this with product property 'Product Number' to avoid confusion during the product creation."?

Regarding hiding certain information in the CMS interface.

If you want to edit the CMS Desk/CMS Site manager, you can find out what files are displaying the given content with the Firefox browser. "Right click on the given frame -> This Frame -> View frame info" - there is the path of the file, which contains the displayed page.

In this case it is the file ~\CMSModules\Ecommerce\Tools\Header.aspx.cs. You need to comment out for example the lines

this.CurrentMaster.Tabs.Tabs[4, 0] = ResHelper.GetString("Ecommerce.Manufacturers");
this.CurrentMaster.Tabs.Tabs[4, 2] = "Manufacturers/Manufacturer_List.aspx";

To hide the "Manufacturers" tab.

Best regards,
Boris Pocatko

User avatar
Member
Member
sandip.patil-acapteam - 6/29/2009 4:31:53 AM
   
RE:Map document field 'Product Code' to product property 'Product Number'
Here is the description of my question...

When we create new document type and if we want this document in e-commerce and use as a product then edit any document type in the CMS Site manager-->Administrator-->Document Type and select the tab 'General' and check 'Document is product type' check box so this document will behave like product to set the e-commerce properties or map the document fields with product properties go to the 'E-Commerce ' tab and set "Product name source" ,"Product price source","Product description source" and other if required to our document type fields.

When we create new document of this product on CMSDesk then we fill the product form and after its creation we go to the 'Product' tab of this document. we get here the pre-filled fields like "Product name:","Description:" and "Price:" because this fields are mapped with document type but not the field "Product number:" because it is not available in the document mapping......


User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 7/8/2009 8:14:19 PM
   
RE:Map document field 'Product Code' to product property 'Product Number'
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.