Tuesday, October 21, 2014

How to show product stock availability in category page in Opencart cms

Today I will show you how to display product stock availability in category page in Opencart cms. There are few code that  you need to add in the several page.

First Step:

========

Go to category.php  in catalog/controller/product and place this code:

$this->data['text_stock'] = $this->language->get('text_stock');


After this code:

$this->data['text_limit'] = $this->language->get('text_limit');






Again place this code:

if ($result['quantity'] <= 0) {
   $this->data['stock'] = $result['stock_status'];
   } elseif ($this->config->get('config_stock_display')) {
   $this->data['stock'] = $result['quantity'];
   } else {
   $this->data['stock'] = $this->language->get('text_instock');
}
 
 

Before this code:  

$this->data['products'][] = array(
                    'product_id'  => $result['product_id'],
                    'thumb'       => $image,
                    'name'        => $result['name'],
                    'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
                    'price'       => $price,
                    'special'     => $special,
                    'stock'       => $this->data['stock'],
                    'tax'         => $tax,
                    'rating'      => $result['rating'],
                    'reviews'     => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
                    'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
                ); 


Again Place this code:

'stock'       => $this->data['stock'],


After this code:

'special'     => $special,




Second Step:

========

Go to category.php in catalog/language/english/product then place this code:

$_['text_stock'] = 'Availability:';
$_['text_instock'] = 'In Stock';


After this code:

$_['text_limit'] = 'Show:';




Third Step:

========
Finaly, go to category.tpl in catalog/view/theme/yourtheme/template/product then place this code:


 <div><span style="color:#38B0E3;"><?<?php echo $text_stock; ?></span><?php echo $product['stock']; ?></div>


After this code:

<?php if ($product['tax']) { ?>
        <br />
        <span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
        <?php } ?>


Hope you have got solution here. Thanks for your reading. 
 

No comments:

Post a Comment