I was hit with a shock when I (and my code) discovered the
ProductTemplateId was removed from the Products table !!!
In the ProductHelper.cs file I had:
if (product.ProductTemplateId == 5)
..........
But now I don't know how to access the ProductTemplateId of 5?
Can it be accessed through another field?
I know this is not right, but can one of these other fields be used instead:
if (product.TemplateFields == 5) ???
or
if (product.ProductProductTemplates == 5) ???
You took the ProductTemplateId out of the Products table !!!
- jmestep
- AbleCommerce Angel
- Posts: 8164
- Joined: Sun Feb 29, 2004 8:04 pm
- Location: Dayton, OH
- Contact:
Re: You took the ProductTemplateId out of the Products table !!!
In 7.0.4, you can have more than one template apply to a product, so you need to get the collection, then select the one you want. I just had to do it on a site I upgraded from 7.0.3. The following will work if you want the first template id or if there is only one
Code: Select all
private static int GetTemplateId(Product product)
{
int templateId = 0;
ProductTemplateCollection templates = ProductTemplateDataSource.LoadForProduct(product.ProductId);
if (templates != null)
{
//get from only one template for now
templateId = product.ProductProductTemplates[0].ProductTemplateId;
}
return templateId;
}
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx
Re: You took the ProductTemplateId out of the Products table !!!
thanks Judy, you saved the day again.
This works also (I used it in CategoryGridPage2.ascx.cs):
if (product.ProductProductTemplates[0].ProductTemplateId == 5)
...
but it only works if all the products for that Category have a Template defined for those
products, otherwise it gives the error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I'll have to check for null or something before using it.
This works also (I used it in CategoryGridPage2.ascx.cs):
if (product.ProductProductTemplates[0].ProductTemplateId == 5)
...
but it only works if all the products for that Category have a Template defined for those
products, otherwise it gives the error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I'll have to check for null or something before using it.