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?
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>
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');
}
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.
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 informationQuino wrote: ↑Sun Mar 08, 2020 11:55 pmCode: 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'); }

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
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.
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');
}
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.
Code: Select all
$data['stock'] = $product_info['stock_status'];
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.
Users browsing this forum: No registered users and 8 guests