Post by Dutch Pride Code » Sun Mar 08, 2020 10:31 pm

OC 3.0.3.2
PHP 7.2.10
Default theme


Is it possible to make the front-end stock quantity display colors on a certain quantity, just like it's done in the admin panel products list? I have found a few free extensions that do this but they are for older versions like OC version 2.x or 1.x even.

If this is not possible easily, where do I find the front-end stock quantity CSS?
Last edited by Dutch Pride Code on Mon Mar 09, 2020 5:40 am, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by Quino » Sun Mar 08, 2020 11:55 pm

I don't think there is a css class for that.

In the product controller you have:

Code: Select all

			if ($product_info['quantity'] <= 0) {
				$data['stock'] = $product_info['stock_status'];
			} elseif ($this->config->get('config_stock_display')) {
				$data['stock'] = $product_info['quantity'];
			} else {
				$data['stock'] = $this->language->get('text_instock');
			}

which basically means:
if you are out of stock, show the "out of stock" message as defined in admin
otherwise, if you have enabled "display stock" in admin, show the quantity
otherwise, just show the "in stock" message from the language file.

in the view it simply states:

Code: Select all

<li>{{ text_stock }} {{ stock }}</li>
no css there.

you can do it in the controller like:

Code: Select all

			if ($product_info['quantity'] <= 0) {
				$data['stock'] = $product_info['stock_status'];
			} elseif ($this->config->get('config_stock_display')) {
				if ($product_info['quantity'] > 5) $data['stock'] = '<span class="text-green">'.$product_info['quantity'].'</span>';
				if ($product_info['quantity'] <= 5) $data['stock'] = '<span class="text-orange">'.$product_info['quantity'].'</span>';
				if ($product_info['quantity'] == 1) $data['stock'] = '<span class="text-red">'.$product_info['quantity'].'</span>';
			} else {
				$data['stock'] = $this->language->get('text_instock');
			}
and then define a class in your css or do it inline with style="".

You can also do it in the view but since the variable stock can be a number or a string there makes the logic more obscure.

New member

Posts

Joined
Fri Feb 28, 2020 1:19 am

Post by sw!tch » Mon Mar 09, 2020 2:57 am

Do you want to show only QTY numbers? Will you ever be using the out of stock statues on the front (e.g Out of Stock, Pre-Order, etc) ?

Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by Dutch Pride Code » Mon Mar 09, 2020 5:39 am

Quino wrote:
Sun Mar 08, 2020 11:55 pm

Code: Select all

			if ($product_info['quantity'] <= 0) {
				$data['stock'] = $product_info['stock_status'];
			} elseif ($this->config->get('config_stock_display')) {
				if ($product_info['quantity'] > 5) $data['stock'] = '<span class="text-green">'.$product_info['quantity'].'</span>';
				if ($product_info['quantity'] <= 5) $data['stock'] = '<span class="text-orange">'.$product_info['quantity'].'</span>';
				if ($product_info['quantity'] == 1) $data['stock'] = '<span class="text-red">'.$product_info['quantity'].'</span>';
			} else {
				$data['stock'] = $this->language->get('text_instock');
			}
Used this piece of code, but with the inline style="color:___" and this is exactly what I needed. This is perfect! Thanks a lot for this helpful information O0

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by Prohibition » Tue May 26, 2020 2:05 pm

Hi
sorry I am new to all of this and the covid situation has forced most of us in South Africa to go online as this is the only legal way to trade at this moment.
May I please ask to explain or tell me where and how to do the inline style="" bit of code thats needed to finish up the change of color. I have changed the other code in my products.php file and tried to google the inline style command, but nothing makes sense.
Thanks

Newbie

Posts

Joined
Tue May 26, 2020 1:57 pm

Post by letxobnav » Tue May 26, 2020 3:27 pm

In the above code you can just replace:

class="text-green" with style="color:green"
class="text-orange" with style="color:orange"
class="text-red" with style="color:red"

or use any colors you like.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Prohibition » Tue May 26, 2020 4:17 pm

Thanks Letxobnav
I did it and cleared cookies etc to refresh my page. it still shows the same original text colour
This is my code now

Code: Select all

if ($product_info['quantity'] <= 0) {
				$data['stock'] = $product_info['stock_status'];
			} elseif ($this->config->get('config_stock_display')) {
				if ($product_info['quantity'] > 5) $data['stock'] = '<span style="color:green">'.$product_info['quantity'].'</span>';
				if ($product_info['quantity'] <= 5) $data['stock'] = '<span style="color:orange">'.$product_info['quantity'].'</span>';
				if ($product_info['quantity'] == 1) $data['stock'] = '<span style="color:red">'.$product_info['quantity'].'</span>';
			} else {
				$data['stock'] = $this->language->get('text_instock');
			}
What could be wrong?

Newbie

Posts

Joined
Tue May 26, 2020 1:57 pm

Post by sw!tch » Tue May 26, 2020 4:29 pm

Clear your theme/SASS cache and refresh your modifications.

Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by Prohibition » Wed May 27, 2020 1:13 am

Nope still in the standard grey, cleared the twig and SASS cahe several times as well as my browser cache

Newbie

Posts

Joined
Tue May 26, 2020 1:57 pm

Post by sw!tch » Wed May 27, 2020 3:07 am

Link to your site?

Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Newbie

Posts

Joined
Tue May 26, 2020 1:57 pm

Post by letxobnav » Wed May 27, 2020 10:30 am


Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Prohibition » Thu May 28, 2020 1:57 am

Thank you. I want the actual text öut of stock to be displayed as red

Newbie

Posts

Joined
Tue May 26, 2020 1:57 pm

Post by letxobnav » Thu May 28, 2020 10:52 pm

then change

Code: Select all

$data['stock'] = $product_info['stock_status'];
to

Code: Select all

$data['stock'] = '<span style="color:red">'.$product_info['stock_status'].'</span>';

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Prohibition » Fri May 29, 2020 1:43 pm

Thank you letxobnav
It is working perfectly
youre the man.

Newbie

Posts

Joined
Tue May 26, 2020 1:57 pm
Who is online

Users browsing this forum: No registered users and 9 guests