Dirty Butter Posted October 28, 2018 Share Posted October 28, 2018 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 More sharing options...
Mike Posted October 28, 2018 Share Posted October 28, 2018 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 More sharing options...
Dirty Butter Posted October 28, 2018 Author Share Posted October 28, 2018 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... Link to comment Share on other sites More sharing options...
Mike Posted October 28, 2018 Share Posted October 28, 2018 Lol.. They defo are not comments so I think that could be your issue. Good luck. Link to comment Share on other sites More sharing options...
bsmither Posted October 28, 2018 Share Posted October 28, 2018 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 More sharing options...
bsmither Posted October 28, 2018 Share Posted October 28, 2018 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} Link to comment Share on other sites More sharing options...
Dirty Butter Posted October 29, 2018 Author Share Posted October 29, 2018 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 More sharing options...
Mike Posted October 29, 2018 Share Posted October 29, 2018 Like bsmither said: You still have an extra {/IF} at the end. Link to comment Share on other sites More sharing options...
bsmither Posted October 29, 2018 Share Posted October 29, 2018 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 More sharing options...
Dirty Butter Posted October 29, 2018 Author Share Posted October 29, 2018 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. Link to comment Share on other sites More sharing options...
Dirty Butter Posted October 29, 2018 Author Share Posted October 29, 2018 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.