Displaying only products in matrix that match variable type

General ShopSite user discussion

Displaying only products in matrix that match variable type

Postby johnbiggscr » Fri Sep 02, 2011 8:12 am

We are creating pages that use the matrix layout. We wish to break up that layout on a page so that the products are shown in different categories sorted by a specific variable value, in this case it may be by name of the product though we might do it by a different variable such as product field or whatever.

I suppose that in theory I can do it by calling mulitple product loops but i do not know how to code such a loop.
I would be trying to achieve the following sort of layout:

Product A image .................................product a blah blah sku: blah blah price: blah blah
Description of Product A ....................... product a blah blah2 sku: blah blah2 price: blah blah2
................................................... product a blah blah3 sku: blah blah3 price: blah blah3


Product b image................................... product b blah blah sku: blah blah price: blah blah
Description of Product b.......................... product b blah blah2 sku: blah blah2 price: blah blah2
..................................................... product b blah blah3 sku: blah blah3 price: blah blah3

And so on.
(ignore the dots, they are just there to make the layout work)

I need some way to call a loop for product a, then call a loop for product b etc.

The number of products in each category may change as products are added and removed from pages, and so trying to loop by a fixed number, as i have asked on this forum in the past, will not be the way to go for us.
Maybe subproducts might do it but i do not know enough about how that works to determine that. If anyone has used that for their sites and could link to it so I could see it in action then that would be helpful, but i really would prefer to call multiple loops for specific variable values.

Anyone any clues?

We are using pro v11.
johnbiggscr
 
Posts: 68
Joined: Mon Mar 01, 2010 12:41 pm
Location: Cedar Rapids

Re: Displaying only products in matrix that match variable t

Postby Jim » Fri Sep 02, 2011 8:30 am

Use a VAR on the page template to determine what will be displayed in a certain area of the page. Loop through the products in that section and in the product template check what var is set and compare your product field (in the example I am using the extra product field1) that indicates what section the product falls in to the var and if it matchs out put the product otherwise don't output anything.

In the page template
[-- VAR.SECTION first --]
[-- loop products --]
[-- product --]
[-- end_loop products --]

[-- VAR.SECTION second --]
[-- loop products --]
[-- product --]
[-- end_loop products --]

[-- VAR.SECTION third --]
[-- loop products --]
[-- product --]
[-- end_loop products --]

...

In the product template
[-- if product.field1 VAR.SECTION --]
output the product info you want
[-- else --]
don't do anything
[-- end_if --]

Note: template tags are not case sensitive so it doesn't matter if they are upper, lower or mixed case.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: Displaying only products in matrix that match variable t

Postby Jim » Fri Sep 02, 2011 8:53 am

Rereading your post it looks like you might also want help with the product layout. You just use the template tag that outputs the product field you want within html code that sets the layout. For example

<table>
<tr>>
<td>[--product.graphic --]</td>
<td>[--product.sku --]<br>[--product.price--]</td>
</tr>
<tr>
<td>[--product.productdescription --]</td>
...
</tr>
</table>

There are some excellent tutorials on the shopsite.com website http://shopsite.com/tutorial/ and a "cookbook" of sample template code that you can copy into your own template at http://shopsite.com/tutorial/cookbook .
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: Displaying only products in matrix that match variable t

Postby johnbiggscr » Fri Sep 02, 2011 10:08 am

I tried going to that link and it said it didnt exist.

I am making some progress using the code you supplied thank you. I have run into a slight snag however.
Because each page will be different in terms of layout and products I cannot use the same template for each page and use a fixed variable name for displaying the matrix at the same time. In other words I do not have product A on each page so hardcoding the template to say VAR.SELECTION Product_A will not work.

I have tried calling the product loop from with both PAGE.Text1 and PAGE.Field1 but neither actually work, they just display the entries just as if they were text. If i cut and paste the exact same code from the PAGE.Text1 and place it directly into the test template it works fine.
Am I able to actually call the product loop from within a page text? if so is there some special syntax i need to use?
johnbiggscr
 
Posts: 68
Joined: Mon Mar 01, 2010 12:41 pm
Location: Cedar Rapids

Re: Displaying only products in matrix that match variable t

Postby Jim » Fri Sep 02, 2011 2:37 pm

Sorry, the cookbook url should be http://www.shopsite.com/templates/cookbook/

Template tags can only be used in the template itself they can't be used in a text field such as Page > text,1, product description or the global Header / Footer.

You don't have to use a "fixed" variable name. You could use one of the extra page fields to contain the the variable that you want the products to be sorted on. Something like this

[-- VAR.Section page.field1 --]
[-- loop products --]
[-- product --]
[-- end_loop products --]

[-- VAR.Section page.field2 --]
[-- loop products --]
[-- product --]
[-- end_loop products --]

etc.

I'm not sure what you mean by this
"I have tried calling the product loop from with both PAGE.Text1 and PAGE.Field1 but neither actually work,"
The code
===============
[-- loop products --]
[-- product --]
[-- end_loop products --]
================
loops through all the products assigned to the page and displays the products in whatever format that you specify in the product template.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: Displaying only products in matrix that match variable t

Postby johnbiggscr » Fri Sep 02, 2011 2:51 pm

What I meant by the last bit was that I tried using calling the code from 2 different field in the page itself but as you said it had to be called from the Template then that answered the question.
johnbiggscr
 
Posts: 68
Joined: Mon Mar 01, 2010 12:41 pm
Location: Cedar Rapids


Return to User Forum

Who is online

Users browsing this forum: No registered users and 78 guests