Another "impulse buy" driver: I would like to have the available stock quantity be displayed, but only when its stock level reaches a low-point set for that product - "Only X Left!" for one product, while it might be "Only Y Left!" for another.
My thought being that if someone sees that there are only "so-many" left, they may be tempted to grab it quick.
My thought being that if someone sees that there are only "so-many" left, they may be tempted to grab it quick.
Hi. Just applied this solution myself. This fix will display "Only x left in stock" when the level is 5 or less. Otherwise, just says In Stock.
First, turn on stock level display on the admin panel (system/settings/edit your store/options) scroll down to Stock section and select Yes to display stock.
In your directory structure, go to catalog\controller\product. Use something like notepad to edit product.php. You to around line 282 and you should see this:
replace this with:
First, turn on stock level display on the admin panel (system/settings/edit your store/options) scroll down to Stock section and select Yes to display stock.
In your directory structure, go to catalog\controller\product. Use something like notepad to edit product.php. You to around line 282 and you should see this:
Code: Select all
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
$this->data['stock'] = $this->language->get('text_instock');
}
Code: Select all
if ($product_info['quantity'] <= 0) {
$this->data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display') && $product_info['quantity'] <= 5) {
$this->data['stock'] = 'Only ' . $product_info['quantity'] . ' left in stock';
} else {
$this->data['stock'] = $this->language->get('text_instock');
}
Last edited by straightlight on Sat Mar 28, 2020 2:47 am, edited 1 time in total.
Reason: Added code tags.
Reason: Added code tags.
This is a universal change only (i.e., not customizable for individual products), but for Opencart v2.0.x.x this works:
Starting at line 273 in /catalog/control/product/product.php:
Find
Replace with
Change the "5" to whatever minimum number you want.
Starting at line 273 in /catalog/control/product/product.php:
Find
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');
}
Code: Select all
if ($product_info['quantity'] <= 0) {
$data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display') && $product_info['quantity'] <= 5) {
$data['stock'] = 'Only ' . $product_info['quantity'] . ' left in stock';
} else {
$data['stock'] = $this->language->get('text_instock');
}
Last edited by straightlight on Sat Mar 28, 2020 2:48 am, edited 1 time in total.
Reason: Replaced colors with code tags.
Reason: Replaced colors with code tags.
How can I display the stock quantity on a search results page.
$result['quantity'] is not working.
$result['quantity'] is not working.
I tested the below on OC 3.0.3.2. Only if the stock goes to 10 and below. You can change that number if you want.
Code: Select all
// Only X Left In Stock Message
if ($product_info['quantity'] <= 0) {
$data['stock'] = $product_info['stock_status'];
} elseif ($this->config->get('config_stock_display') && $product_info['quantity'] <= 10) {
$data['stock'] = 'Only ' . $product_info['quantity'] . ' left in stock';
} else {
$data['stock'] = $this->language->get('text_instock');
}
Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing
Hi Sean,
I'm not a very advanced coder, could you please tell me where you added this code? Was it in product.php? Did you replace any section of the code or simply add it?
Thanks in advance!
I'm not a very advanced coder, could you please tell me where you added this code? Was it in product.php? Did you replace any section of the code or simply add it?
Thanks in advance!
Already indicated here:Bjornhjacobs wrote: ↑Sat Mar 28, 2020 1:47 amHi Sean,
I'm not a very advanced coder, could you please tell me where you added this code? Was it in product.php? Did you replace any section of the code or simply add it?
Thanks in advance!
Starting at line 273 in /catalog/controller/product/product.php:
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Hey Bjornhjacobs,
Just seeing this, I wasn't very active lately as there are a lot of things going on.
Straightlight replied above. If you are still having issues let us know.
Just seeing this, I wasn't very active lately as there are a lot of things going on.
Straightlight replied above. If you are still having issues let us know.
Bjornhjacobs wrote: ↑Sat Mar 28, 2020 1:47 amHi Sean,
I'm not a very advanced coder, could you please tell me where you added this code? Was it in product.php? Did you replace any section of the code or simply add it?
Thanks in advance!
Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing
Who is online
Users browsing this forum: No registered users and 5 guests