Page 1 of 1
[Solved] How Do I add text if price or quantity is 0?
Posted: Sat Nov 26, 2011 10:33 am
by Cyberwoolf
I'm changing a shop over from prestashop and I'm trying to add text if the product is quantity is 0 (sold out) and different text if it's more than 0 (Available). . Like my last post, I've done a search and found a couple topics, but none of the methods work for 1.5.1.3 and I can't figure it out.
I've tried various methods including quantity set to 0 and price to 0.
I was trying something like this in category.tpl:
Code: Select all
<?php if (!$product['special'] && == '0.00') { ?>
<?php echo ='SOLD OUT'; ?>
<?php } else { ?>
I've been going nuts trying to figure out these 2 problems (other post).

Re: How Do I add text if price or quantity is 0?
Posted: Sat Nov 26, 2011 11:40 pm
by uksitebuilder
The first thing you need to do is get the quantity variable and pass the correct text to the template
edit: catalog/controller/product/category.php
find
Code: Select all
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
add after
Code: Select all
'availability' => ($result['quantity']>0?$this->language->get('text_available'):$this->language->get('text_soldout')),
Now you have the availability you can use it in the template file
edit: catalog/view/theme/default/template/product/category.tpl
find
Code: Select all
</div>
<?php } ?>
<?php if ($product['rating']) { ?>
add before
Code: Select all
<?php echo $product['availability']; ?>
and finally create a couple of language defines for 'Available' and 'Sold Out'
edit: catalog/language/english/product/category.php
find
Code: Select all
$_['text_points'] = 'Reward Points:';
add after
Code: Select all
$_['text_available'] = ' (<span style="color:green">Available</span>)';
$_['text_soldout'] = ' (<span style="color:red">Sold Out</span>)';
You will most likely want to do similar for search results page, manufacturers_info page and possibly the product page itself.
Re: How Do I add text if price or quantity is 0?
Posted: Sun Nov 27, 2011 12:43 am
by Cyberwoolf
Thank you very much

.. I get:
Notice: Undefined variable: availability in catalog/view/theme/default/template/product/category.tpl
Re: How Do I add text if price or quantity is 0?
Posted: Sun Nov 27, 2011 2:21 am
by uksitebuilder
apologies the 2nd edit was incorrect
change $availability to $product['availability']
code above edited
Re: How Do I add text if price or quantity is 0?
Posted: Sun Nov 27, 2011 2:36 am
by Cyberwoolf
Thank you! That worked. I'll make a vQmod of that too.
I also had to add this (I made it a div) where I wanted it to go so it would show up:
Code: Select all
html += '<div class="avail">' + $(element).find('.avail').html() + '</div>';
Thanks for letting me know how the system works too. It will help with other modifications :-)