Page 1 of 1
How to add Stock Status to Category Page
Posted: Sun Oct 10, 2010 6:21 am
by jules_nz
Hi everyone
I had a bit of help from this forum, so thought I would give back
This is to add the product stock status to the category page in version 1.4.7
Open Catalog/Controller/Product/Category.php
Find
Code: Select all
if ($special) {
$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
}
}
And add after:
Code: Select all
$product_info = $this->model_catalog_product->getProduct($result['product_id']);
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = $product_info['stock'];
} else {
if ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = $this->language->get('text_instock');
}
}
Find code:
And add on the next line:
Open catalog/language/english/product/category.php
add to the list:
Open catalog/view/theme/{your custom theme}/product/category.tpl
And add the following code to wherever you want it displayed:
Code: Select all
<?php echo $products[$j]['stock']; ?>
I didn't want the model so I just over wrote the word "model" on line 50 with "stock"
Example of this on a live site is
http://www.dollworld.co.nz/shop
And after all that someone is going to tell me its actually a feature you can now turn on/off in admin - buy even if that is the case maybe this would help older versions as well??
As always use at your own will and always back up first
Re: How to add Stock Status to Category Page
Posted: Tue Oct 12, 2010 5:52 am
by opencartnovice
Hi jules_nz,
I've been following your instruction but it does not work. In store front it shows
Notice: Undefined index: stock in .../catalog/view/theme/default/template/product/category.tpl on line xx
where xx=
Code: Select all
<?php echo $products[$j]['stock']; ?>
when I removed ['stock'] it shown "Array"
I acctually want to show location field but I think if it works it can work with other fields.
Many thanks,
a very new of OC
Re: How to add Stock Status to Category Page
Posted: Tue Oct 12, 2010 7:22 am
by jules_nz
My apologies I missed a step!
You need to add the stock field to the array in the catalog/controller/product/category.php
Find code:
And add on the next line:
Re: How to add Stock Status to Category Page
Posted: Thu Oct 14, 2010 5:19 am
by opencartnovice
jules_nz wrote:My apologies I missed a step!
You need to add the stock field to the array in the catalog/controller/product/category.php
Find code:
And add on the next line:
It works perfectly.
Many thanks
Re: How to add Stock Status to Category Page
Posted: Sat Apr 16, 2011 3:47 am
by Digital Sushi
Sorry about resurrecting such an old topic!
I've followed the steps and everything seemed to be working fine, but now I've come across a few errors:
These products ARE in stock, but they show as "Supplier out of Stock"
http://www.digitalsushi.co.za/the-settlers-of-catan
http://www.digitalsushi.co.za/model-dis ... 5-21-26-cm
http://www.digitalsushi.co.za/machine-n ... -stand-006
These products are listed as Back Order You Copy Now, but are show as Supplier out of Stock:
http://www.digitalsushi.co.za/talisman- ... e-highland
Just as a few examples.
It seemed to work on OpenCart 1.4.9.3, but doesn't seem to like 1.4.9.4. Any ideas?
EDIT: Okay so it only displays incorrectly on the actual product page. It states the products is either "In Stock" or "Supplier Out of Stock". How can I get this to correctly replicate like the category, latest etc pages?
EDIT 2: This product I have the default status as "Supplier out of Stock", but on the front page it shows as "Ships in 2 - 3 Working Days."
Re: How to add Stock Status to Category Page
Posted: Sat Apr 16, 2011 6:53 am
by Digital Sushi
This is becoming stranger and stranger.
I just added a new product to the site. Both the Latest module and the product page are displaying the identical Stock Statues, which is "Back Order Your Copy Now".
http://www.digitalsushi.co.za/runebound
But a slightly older title, Talisman Expansion - The Highland, shows "Back Order Your Copy Now" on the Latest module, but Supplier Out of Stock on the product page.
http://www.digitalsushi.co.za/talisman- ... e-highland
What in the world is going on?
EDIT: I've found the problem! I recently modified my template so that the Related products show on the page under the description. Now, if any product has a Related item is screws up the stock status. How odd is that?
EDIT2: I restored it to its original Related code, but still any product with a related item messes up the system.
Re: How to add Stock Status to Category Page
Posted: Sat Apr 16, 2011 7:46 pm
by Digital Sushi
Alright so the problem comes in where products that have related items, it seems to take the stock status from them, which is just plain odd! Any fixes for this?
Re: How to add Stock Status to Category Page
Posted: Sun Apr 17, 2011 3:02 am
by jules_nz
I upgraded to 1.4.9.3 okay, but haven't attempted the 1.4.9.4 yet
But I want to keep my cart up-to-date, so i will attempt it either today or tomorrow, and will let you know how I get on
Re: How to add Stock Status to Category Page
Posted: Sun Apr 17, 2011 6:41 am
by Digital Sushi
Great, thanks! It's such an odd error, but I guess it has to do with 1.4.9.4?
Re: How to add Stock Status to Category Page
Posted: Thu Sep 15, 2011 8:23 pm
by mista
Thanks Jules, this works perfect. I use version 1.4.9.4 and didn't have any errors (I use a custom template).
Remember if you want to maintain the new view/layout throughout the site you'll have to update the special (Special offers) and search (Search result) related pages as well.
Files to edit (for special offers):
catalog/controller/product/special.php
catalog/language/{your installed languages}/product/special.php
catalog/view/theme/{your custom theme}/product/special.tpl
Also, the 'Out of stock' translation is taken from the backend (in: System->Localisation->Stock statuses) so check translations there.
If you want a label to show in front of the status you need to change the .tpl file as follows:
Find:
Code: Select all
$text_instock = $this->language->get('text_instock');
and add below:
Code: Select all
$text_availability = $this->language->get('text_availability');
The change step 4 from:
Code: Select all
<?php echo $products[$j]['stock']; ?>
to:
Code: Select all
<b><?php echo $text_availability; ?></b> <?php echo $products[$j]['stock']; ?><br />
Use at your own risk! Remember to backup first always when editing code!!!
Re: How to add Stock Status to Category Page
Posted: Wed Apr 10, 2013 2:23 am
by pstruh
how to get this works on 1.5.4 ?
Re: How to add Stock Status to Category Page
Posted: Fri Apr 26, 2013 10:52 am
by megahuman
I would also love to know how to get this to work in 1.5.5.1
Can somebody please assist?
Re: How to add Stock Status to Category Page
Posted: Fri Apr 26, 2013 11:31 am
by jules_nz
I only have 1.5.3 but I got it working fine with that version
You just might need to tweak it a bit as the codes and variables can change from version to version
Re: How to add Stock Status to Category Page
Posted: Fri Apr 26, 2013 11:50 am
by megahuman
I'm not too cluey with php... html and css is fine but php does my head in
If you could submit some code that might help that'd be awesome!
Re: How to add Stock Status to Category Page
Posted: Fri Apr 26, 2013 11:52 am
by megahuman
Might I add, I can get it to work, however on one full page of items, it seems to display either 'in stock' or 'out of stock' on every item, regardless of if the item actually has stock or not.
So it seems to just choose one item, then display that same stock status for all the other items on the page.
I'm sure it can't be too difficult, I just must be missing something -_-