Jump to content

[Resolved] Need help with If/Else logic


Recommended Posts

We show all our product listings, whether they are in stock or not, because part of our purpose is as a ministry to help people FIND lovies. Leaving our sold items online gives people information about brand, description, etc. that is very useful to them. And we're setup to help them find what they need.

That means we need Google to provide our sold items in search results. (I DO leave them out of Google Adwords)

Google balks if there is not accurate pricing.

1. Regular Price wrongly shows Price twice https://dirtybutter.com/plushcatalog/walmart-brown-white-beagle-dog-holding-red-xoxo-heart.html

2. Sale Price with Regular Price showing as well WORKS https://dirtybutter.com/plushcatalog/carters-6990-white-polka-dot-blue-dog-with-green-ears-feet-no-sound.html

3. Sold, showing REGULAR price . Does not show the Sale price I would like to have showing  https://dirtybutter.com/plushcatalog/springs-global-pink-flat-head-rabbit-velour-blankie.html

I've attempted a series of if/else statements to make this work, but I've messed up the nesting logic in some way.

 {if ($CTRL_ALLOW_PURCHASE) && (!$CATALOGUE_MODE)}
	{if ($PRODUCT.ctrl_sale) && ($PRODUCT.stock_level != '0')}
		<td>Sale Price</td>
		<td>
		  <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
			<meta itemprop="priceCurrency" content="USD" />
			<meta itemprop="price" content="{$PRODUCT.price_to_pay}"{* Example: 10.99 *} />
			<span>{$PRODUCT.sale_price}</span>
		  </div>
		</td> 
	{else}
	<td>Regular Price</td>
	<td>
	  <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
		<meta itemprop="priceCurrency" content="USD" />
		<meta itemprop="price" content="{$PRODUCT.full_base_price}"{* Example: 14.99 *} />
		<span>{$PRODUCT.price}</span>
	  </div>
	</td> 
	{/if}
    </tr>
	{/if}
	{if ($PRODUCT.ctrl_sale) && ($PRODUCT.stock_level == '0')}
	<tr>
	<td>Sold for </td>
	<td>
	  <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
		<meta itemprop="priceCurrency" content="USD" />
		<meta itemprop="price" content="{$PRODUCT.price_to_pay}"{* Example: 10.99 *} />
		<span>{$PRODUCT.sale_price}</span>
	  </div>
	</td> 
	{else}
	<td>Regular Price</td>
	<td>
	  <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
		<meta itemprop="priceCurrency" content="USD" />
		<meta itemprop="price" content="{$PRODUCT.full_base_price}"{* Example: 14.99 *} />
		<span>{$PRODUCT.price}</span>
	  </div>
	</td>
{/if}

 

Link to comment
Share on other sites

Based on what I assume you are trying to do, I see some table tags and some {if} structure gone awray.

The first line {if} and the last line {/if} are OK.

Then, starting with the second line, the {if}, {else}, {/if} sections are OK.

But then you break the table row structure with:

	</tr>
	{/if}
	{if ($PRODUCT.ctrl_sale) && ($PRODUCT.stock_level == '0')}
	<tr>

I think simply:

    {if ($PRODUCT.ctrl_sale) && ($PRODUCT.stock_level == '0')}

to start an alternate pair of cells when out of stock, followed by a missing closing {/if} at the next to last line.

Also, considering the Regular Price is the same for both in and out of stock, it need not be tested.

But let's review the logic:

You want a price to show: Regular (and Sale if appr.)
You want one of two phrases to show: Regular or Sold (and Sale if appr.)

+ Stock: Regular (and Sale)
0 Stock: Sold (and Sale)

{if ($CTRL_ALLOW_PURCHASE) && (!$CATALOGUE_MODE)}

	{if ($PRODUCT.ctrl_sale)}
	<tr>{* Only show this row when item is on sale - regardless of stock *}
		<td>Sale Price</td>
		<td>
			<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
			<meta itemprop="priceCurrency" content="USD" />
			<meta itemprop="price" content="{$PRODUCT.price_to_pay}"{* Example: 10.99 *} />
			<span>{$PRODUCT.sale_price}</span>
			</div>
		</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>
			<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
			<meta itemprop="priceCurrency" content="USD" />
			<meta itemprop="price" content="{$PRODUCT.full_base_price}"{* Example: 14.99 *} />
			<span>{$PRODUCT.price}</span>
			</div>
		</td>
	</tr>
{/if}

 

Link to comment
Share on other sites

The over-all table structure isn't right.

In content.product.php:

                  <tr>
                     <td>{$LANG.catalogue.stock_level}</td>
                     <td>{$PRODUCT.stock_level}</td>
					<tr>
{if ($CTRL_ALLOW_PURCHASE) && (!$CATALOGUE_MODE)}

Change to:

                  <tr>
                     <td>{$LANG.catalogue.stock_level}</td>
                     <td>{$PRODUCT.stock_level}</td>
                  </tr>
{if ($CTRL_ALLOW_PURCHASE) && (!$CATALOGUE_MODE)}

 

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

×
×
  • Create New...