Post by stein » Wed Sep 09, 2009 11:25 pm

Hello everyone,

First of all congratulations for OpenCart, it is awesome! I am new to it since a couple weeks, and today I posted an article on my blog on how to modify OpenCart 1.3.2 to display stock of items in the storefront, as either numbers or coloured icons. I would repost a copy here, but it is far too long and there are some images included.

For those interested, you can find it here:
OpenCart: display stock levels in storefront, as numbers or colour icons, next to the price.

Examples of how products look like:

Image

Image

Again I repeat its my first contribution ever to OpenCart and the code might not be optimised enough, but I found that at least it does its job well. So if someone can give tips on optimising the code, it will be very appreciated and I will learn new things -> feedback appreciated!

Thanks for your interest and keep up the good work :)

Newbie

Posts

Joined
Wed Sep 09, 2009 11:12 pm

Post by madany » Thu Sep 10, 2009 12:10 pm

GOOD!!! :)

New member

Posts

Joined
Mon Aug 31, 2009 2:03 pm

Post by nzjolly » Tue Sep 22, 2009 5:45 am

does anyone know or have made this work in the latest version of open cart? says tested with 132 but i cannot find half the files hes talking about?

New member

Posts

Joined
Tue Sep 01, 2009 6:52 am

Post by dbstr » Tue Sep 22, 2009 7:28 am

Probably because he writes "catalog/view/common/home.php" while it should be "catalog/view/common/home.tpl"?

I did it myself, but nok like this guide. I made it in the controllers, and is just passing a color variable to the template files. But my site is also a major design/code rewrite. ;-)

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by nzjolly » Tue Sep 22, 2009 7:56 am

does anyone have a modified guide or some other easy way to change the stock levels to green yellow and red... instead of a number?

New member

Posts

Joined
Tue Sep 01, 2009 6:52 am

Post by nzjolly » Tue Sep 22, 2009 9:53 am

Well i can now make it kind of work.
if ($product_info['quantity'] <= 0) {
if ($product_info['stock_status_id'] == '7'){
$this->data['stock'] = '<img src="catalog/view/theme/default/image/stock_red.gif">'; // Product discontinued, show red.
} elseif ($product_info['stock_status_id'] == '6') {
$this->data['stock'] = '<img src="catalog/view/theme/default/image/stock_yellow.gif">'; // Product temporarily out of stock, show yellow.
}
} else {
if ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = '<img src="catalog/view/theme/default/image/stock_green.gif">'; // Product in stock, show green.
}
}
if i change the code as is said, and update the images, and set the product to "2 /3 days" and the stock level to ZERO then it will show yellow. however in stock doesn't work and nor does out of stock.

have the stock ID codes changed?

ie 7 and 6?

New member

Posts

Joined
Tue Sep 01, 2009 6:52 am

Post by dbstr » Tue Sep 22, 2009 10:17 am

Yeah, most likely.. Check your database. Can't remember if you can see the id's in admin, try editing the statuses and check the URL.

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by nzjolly » Tue Sep 22, 2009 10:35 am

if ($product_info['quantity'] <= 0) {
if ($product_info['stock_status_id'] == '5'){
$this->data['stock'] = '<img src="catalog/view/theme/default/image/stock_red.gif">'; // Product discontinued, show red.
} elseif ($product_info['stock_status_id'] == '6') {
$this->data['stock'] = '<img src="catalog/view/theme/default/image/stock_yellow.gif">'; // Product temporarily out of stock, show yellow.
}
} else {
if ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = '<img src="catalog/view/theme/default/image/stock_green.gif">'; // Product in stock, show green.
}
}
okay changed to the above, now have no stock red, and 2/3 yellow, but in stock nothing... naadaa no green... arghhhhhhh i hope someone can see the reason why and post up

New member

Posts

Joined
Tue Sep 01, 2009 6:52 am

Post by dbstr » Tue Sep 22, 2009 10:41 am

Online from my phone, hard to see it all, but try deleting

Code: Select all

} else { 
if ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by nzjolly » Tue Sep 22, 2009 10:58 am

yep tried that, but just an error then occurs,

T_ELSE, expecting T_Function

New member

Posts

Joined
Tue Sep 01, 2009 6:52 am

Post by dbstr » Tue Sep 22, 2009 11:07 am

Yeah I just read the 'guide', don't delete that.. I'm afraid I can't help you right now. What does it say when it's supposed to be green? And what if you view the source code?

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by nzjolly » Tue Sep 22, 2009 11:11 am

got it working !!!! yay...
if ($product_info['stock_status_id'] == '5'){
$this->data['stock'] = '<img src="catalog/view/theme/default/image/stock_red.gif">'; // Product discontinued, show red.
} elseif ($product_info['stock_status_id'] == '6') {
$this->data['stock'] = '<img src="catalog/view/theme/default/image/stock_yellow.gif">'; // Product temporarily out of stock, show yellow.
}
} else {
if ($product_info['stock_status_id'] == '7'){
$this->data['stock'] = '<img src="catalog/view/theme/default/image/stock_green.gif">'; // Product in stock, show green.
}
}

New member

Posts

Joined
Tue Sep 01, 2009 6:52 am
Who is online

Users browsing this forum: No registered users and 9 guests