[How To] Replace price with "out of stock" if Qty = 0
17 posts
• Page 1 of 1
[How To] Replace price with "out of stock" if Qty = 0
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(
insert Below:
- Code: Select all
'quantity' => $result['quantity'],
now locate catalog/view/theme/default/template/product/category.tpl and find:
- 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 } ?>
Replace with:
- 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 } ?>
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:
- 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.
Last edited by SXGuy on Sat Aug 13, 2011 3:51 pm, edited 1 time in total.
- SXGuy
- Posts: 1568
- Joined: Sat Nov 07, 2009 6:07 pm
Re: [How To] Replace price with "out of stock" if Qty = 0
I think I've shared this too somewhere.. but good to have another point of reference for it

Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
-

Qphoria - Administrator
- Posts: 18210
- Joined: Mon Jul 21, 2008 7:02 pm

Re: [How To] Replace price with "out of stock" if Qty = 0
Hi
I know its an old post but can you clarify as to 'insert code', is that in place of, below or next to.
I know its an old post but can you clarify as to 'insert code', is that in place of, below or next to.

- xl5
- Posts: 54
- Joined: Mon Jul 18, 2011 7:45 am
Re: [How To] Replace price with "out of stock" if Qty = 0
Hi
how do you do this in v 1.5.1
i can't find section in category.tpl to replace?
how do you do this in v 1.5.1
i can't find section in category.tpl to replace?
Matthew
- MatthewB
- Posts: 304
- Joined: Fri Jul 22, 2011 9:18 pm
- Location: Sunderland Tyne and Wear
Re: [How To] Replace price with "out of stock" if Qty = 0
should work in 1.5.1 also.
And as far as i know, the code in category.tpl stayed the same between 1.5.0 and 1.5.1 so look a little deeper.
And as far as i know, the code in category.tpl stayed the same between 1.5.0 and 1.5.1 so look a little deeper.
- SXGuy
- Posts: 1568
- Joined: Sat Nov 07, 2009 6:07 pm
Re: [How To] Replace price with "out of stock" if Qty = 0
Is still can't seem to find the code in category.tpl
i've attached file
i've attached file
- Attachments
-
category.tpl- (7.76 KiB) Downloaded 57 times
Matthew
- MatthewB
- Posts: 304
- Joined: Fri Jul 22, 2011 9:18 pm
- Location: Sunderland Tyne and Wear
Re: [How To] Replace price with "out of stock" if Qty = 0
1.5.1
thats the code in 1.5.1 but i think the replacement made need a little tweeking.
Its late at the moment, so i cant think straigjt, gimmie 8 hours or so to have a sleep and ill reply with the modified code for you.
- Code: Select all
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
thats the code in 1.5.1 but i think the replacement made need a little tweeking.
Its late at the moment, so i cant think straigjt, gimmie 8 hours or so to have a sleep and ill reply with the modified code for you.
- SXGuy
- Posts: 1568
- Joined: Sat Nov 07, 2009 6:07 pm
Re: [How To] Replace price with "out of stock" if Qty = 0
I just released a module that disables the "Add to Cart" button, and replaces the button's default "Add to Cart" text with Out Of Stock, 2 - 3 Days, etc. i.e. whatever text you want to be shown, for products that have 0 (zero) quantity.
Take a look at here (just see the pictures, and you'll get the idea):
http://www.opencart.com/index.php?route ... on_id=4358
Take a look at here (just see the pictures, and you'll get the idea):
http://www.opencart.com/index.php?route ... on_id=4358
See all my extensions: http://www.opencart.com/index.php?route ... 20OpenCart
-

GoGo OpenCart - Posts: 445
- Joined: Mon Nov 14, 2011 3:30 pm
Re: [How To] Replace price with "out of stock" if Qty = 0
GoGo OpenCart wrote:I just released a module that disables the "Add to Cart" button, and replaces the button's default "Add to Cart" text with Out Of Stock, 2 - 3 Days, etc. i.e. whatever text you want to be shown, for products that have 0 (zero) quantity.
Take a look at here (just see the pictures, and you'll get the idea):
http://www.opencart.com/index.php?route ... on_id=4358
Does this look-up also includes the products already included in the cart and about to proceed to checkout but specific products that may no longer be in stock ?
Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1912
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: [How To] Replace price with "out of stock" if Qty = 0
What you are asking, is the following: If some product is already in the Cart, and if by any chance in the meantime becomes unavailable (got 0 stock), it should be popped-up from the Cart, and not allowed to be processed further on with the checkout, right? Is so, then no, it doesn't do that, it only disables the "Add to Cart" button everywhere within the site where the button is shown.
See all my extensions: http://www.opencart.com/index.php?route ... 20OpenCart
-

GoGo OpenCart - Posts: 445
- Joined: Mon Nov 14, 2011 3:30 pm
Re: [How To] Replace price with "out of stock" if Qty = 0
While your original idea is well thought regarding the add to cart event, a module added on the top should be integrated as well to state from the checkout/checkout route that one or more specific products could not be processed through checkout due to stock reasons or even multiple reasons that may or may not be implied. This event should even be added once the checkout button has been used and forwarded as first action from checkout/checkout page. 

Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1912
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: [How To] Replace price with "out of stock" if Qty = 0
Well, OpenCart already does that check 
Just put some product in your Shopping Cart, and then go to your Admin panel, and put 0 Quantity for that product you've already put in your Shopping Cart, then click on Checkout, and you'll get the following warning message: Products marked with *** are not available in the desired quantity or not in stock!
Although, it doesn't check at the final checkout step, i.e. when pressing the "Confirm Order" button, so it might be a bug.

Just put some product in your Shopping Cart, and then go to your Admin panel, and put 0 Quantity for that product you've already put in your Shopping Cart, then click on Checkout, and you'll get the following warning message: Products marked with *** are not available in the desired quantity or not in stock!

Although, it doesn't check at the final checkout step, i.e. when pressing the "Confirm Order" button, so it might be a bug.
See all my extensions: http://www.opencart.com/index.php?route ... 20OpenCart
-

GoGo OpenCart - Posts: 445
- Joined: Mon Nov 14, 2011 3:30 pm
Re: [How To] Replace price with "out of stock" if Qty = 0
It may already check the product quantity but it does not check per item the stock status ID of each stores which shipping specifically depends on and reliable on geo zones. See, the stock status ID doesn't really have to depend on the quantity but also based on the zones. 

Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1912
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: [How To] Replace price with "out of stock" if Qty = 0
Please can someone sticky this as it is a great method.
Thanks
Thanks
- zishan
- Posts: 43
- Joined: Tue Jan 10, 2012 9:40 pm
Re: [How To] Replace price with "out of stock" if Qty = 0
Hi,
It's a long time ago but I was searching for the same thing: change price to 'out of stock' when the products status = o.
Couldn't find any mods and tried the code above but it didn't work for me in OS 1.5.5.1. I've modified the code but it still doesn't work.
Of course I will keep on trying but I've been working on my site almost 18 hours a day the last 7 weeks to figure things out myself (and most of the issues I've solved myself by reading the forum) but I'm getting tired now!
So now I'm thinking: waarom het wiel opnieuw uitvinden! (as we in the Netherlands say)
Explanation: why spend a lot of time to figure out something that another one has already figured out! So....
Who can and will help me?
Probably it's a small thing I'm forgetting to change. Does anybody know? How to change the code above to make this work in OS 1.5.5.1?
Hope for a lot of responces ;-)
Thanx already,
With regards
Angelique.
It's a long time ago but I was searching for the same thing: change price to 'out of stock' when the products status = o.
Couldn't find any mods and tried the code above but it didn't work for me in OS 1.5.5.1. I've modified the code but it still doesn't work.
Of course I will keep on trying but I've been working on my site almost 18 hours a day the last 7 weeks to figure things out myself (and most of the issues I've solved myself by reading the forum) but I'm getting tired now!
So now I'm thinking: waarom het wiel opnieuw uitvinden! (as we in the Netherlands say)
Explanation: why spend a lot of time to figure out something that another one has already figured out! So....
Who can and will help me?
Probably it's a small thing I'm forgetting to change. Does anybody know? How to change the code above to make this work in OS 1.5.5.1?
Hope for a lot of responces ;-)
Thanx already,
With regards
Angelique.
- tresj
- Posts: 6
- Joined: Fri Jan 25, 2013 12:49 am
17 posts
• Page 1 of 1
Who is online
Users browsing this forum: Bing [Bot], NoJoke and 9 guests













