Question

Dear stackoverflow code experts. I have a query relating to opencart stock.

The frontend product page has option of displaying Stock, either in terms of availability (Available or Out of Stock) or in terms of quantity in actual numbers.

Is it possible to display it in some other way? eg. I want that if the stock quantity is less than or equal to 5, then it should display quantity, else display the text: Available.

Or in a more sophisticated manner, if product quantity is greater than 5 or zero, then display text, else display quantity in number.

I understand it may have to do something with ../catalog/controller/product/product.php file.

I am not an expert in coding. Please help me.

Thank you.

Was it helpful?

Solution

It's simple.

First set "display stock" to Yes

admin panel>system>setting>options set display stock to "YES"

now

//catalog>controller>product>product.php

Find (around line 282)

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 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'] = $product_info['quantity'];
} else {
 $this->data['stock'] = $this->language->get('text_instock');
}

Hope this helps

OTHER TIPS

Edit the file catalog/controller/product/category.php

Step : 1

Find the code:

if ($this->config->get('config_review_status')) {
    $rating = (int)$result['rating'];
} else {
    $rating = false;
}

Add the following just below the above code :

if ($result['quantity'] <= 0) {
    $rstock = $result['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
    $rstock = "Stoc: " . $result['quantity'];
} else {
    $rstock = "In stoc";
}

Step : 2

Find :

'thumb' => $image,

Add the following just after the above line

'stoc' => $rstock,

Step 3

Edit the file catalog/view/theme/yourtheme/template/product/category.tpl

Find :

<div class="cart">

Add the following :

<?php echo $product['stoc']; ?>

And now the stock will appear for products in category page.

You can do the same for search (the files would be search.php and search.tpl - in the same folders as the category)

You can see a more detailed tutorial at :

  1. http://www.aleixcortadellas.com/main/2009/09/09/742/
  2. http://forum.opencart.com/viewtopic.php?t=27137
  3. http://forum.opencart.com/viewtopic.php?t=66506

All of the above uses the same idea, but implemented in different ways. But this should help you solve your problem.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top