Interesting Loop Products Problem

General ShopSite user discussion

Interesting Loop Products Problem

Postby royhink » Mon Oct 29, 2007 11:52 am

I've been asked if I can lay out a category page showing sub category headers, such as:

PAGE NAME

SUBCATEGORY 1
Product1
Product2

SUBCATEGORY 2
Product 3Product 4
Product 5

Can you do a conditional in the loop to confirm a code in a product field? Something like:
[ LOOP PRODUCTS ]
IF product.field9 SUBCATEGORY1
[ PRODUCT SUBCAT1 ]
IF product.field9 SUBCATEGORY2
[PRODUCT SUBCAT2 ]

Can this be done at all, do you think?

Any help appreciated!
royhink
 
Posts: 104
Joined: Fri Jul 20, 2007 10:04 am
Location: Petaluma, CA

Postby Jim » Mon Oct 29, 2007 12:57 pm

You can do sort of what you want but you have to do a loop products section for each of the subcategories you want. Set a VAR to the subcategory that you want just before each Loop section and then in the loop just check your product.fieldx to see if it matches the VAR and if it does output the item otherwise skip it.

set VAR
loop products to see if product field matchs VAR

set VAR
loop

etc.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Postby royhink » Mon Oct 29, 2007 2:34 pm

Thanks for the response, Jim. I appreciate it.

I wanted to be sure I could do this before my designer spent time on it.

It sounds like I'm heading to:

<tr><td>SUBCATEGORY1 HEADER
<tr><td>
[-- loop products --]
[-- var.category subcat1 --]
[ IF VAR.category product.fieldx --]
[-- product template --]
[-- end_loop products --]

<tr><td>SUBCATEGORY2 HEADER
<tr><td>
[-- loop products --]
[-- var.category subcat2 --]
[ IF VAR.category product.fieldx --]
[-- product template --]
[-- end_loop products --]

Is this what you were thinking?
royhink
 
Posts: 104
Joined: Fri Jul 20, 2007 10:04 am
Location: Petaluma, CA

Postby Jim » Tue Oct 30, 2007 6:32 am

I think I may have misled you a little on this. In the Page template you do not have access to the product database fields, only page database fields.

So you set the VAR for what category you want and then do the Loop product section. In the Product template you check the VAR to see if it matches the VAR and determine if the product is displayed. so it would be something like this.

IN PAGE TEMPLATE
Code: Select all
[-- var.category subcat1 --]

<tr><td>SUBCATEGORY1 HEADER
<tr><td>
[-- loop products --]
[-- product template --]
[-- end_loop products --]

[-- var.category subcat2 --]
<tr><td>SUBCATEGORY2 HEADER
<tr><td>
[-- loop products --]
[-- product template --]
[-- end_loop products --]


IN PRODUCT TEMPLATE.
Code: Select all
[ IF VAR.category product.fieldx --]
   output the product using what ever formatting you need
[-- else --]
 don't do anything
[-- end_IF--]


Make sure you have the table tags <tr><td> matching around the right data.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Postby royhink » Tue Dec 04, 2007 5:11 pm

I apologize for the long post.....

I am getting some odd layout results from this loop code, and really need a new set of eyes to look at it. Any ShopSite wizards help appreciated.

I have a series of 'subcategories' on a page, and a series of loops that pick up the correct product based on a code in a product.field.

The problem is, If I have an odd number of products in a subcategory, the row breaks don't seem to be working.

The format is very dependent on the product order. When I resorted the products on the page, it solved most, but not all the layout problems.

You can see the under construction page here:
http://www.bestcountryreports.com/Argen ... ports.html

My code in the page template
Code: Select all
<!-- begin 1st product table -->
      <table class="p-b" align="center" border="0" cellpadding="0" cellspacing="0" width="600">
        <tbody>
          <tr>
            <td colspan="2" valign="top">
            <div align="left"><a name="Society"></a><span class="c-n3">Culture</span></div>
            </td>
          </tr>
          <tr>
            <td align="middle" valign="top" width="105">Sub Cat Image Placeholder
            </td>
            <td style="text-align: center; vertical-align: top;">
        <table style="width: 495px; text-align: left; margin-left: auto; margin-right: auto;" valign="top" border="0" cellpadding="10" cellspacing="0">
              <tbody>
      <tr>
