subproducts and related items on same page?

General ShopSite user discussion

subproducts and related items on same page?

Postby mactheweb » Wed Jun 27, 2007 10:07 am

I'm slowly learning the templating of shopsite. Is it possible to use subproducts for the normal multiple products on one page and to use it for related items both on the same more info products page? If so, how?
mactheweb
 
Posts: 21
Joined: Mon Feb 12, 2007 11:08 am

Postby Jim » Wed Jun 27, 2007 1:20 pm

Lots of things are possible with the template language. I'm not sure I under stand what you are asking though.

You can have multiple [-- Loop Products --] on a page template and multiple [-- loop supproducts --] in a product template.

By using a [-- VAR.somename somevalue --] tag before the loop you can then do decisions within the product template to check if a particular field is a specific value and if it is then you do one action and if it is not then you do something else.
In the page template you could have

[-- VAR.nosubproduct "Yes" --]
[-- loop products --]
[-- product --]
[-- end_loop products --]


[-- VAR.nosubproduct "No" --]
[-- loop products --]
[-- product --]
[-- end_loop products --]


Then in the product template you could have

[-- if VAR.nosubproduct "no" --]

[-- product.name --]
[-- product.sku --]

[-- Else --]
[-- if var.nosubproduct "Yes" --]
[-- loop subproducts --]
[-- subproducts --]
[-- end_loop subproducts --]

[--end_if --]

The result of the first [-- loop products --] on the page would result in
subproducts being listed.
and the result of the second [-- loop products --] on the page would result in the product name and sku being displayed.

You can extend the example to only display certain subproducts by setting a VAR and then in the [-- Define Subproducts --] section of the product template check for a value in a field of the subproduct to see if it matches or not and do appropriate actions depending on the value set for the subproduct. The Extra Product Fields are a good place to put something to check against.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Let me see if I've gotten this right

Postby mactheweb » Wed Jun 27, 2007 3:09 pm

First thanks for the thorough reply.

If I understand this right, I could use

[-- VAR.PRODUCT.Field10 "main" --]
[-- loop subproducts --]
[-- product --]
[-- end_loop subproducts --]

for the main subproducts and

[-- VAR.PRODUCT.Field10 "extra" --]
[-- loop subproducts --]
[-- product --]
[-- end_loop subproducts --]

for the cross sell section?

And for the define subproducts section:
[-- DEFINE SUBPRODUCT --]
[-- IF VAR.PRODUCT.Field10 "main" --]
<div class="moreproducts">
<p style="float:right"><a href="[-- PRODUCT.AddToCartURL --]"><img src="http://www.tolandhomegarden.com/shop/media/cart_add.png" alt="add to cart" width="116"height="51"></a></p>
<h3>[-- PRODUCT.Field1 --]</h3>
<div style="margin-right: 119px"><p>Item Number: [-- PRODUCT.SKU --]</p>
<p>Dimensions: [-- PRODUCT.Field8 --]</p>
<p>Wholesale Price: [-- PRODUCT.Price --] </p></div><hr>
</div>
[-- END_IF --]

[-- IF VAR.PRODUCT.Field10 "extra" --]
something else
[-- END_IF --]


[-- END_DEFINE SUBPRODUCT --]
mactheweb
 
Posts: 21
Joined: Mon Feb 12, 2007 11:08 am

Postby Jim » Wed Jun 27, 2007 8:14 pm

The code looks basically correct. Although it probably would work I wouldn't use the PRODUCT.Field10 as the name of the VAR like [-- VAR.PRODUCT.Field10 "main" --] Since PRODUCT.Field10 is actually a field in the product database. It could be confusing for someone who is reading the template to understand what is going on. It might be less confusing to use something like [-- VAR.ProdType "main" --]

The way you have the code written all products would be dealt with in the same way in each loop subproduct section. Which may be what you want. However, what I was suggesting for the extra product fields is that you could use them to determine what to do with _each_ subproduct. You could set the extra product field 10 to be "main" on some products and "extra" on others. Then in your define subproducts section you would have a statement comparing product.field10 to the VAR that you set to determine where the products display.

[-- IF VAR.ProdType product.field10 --] So you are comparing the VAR to a field in the product record and not just to what you had previously set the VAR to be.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah


Return to User Forum

Who is online

Users browsing this forum: No registered users and 52 guests