Post by raybark » Sun Mar 30, 2014 12:59 am

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.

New member

Posts

Joined
Tue Sep 03, 2013 9:23 pm

Post by malcj » Sun Aug 17, 2014 5:05 pm

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:

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');
}
replace this with:

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.

Newbie

Posts

Joined
Sun Aug 17, 2014 4:52 pm

Post by raybark » Mon Jan 19, 2015 10:03 pm

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

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');
}
Replace with

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');
}
Change the "5" to whatever minimum number you want.
Last edited by straightlight on Sat Mar 28, 2020 2:48 am, edited 1 time in total.
Reason: Replaced colors with code tags.

New member

Posts

Joined
Tue Sep 03, 2013 9:23 pm

Post by Krishna6024 » Fri Jun 03, 2016 11:01 pm

How can I display the stock quantity on a search results page.

$result['quantity'] is not working.

Newbie

Posts

Joined
Sat May 28, 2016 4:22 am

Post by nightwing » Sun Dec 29, 2019 11:53 pm

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


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by Bjornhjacobs » Sat Mar 28, 2020 1:47 am

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!

Newbie

Posts

Joined
Tue Jun 26, 2018 9:10 am

Post by straightlight » Sat Mar 28, 2020 2:49 am

Bjornhjacobs wrote:
Sat Mar 28, 2020 1:47 am
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!
Already indicated here:
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


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by nightwing » Mon Apr 06, 2020 5:39 am

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.
Bjornhjacobs wrote:
Sat Mar 28, 2020 1:47 am
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!

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm

Who is online

Users browsing this forum: No registered users and 5 guests