<!-- Set VAR for each subcategory -->
      [-- VAR.subcat Society --]
      [-- LOOP Products 2 --]
          [-- PRODUCT BCR_MainProd_1 --]
      [-- END_LOOP PRODUCTS --]
        </tr>
        <tr><td>line placeholder
          </td></tr>
        </tbody>
        </table>
            </td>
          </tr>
        </tbody>
      </table>
<!-- begin 2nd product table -->
      <table .........................


and in my product template
Code: Select all
[-- IF VAR.subcat PRODUCT.Field10 --]
   <td width="50%" align="left" valign="top">
      <span class="c-pn"><b><a href="[-- PRODUCT.MoreInfoURL --]">
        [-- PRODUCT.Name --]</a></b></span>
<br>
      [-- IF PRODUCT.Field6 --]
      <font class="c-ptl">[-- PRODUCT.Field6 --]</font><br>
      [-- END_IF --]
      [-- IF PRODUCT.ProductDescription --]
      <font class="p-b">[-- PRODUCT.ProductDescription --]</font><br>
      [-- END_IF --]
                <font class="p-p">[-- PRODUCT.Price --]</font>

<!--  DISPLAY 'MORE' LINK AFTER SHORT DESCRIPTION  -->
        [-- IF PRODUCT.DisplayMoreInformationPage --] 
      <br><a href="[-- PRODUCT.MoreInfoURL --]"> 
      <font class="p-b">More Information</a> 
        [-- END_IF --]
                &nbsp;&nbsp;
                <a href="[-- PRODUCT.AddtoCartURL --]">Add to Cart</a>
                </font>
</td>
[-- ELSE --]
    <!-- do nothing -->
[-- END_IF --]
royhink
 
Posts: 104
Joined: Fri Jul 20, 2007 10:04 am
Location: Petaluma, CA

Postby Jim » Tue Dec 04, 2007 6:57 pm

Each time you go through the loop 2 time ShopSite will generate the closing and opening TR tags. But it is counting all products that are examined and it doesn't know if the product template actually displayed the product or not. So if you have 6 products and the 1st and 2nd aren't out put you would see an empty <tr></tr> set. Say the odd number ones match the Var then you will see one product per row in the left column. If even ones match then you would see one product per row in the right column. If 1,2,4,5 match you would see 2 in the first row then then one in the right column then one in the left.

The way to get around this is to have your product template keep track of when the opening and closing tag are out put instead of using the "count" value in the Loop products tag. You do this by keeping track if you are on the even or odd product and using the INC and DEC parameters for a var counter then put out the appropriate start and end tags when needed.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Postby royhink » Wed Dec 05, 2007 1:07 pm

Thanks for the response, Jim. I've always had trouble understanding the way the loops work.

Can you step me thru the code? I haven't a clue!
royhink
 
Posts: 104
Joined: Fri Jul 20, 2007 10:04 am
Location: Petaluma, CA

Postby royhink » Thu Dec 06, 2007 6:46 pm

The solution I ended up with is working in all browsers. If you see a more elegant way, let me know.

Thanks for the direction, Jim. I was able to work this out after a good nights sleep!

Code: Select all
IN PAGE TEMPLATE

<tr>
<!-- Set VAR for each subcategory -->
[-- VAR.product 0 --]
[-- VAR.subcat Society --]
[-- LOOP Products --]
    [-- PRODUCT BCR_MainProd_2 --]
[-- END_LOOP PRODUCTS --]
</tr>
                   
IN PRODUCT TEMPLATE

[-- IF VAR.subcat PRODUCT.Field10 --]
   <td>
          product layout
</td>
   [-- VAR.product INC --]
   [-- IF VAR.product "2" --]
      </tr><tr>
           [-- VAR.product "0" --]
   [-- END_IF --]
