You took the ProductTemplateId out of the Products table !!!

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

You took the ProductTemplateId out of the Products table !!!

Post by Mike718NY » Sun Jan 10, 2010 1:01 pm

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) ???

User avatar
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 !!!

Post by jmestep » Sun Jan 10, 2010 1:17 pm

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

Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

Re: You took the ProductTemplateId out of the Products table !!!

Post by Mike718NY » Mon Jan 11, 2010 10:21 am

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.

Post Reply