[How To] Replace price with "out of stock" if Qty = 0
Posted: Tue Nov 10, 2009 12:04 am
This is something ive just written for a client and thought id share it with you.
Its a simple mod, but just in case you need it, then here it is.
This mod will replace the price of an item with the words "Out of stock" if the quanity of the product is 0.
You can adapt it so it includes the price as well as the status if you wish, however as that wasnt needed for me, ill just list what i did to achieve what i needed.
First we need to be able to add the stock quanity into the array that is generated for the product pages under the categories.
locate catalog/controller/product/category.php and find:
insert Below:
now locate catalog/view/theme/default/template/product/category.tpl and find:
Replace with:
Optional
If you wish to keep the price of the product and also list whether it is out of stock then replace with this instead:
Hope this helps some of you guys,
Remember, you can also add this technique to any module, all you need to do, is repeat the same process but instead of editing the files listed under the product folders, just edit the files under "module" instead.
I.E catalog/controller/module/bestseller.php and catalog/view/theme/default/template/module/bestseller.tpl
Ive included this mod for use with the slideshow module also.
Its a simple mod, but just in case you need it, then here it is.
This mod will replace the price of an item with the words "Out of stock" if the quanity of the product is 0.
You can adapt it so it includes the price as well as the status if you wish, however as that wasnt needed for me, ill just list what i did to achieve what i needed.
First we need to be able to add the stock quanity into the array that is generated for the product pages under the categories.
locate catalog/controller/product/category.php and find:
Code: Select all
$this->data['products'][] = array(
Code: Select all
'quantity' => $result['quantity'],
Code: Select all
<?php if (!$products[$j]['special']) { ?>
<span style="color: #900; font-weight: bold;"><?php echo $products[$j]['price']; ?></span><br />
<?php } else { ?>
<span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
<?php } ?>
Code: Select all
<?php if (!$products[$j]['special']) { ?>
<span style="color: #900; font-weight: bold;">
<?php if ($products[$j]['quantity'] <= 0) {
echo 'Out of Stock';
} else {
echo $products[$j]['price'];
} ?></span><br />
<?php } else { ?>
<span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php if ($products[$j]['quantity'] <= 0) {
echo 'Out of Stock';
} else {
echo $products[$j]['price'];
} ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
<?php } ?>
If you wish to keep the price of the product and also list whether it is out of stock then replace with this instead:
Code: Select all
<?php if (!$products[$j]['special']) { ?>
<span style="color: #900; font-weight: bold;">
<?php if ($products[$j]['quantity'] <= 0) {
echo 'Out of Stock';
} ?></span><br />
<?php echo $products[$j]['price']; ?></span><br />
<?php } else { ?>
<span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php if ($products[$j]['quantity'] <= 0) {
echo 'Out of Stock';
} ?></span><br />
<?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
<?php } ?>
Hope this helps some of you guys,
Remember, you can also add this technique to any module, all you need to do, is repeat the same process but instead of editing the files listed under the product folders, just edit the files under "module" instead.
I.E catalog/controller/module/bestseller.php and catalog/view/theme/default/template/module/bestseller.tpl
Ive included this mod for use with the slideshow module also.