[-- ELSE --]
   <!-- -->
[-- END_IF --]
royhink
 
Posts: 104
Joined: Fri Jul 20, 2007 10:04 am
Location: Petaluma, CA

Postby CarolA » Fri Feb 29, 2008 10:00 am

Just wanted to say thanks for posting these details in this thread. I needed to do the same thing and it was easy with this information to go by. :D
CarolA
 
Posts: 70
Joined: Thu Nov 29, 2007 2:59 pm
Location: Utah

Thanks - Worked for active product mod I have done

Postby dmsid » Tue Oct 14, 2008 7:46 am

Thanks for the help. I used these posts to help with a mod I have done to flag products active and inactive. (Why SS has not done this for the past 6 years I have used the product I will never know. How hard would it be to have a active/inactive checkbox on the product page. :( Yes I have asked a dozen times.)

Now I can have two columns on the Category Pages without blanks for products I have flagged inactive.

THANKS! :)

Page Template

<tr>
[-- VAR.product 0 --]
[-- LOOP PRODUCTS --]
[-- PRODUCT --]
[-- END_LOOP PRODUCTS --]
</tr>


Product Template
#<!-- ------------------------------------------------ -->#
#<!-- ------------------- Product -------------------- -->#
#<!-- ------------------------------------------------ -->#
[-- DEFINE PRODUCT --]
[-- VAR.define "product" --]
[-- INCLUDE awesome_orange_001_pr_vars.sst PROCESS --]

##############################################################################
# CHECK FOR ACTIVE PRODUCT
[-- IF PRODUCT.Field1 "1" --]

##############################################################################

<td valign="top" class="products_content">
<table width="700" border="0" class="product_list">
<tr class="product_list_row_1">
<td class="product_list_1a"></td>
<td class="product_list_1b"></td>
<td class="product_list_1c"></td>
</tr>
<tr class="product_list_row_2">
<td class="product_list_2a"></td>
<td width="350" class="product_list_content">[-- INCLUDE awesome_orange_001_pr_include.sst PROCESS --]</td>
<td class="product_list_2c"></td>
</tr>
<tr class="product_list_row_3">
<td class="product_list_3a"></td>
<td class="product_list_3b"></td>
<td class="product_list_3c"></td>
</tr>
</table>
</td>

[-- VAR.product INC --]
[-- IF VAR.product "2" --]
</tr><tr>
[-- VAR.product "0" --]
[-- END_IF --]

##############################################################################
# CHECK FOR ACTIVE PRODUCT
[-- END_IF --]

[-- END_DEFINE PRODUCT --]
dmsid
 
Posts: 29
Joined: Tue Aug 29, 2006 10:15 am

Postby adam123 » Tue Nov 17, 2009 5:08 pm

In the product template,

If you would like to re-use the same layout, do you have to keep re-defining the layout for each category using repeated "if" statements or is there a better way?

For instance I have links the user would click on like: Manufacterer, Brand, etc. which are different fields, but I would like to use the same product layout for the way each type will be laid out.

This is something I am going for at the moment:

*-wildcard (any field)

Page Template
[-- var.manufacturer manufacturer_chosen_type --]
<h1>MANUFACTURER - MANUFACTURER CHOSEN TYPE</h1>
[-- loop products --]
[-- product template --]
[-- end_loop products --]

[-- var.brand brand_chosen_type --]
<h1>BRAND - BRAND CHOSEN TYPE</h1>
[-- loop products --]
[-- product template --]
[-- end_loop products --]

[-- var.flavor flavor_chosen_type --]
<h1>FLAVOR - FLAVOR CHOSEN TYPE</h1>
[-- loop products --]
[-- product template --]
[-- end_loop products --]



Product Template:
[ IF VAR.product.field* --]
output the product using what ever formatting you need
[-- else --]
don't do anything
[-- end_IF--]




Please let me know if I am not being clear, thanks!
adam123
 
Posts: 7
Joined: Tue Nov 10, 2009 10:20 am
Location: New York


Return to User Forum

Who is online

Users browsing this forum: No registered users and 115 guests