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:

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:

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

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

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

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.

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 seanstorm100 » 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,
Sean


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm
Who is online

Users browsing this forum: No registered users and 4 guests