Page 1 of 1

[How To] Replace price with "out of stock" if Qty = 0

Posted: Tue Nov 10, 2009 12:04 am
by SXGuy
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:

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.

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Tue Nov 10, 2009 3:10 am
by Qphoria
I think I've shared this too somewhere.. but good to have another point of reference for it

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Aug 13, 2011 10:26 pm
by xl5
Hi
I know its an old post but can you clarify as to 'insert code', is that in place of, below or next to. :-\

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Aug 13, 2011 11:50 pm
by SXGuy
Below.

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Fri Aug 19, 2011 9:19 pm
by MatthewB
Hi

how do you do this in v 1.5.1

i can't find section in category.tpl to replace?

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Aug 20, 2011 12:37 am
by SXGuy
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.

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Aug 20, 2011 1:13 am
by MatthewB
Is still can't seem to find the code in category.tpl

i've attached file

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Aug 20, 2011 6:41 am
by SXGuy
1.5.1

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.

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Thu Aug 25, 2011 10:57 pm
by MatthewB
any luck with this code?

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Tue Dec 20, 2011 9:44 pm
by GoGo OpenCart
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

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Dec 24, 2011 3:03 am
by straightlight
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 ?

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Dec 24, 2011 3:15 am
by GoGo OpenCart
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.

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Dec 24, 2011 3:20 am
by straightlight
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. ;)

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Dec 24, 2011 3:49 am
by GoGo OpenCart
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.

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Dec 24, 2011 4:54 am
by straightlight
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. ;)

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sun Apr 22, 2012 5:00 am
by zishan
Please can someone sticky this as it is a great method.

Thanks

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Mar 16, 2013 10:12 am
by tresj
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.

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Thu Sep 26, 2013 11:37 am
by alibroon
I am also looking for this. We really want the cart to function as a catalogue so we have already disabled the Add to Cart functions. So to be able to change the price to Sold would be ideal for us. Did you get any further with a solution for 1.5.5.1

Re: [How To] Replace price with "out of stock" if Qty = 0

Posted: Sat Jul 28, 2018 9:43 am
by sheridangraphics
Hi All,

I bought a plugin a while back which replaces 00.00 with pick options. All my 0 priced options required the customer to select specific options to calculate the overall price. The problem I have is in checkout I dont want it to say pick options in tax, delivery or other areas where 00.00 may come up. how can i get passed this issue?