Jump to content

Need Help Nesting {if} {else}


Dirty Butter

Recommended Posts

I'm pretty sure Bsmither helped me with this some time ago, but I could't find it.

I need four scenarios to work within one section of code in the Specifications:

Regular price in stock shows Regular Price

Regular price out of stock says Sold for Regular Price

Sale item in stock has Regular Price row and Sale Price row below

Sale item out of stock shows Sold for Sale Price

If I can get that logic coded correctly, I want to then get the meta data added to each one, but I have to get the logic worked out first.

I've worked on this solid for almost two days and never found the right combination. (I have a stray brace comment in here somewhere - I'll find that if I get the main part fixed.)

I currently have:

{* PLUSH ORDER OF PRICES *}
                  <tr>
                     <td>{$LANG.catalogue.stock_level}</td>
                     <td>{$PRODUCT.stock_level}</td>
                  </tr>
		  {if ($PRODUCT.ctrl_sale)}
		   <tr>{* Only show this row when item is on sale - regardless of stock *}
		  <td>Sale Price</td>
		  <td><span>{$PRODUCT.sale_price}</span></td> 
		  </tr>
                  {/if} 
		  <tr>{* Always show this row *}
		  {if ($PRODUCT.stock_level gt 0)}{* In stock *}
	  	  <td>Regular Price</td>
		  {else}{* Not in stock *}
		  <td>Sold for </td>
		  {/if}
		  <td><span>{$PRODUCT.price}</span></td>
		  </tr>
		  {/if}
{* END PLUSH ORDER OF PRICES *}

Here are the pages I've been using to check my code:

dirtybutter.com/plushcatalog/eden-yellow-pink-elephant-windup-you-are-my-sunshine-head-turns.html  (This is the one that is messed up.)

dirtybutter.com/plushcatalog/bearington-baby-little-stitches-196659-pnut-gray-elephant.html (order of Sale and Regular Price rows looks odd but I could live with that)

dirtybutter.com/plushcatalog/commonwealth-toy-pink-love-monster-cat-with-hearts.html

dirtybutter.com/plushcatalog/carters-halloween-orange-pumpkin-tan-velour-bear-with-cap.html

Any and All help is MUCH appreciated!!

 

Link to comment
Share on other sites

I'm now expert on this coding but the only looks out of place to me is 

56 minutes ago, Dirty Butter said:

{if ($PRODUCT.stock_level gt 0)}{* In stock *}

and

56 minutes ago, Dirty Butter said:

{else}{* Not in stock *}

as is doesn't specify what is being done with the *In stock* section or the *Not in stock*.

I would think it would be using the * as a multiplier?

This is a total guess just trying to help out. 

Link to comment
Share on other sites

You may have one too many {/if} statements.

Check to see if the very last {/if} has a matching {if} somewhere above what was posted.

You may want to pivot your logic.

First determine if the item is in stock.

Then determine if it is on sale.

 

Link to comment
Share on other sites

I've gone around in circles again :(

{* NEW NESTING *}

                  <tr>
                     <td>{$LANG.catalogue.stock_level}</td>
                     <td>{$PRODUCT.stock_level}</td>
                  </tr>


			  {if ($PRODUCT.stock_level gt 0)}{* IF IN STOCK - PRICE *}
				<tr>
					<td>Regular Price</td>
					<td><span>{$PRODUCT.price}</span></td> 
				</tr>
		 
				
							{if ($PRODUCT.ctrl_sale)} {* IF ON SALE - SALE PRICE *}
								<tr>
									<td>Sale Price</td>
									<td><span>{$PRODUCT.sale_price}</span></td>
								</tr>
							{/if}

			   {else ($product['stock_level'] = 0) {* IF OUT OF STOCK  EITHER  ON SALE OR REGULAR PRICE *}
									<tr>
										<td>Sold for
										{if ($PRODUCT.ctrl_sale)} 	{* IF ON SALE - SALE PRICE *}	
										<td><span>{$PRODUCT.sale_price}</span></td>
									{else}	
										<tr>
											<td>Regular Price</td> {* SOLD FOR REGULAR PRICE *}
											<td><span>{$PRODUCT.price}</span></td> 
										</tr>
								     {/if}
			     {/if}

{/if}



{* END OF NEW NESTING *}

 

Hopefully it's just that I didn't know the right way to show when it is Out of Stock, not the nesting itself.

Exception] /plushtest/includes/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php:128 - Syntax error in template "file:/plushtest/skins/blue/templates/content.product.php" on line 128 "{else ($product['stock_level'] = 0) {* IF OUT OF STOCK EITHER ON SALE OR REGULAR PRICE *}" - Unexpected " = ", expected one of: "","" , ")"

Link to comment
Share on other sites

Please check this:

{else ($product['stock_level'] = 0) {* IF OUT OF STOCK  EITHER  ON SALE OR REGULAR PRICE *}

The correct syntax to use is:

{elseif $product['stock_level'] eq 0}{* IF OUT OF STOCK  EITHER  ON SALE OR REGULAR PRICE *}

However, just use {else} because the {if} determined the product has stock. Otherwise it doesn't - no need to test for it.

Also, edit:

<td>Sold for

by having the closing tag </td>.

Please study this:

{* NEW NESTING *}
<tr>
   <td>{$LANG.catalogue.stock_level}</td>
   <td>{$PRODUCT.stock_level}</td>
</tr>
{if $PRODUCT.stock_level gt 0}{* IF IN STOCK - PRICE *}
<tr>
   <td>Regular Price</td>
   <td><span>{$PRODUCT.price}</span></td>
</tr>
  {if $PRODUCT.ctrl_sale}{* IF ON SALE - SALE PRICE *}
<tr>
   <td>Sale Price</td>
   <td><span>{$PRODUCT.sale_price}</span></td>
</tr>
  {/if}
{else}{* IF OUT OF STOCK  EITHER  ON SALE OR REGULAR PRICE *}
<tr>
   <td>Sold for</td>
  {if ($PRODUCT.ctrl_sale)}{* IF ON SALE - SOLD FOR SALE PRICE *}
   <td><span>{$PRODUCT.sale_price}</span></td>
  {else}{* ELSE SOLD FOR REGULAR PRICE *}
   <td><span>{$PRODUCT.price}</span></td>
  {/if}
</tr>
{/if}

{/if}
{* END OF NEW NESTING *}

Again, the very last {/if} is suspicious. Please make sure it has a matching {if} statement.

Link to comment
Share on other sites

YES! The closed if was needed from somewhere else. I ended up putting it as the last line in the file, based on the error message. I was wrongly assuming it was part of the nesting issue. Anyway, that is fixed.

It now works for all four situations. I'll do some more studying to be sure I understand what you did, Bsmither! Thank you as always. Hopefully I can now put the meta data in and please Google!

I was pleasantly surprised that I did not have to do anything else to the code to get the metadata included. Once the nesting was correct, the Google Structured Data Test Tool showed no errors!

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...