Using Product Templates on Category Pages

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
rmaweb
Commander (CMDR)
Commander (CMDR)
Posts: 118
Joined: Fri Sep 10, 2010 9:41 am

Using Product Templates on Category Pages

Post by rmaweb » Tue Jul 29, 2014 10:09 am

Hello Fellow Ablecommerce users ( and Able Team Members )

I am currently trying to build a custom Category Page conLib file. For it, I would like to use a product template that is attached to all of the products for that category and list the products in a table format with the table header cells being a repeater with the merchant field names in the product template and the body cells being a repeater on each table row with the input values for each field in the product template, as well as the price and add to cart links. I am really getting stumped on trying to come up with a way to identify if a particular merchant field in the product template is used by any products in the category, and if not, to not display it ( so that I dont have a table stretched out with columns that don't have any data in them ).

Has anybody else come up with a category display conlib that makes use of product templates? And if so, can you share how you made it work?

As a reference, here is two categories on my site that would benefit from the above conlib, http://store.scottsbt.com/Fishing/Reels ... alVSX.aspx and http://store.scottsbt.com/Fishing/Reels ... nning.aspx

In them are hard-coded tables that I have in the category description that has the models (products) and the information for those products. Underneath, is the control that actually displays the products. In those product pages, are tables that show the same model information, but the header rows are the tf.InputField.Name fields and the content underneath are the tf.InputValue fields from the product template used on those products.

I would like to move away from having a hard-coded table in the description that displays model information for products that we might not have anymore, and also has the repetition of having that table and then the products displayed underneath in the category page.

I included 2 categories because the products in those categories use the same product template, however, not all of the product template fields are used on both of them. In the product display pages, I have it set to check to see if the value of a field is null or empty, and to not display the field if so. However, I can't figure out how to do this on a category wide level.

Any help would be appreciated,
Ryan A.
Ryan A.
Scott's Bait and Tackle
http://store.scottsbt.com
Work In Progress
Able Gold R10
Bootstrap 3.3

jguengerich
Commodore (COMO)
Commodore (COMO)
Posts: 436
Joined: Tue May 07, 2013 1:59 pm

Re: Using Product Templates on Category Pages

Post by jguengerich » Fri Aug 08, 2014 8:35 am

If it helps, here is an answer to one part of your question. This is an SQL query that would give you a list of the field IDs of all the template fields from a specific template that are used by any product in a specific category:

Code: Select all

select distinct ac_InputFields.InputFieldId
	from ac_ProductTemplates
		join ac_ProductProductTemplates on ac_ProductProductTemplates.ProductTemplateId = ac_ProductTemplates.ProductTemplateId
		join ac_Products on ac_Products.ProductId = ac_ProductProductTemplates.ProductId
		join ac_CatalogNodes on ac_CatalogNodes.CatalogNodeId = ac_Products.ProductId
		join ac_Categories on ac_Categories.CategoryId = ac_CatalogNodes.CategoryId
		join ac_InputFields on ac_InputFields.ProductTemplateId = ac_ProductTemplates.ProductTemplateId
		join ac_ProductTemplateFields on ac_ProductTemplateFields.InputFieldId = ac_InputFields.InputFieldId
	where ac_Categories.Name = 'Some Category Name'
		and ac_ProductTemplates.Name = 'Some Template Name'
		and InputValue <> ''
Obviously, there are several ways to implement this. You could do a direct query, you could use NHibernate Criteria, you could use AC DomainModel objects and generic lists & LINQ, etc.
I suppose the least optimized version would be retrieving lists from the objects and using loops to go through them and build a "used field" list. You would know the category when the page loads, so you could do things like:

Code: Select all

ProductDataSource.LoadForCategory(...) // gives you a list of products in the category
someProduct.TemplateFields // gives you a list of template fields a particular product has the ability to use
someTemplateField.InputValue // if empty string, this field isn't used
someTemplateField.InputFieldId  // the Id to add your list of used fields (if it isn't already in the list)
Note I'm not 100% sure on those last 2 lines. I haven't actually tested the code. I already corrected this post twice :).
There's still the matter of creating a table based on this info. You'd almost have to build it "on the fly" if you really want the number of columns to be dynamic.
Jay

Post Reply