Referring to Custom Data Fields in Scriptlets
-
- Ensign (ENS)
- Posts: 5
- Joined: Thu Oct 07, 2010 11:18 am
Referring to Custom Data Fields in Scriptlets
The product being sold is a collection of maps organized by region. Each region can contain hundreds of individual maps. When a customer picks a region a query runs against an existing table and the detail information of the region is displayed. I got that to work by using the existing SKU field in the products table. Since this process only needs to run for specific categories, I modified the Show Product 1 scriptlet like this:
#if($Category.ParentId == 7)
[[Conlib:Custom/ChartDetail RegionID="$Product.SKU"]]
#end
This feeds $Product.SKU into the custom control, ChartDetail. Works just fine. Unfortunately, we need to use the SKU field to contain a SKU, not a RegionID.
I added the RegionID as a custom field to the products admin page using the 'How to add a Product Custom Field' post. (Many thanks to AbelMods!) That's all working just fine. I can add a RegionID from the admin page and it shows up in the database.
Now I need to grab the value from that custom field and plug it into the ChartDetail web control in the Show Product 1 scriptlet. I've tried many combinations of syntax, but nothing is working yet.
Thanks in advance.
#if($Category.ParentId == 7)
[[Conlib:Custom/ChartDetail RegionID="$Product.SKU"]]
#end
This feeds $Product.SKU into the custom control, ChartDetail. Works just fine. Unfortunately, we need to use the SKU field to contain a SKU, not a RegionID.
I added the RegionID as a custom field to the products admin page using the 'How to add a Product Custom Field' post. (Many thanks to AbelMods!) That's all working just fine. I can add a RegionID from the admin page and it shows up in the database.
Now I need to grab the value from that custom field and plug it into the ChartDetail web control in the Show Product 1 scriptlet. I've tried many combinations of syntax, but nothing is working yet.
Thanks in advance.
Re: Referring to Custom Data Fields in Scriptlets
Suppose your custom field name is Region, now on show product 1 we want to read value for that field. Then we can do something like this
Code: Select all
#foreach($pcf in $Product.CustomFields)
#if($pcf.FieldName == "Region")
Region:- $pcf.FieldValue
#end
#end
- napacabs
- Lieutenant, Jr. Grade (LT JG)
- Posts: 45
- Joined: Mon Jan 14, 2008 2:58 pm
- Location: Chino, California
- Contact:
Re: Referring to Custom Data Fields in Scriptlets
How can one add this to a control such as ConLib:FeaturedProductsGrid?
Re: Referring to Custom Data Fields in Scriptlets
Tom,
I've included some sample code below. It's based on a great post from AbleMods that explains how to use the custom fields. Take a look viewtopic.php?f=47&t=12056.
You can add this code to your FeaturedProductsGrid.ascx.
Here's the code to add to your FeaturedProductsGrid.ascx.cs.
The second argument in the call is the name of your custom field. You can put as many of these on your control as you need or you could hard code which fields to return in the function. If you wanted to return the same set of custom fields every time, your function might look like this. Note you would have to adjust the code in the ascx file to only pass the product object.
That will hopefully get you started.
I've included some sample code below. It's based on a great post from AbleMods that explains how to use the custom fields. Take a look viewtopic.php?f=47&t=12056.
You can add this code to your FeaturedProductsGrid.ascx.
Code: Select all
<asp:Label ID="CustomFieldLabel" runat="server" Text='<%# GetCustomField(Container.DataItem, "CustomField") %>'></asp:Label><br />
Code: Select all
protected string GetCustomField(object dataItem, string fieldName)
{
Product product = (Product)dataItem;
foreach (ProductCustomField pcf in product.CustomFields)
{
if (pcf.FieldName == fieldName)
return pcf.FieldValue;
}
return string.Empty;
}
Code: Select all
protected string GetCustomField(object dataItem)
{
Product product = (Product)dataItem;
string customValues = string.Empty;
foreach (ProductCustomField pcf in product.CustomFields)
{
if (pcf.FieldName == "CustomField")
{
customValues += string.Format("Custom Field 1 = {0}<br />", pcf.FieldValue);
}
else if (pcf.FieldName == "CustomField2")
{
customValues += string.Format("Custom Field 2 = {0}<br />", pcf.FieldValue);
}
}
return customValues;
}
- napacabs
- Lieutenant, Jr. Grade (LT JG)
- Posts: 45
- Joined: Mon Jan 14, 2008 2:58 pm
- Location: Chino, California
- Contact:
Re: Referring to Custom Data Fields in Scriptlets
David, code works perfectly, thank you very much for sharing.
Re: Referring to Custom Data Fields in Scriptlets
Similar question:
I need to pull a Custom Field value into my email templates. I suspect that there's a method in NVelocity to do this, but I don't see any mention of it in the posts. Anyone else been successful in getting a custom field value to display in the product grids on the email templates, packing slips, pull sheets, etc?
Thanks!
I need to pull a Custom Field value into my email templates. I suspect that there's a method in NVelocity to do this, but I don't see any mention of it in the posts. Anyone else been successful in getting a custom field value to display in the product grids on the email templates, packing slips, pull sheets, etc?
Thanks!
Re: Referring to Custom Data Fields in Scriptlets
Take a look at this forum post for using custom product fields to an email template:
viewtopic.php?f=42&t=11146&p=47679&hili ... eld#p47679
viewtopic.php?f=42&t=11146&p=47679&hili ... eld#p47679