Jump to content
Sign in to follow this  
Dirty Butter

Need Help Nesting {if} {else}

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!!

 

Edited by Dirty Butter

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

I've experimented with so many permutations since yesterday that I wouldn't even hazard a guess as to what's going on in it.

Thanks for your input! Those are supposed to be comments? But who knows...

Share this post


Link to post
Share on other sites

Lol..

They defo are not comments so I think that could be your issue.

Good luck.

Share this post


Link to post
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.

 

Share this post


Link to post
Share on other sites

Here is a logic flow from my comment above:

{if in stock}
  Price
  {if on sale}Sale Price{/if}
{else out of stock}
  Sold for{if on sale}Sale Price{else}Price{/if}
{/if} 

 

Edited by bsmither

Share this post


Link to post
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: "","" , ")"

Edited by Dirty Butter

Share this post


Link to post
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.

Edited by bsmither

Share this post


Link to post
Share on other sites

AH - the gt 0 in the stock level "means greater than zero" and eq 0 means "equal to 0".

Just got back home. Will work on the rest of your changes as soon as I can.

Share this post


Link to post
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!

 

Edited by Dirty Butter

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...