Post by jules_nz » Sun Oct 10, 2010 6:21 am

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:

Code: Select all

'special' => $special,
And add on the next line:

Code: Select all

'stock' => $this->data['stock'],
Open catalog/language/english/product/category.php
add to the list:

Code: Select all

$_['text_instock']      = 'In Stock'; 
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
Last edited by jules_nz on Thu Oct 14, 2010 5:29 am, edited 1 time in total.

Active Member

Posts

Joined
Tue Aug 11, 2009 12:58 pm

Post by opencartnovice » Tue Oct 12, 2010 5:52 am

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

New member

Posts

Joined
Thu Oct 07, 2010 5:12 am

Post by jules_nz » Tue Oct 12, 2010 7:22 am

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:

Code: Select all

'special' => $special,
And add on the next line:

Code: Select all

'stock' => $this->data['stock'],

Active Member

Posts

Joined
Tue Aug 11, 2009 12:58 pm

Post by opencartnovice » Thu Oct 14, 2010 5:19 am

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:

Code: Select all

'special' => $special,
And add on the next line:

Code: Select all

'stock' => $this->data['stock'],
It works perfectly.
Many thanks

New member

Posts

Joined
Thu Oct 07, 2010 5:12 am

Post by Digital Sushi » Sat Apr 16, 2011 3:47 am

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."

Active Member

Posts

Joined
Mon Oct 18, 2010 10:23 pm
Location - South Africa

Post by Digital Sushi » Sat Apr 16, 2011 6:53 am

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.

Active Member

Posts

Joined
Mon Oct 18, 2010 10:23 pm
Location - South Africa

Post by Digital Sushi » Sat Apr 16, 2011 7:46 pm

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?

Active Member

Posts

Joined
Mon Oct 18, 2010 10:23 pm
Location - South Africa

Post by jules_nz » Sun Apr 17, 2011 3:02 am

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

Active Member

Posts

Joined
Tue Aug 11, 2009 12:58 pm

Post by Digital Sushi » Sun Apr 17, 2011 6:41 am

Great, thanks! It's such an odd error, but I guess it has to do with 1.4.9.4?

Active Member

Posts

Joined
Mon Oct 18, 2010 10:23 pm
Location - South Africa

Post by mista » Thu Sep 15, 2011 8:23 pm

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!!!

OpenCart version 1.4.9.4


Newbie

Posts

Joined
Tue Mar 29, 2011 5:50 pm

Post by pstruh » Wed Apr 10, 2013 2:23 am

how to get this works on 1.5.4 ?

Newbie

Posts

Joined
Sun Apr 07, 2013 6:44 pm

Post by megahuman » Fri Apr 26, 2013 10:52 am

I would also love to know how to get this to work in 1.5.5.1

Can somebody please assist?

Web Design and Development at 7 Design


Active Member

Posts

Joined
Tue Dec 14, 2010 4:57 pm

Post by jules_nz » Fri Apr 26, 2013 11:31 am

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

Active Member

Posts

Joined
Tue Aug 11, 2009 12:58 pm

Post by megahuman » Fri Apr 26, 2013 11:50 am

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!

Web Design and Development at 7 Design


Active Member

Posts

Joined
Tue Dec 14, 2010 4:57 pm

Post by megahuman » Fri Apr 26, 2013 11:52 am

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 -_-

Web Design and Development at 7 Design


Active Member

Posts

Joined
Tue Dec 14, 2010 4:57 pm
Who is online

Users browsing this forum: No registered users and 17 guests