header ad

Saturday, August 11, 2018

In stock or Out of stock label on Opencart Category page

This tutorial help you to add stock status on your Opencart category page. This guide test with Opencart 3.0.2.0



















Edit stylesheet.css

Open \opencart\catalog\view\theme\default\stylesheet\stylesheet.css

add following code in last line

.stock_label
{
width: auto; height:auto; display:inline-block;
padding:2px 5px 2px 5px;
background:#000;
font-size:12px; color:#FFF; font-weight:600;
}



Edit Category.php controller file

Open \opencart\catalog\controller\product\category.php

Find following code

$data['products'][] = array(
'product_id'  => $result['product_id'],
'thumb'       => $image,
'name'        => $result['name'],
'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
'price'       => $price,
'special'     => $special,
'tax'         => $tax,
'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating'      => $result['rating'],
'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);


Replace this code with following


////// Stock Status ////////
if ($result['quantity'] <= 0) {
$stock_status = $result['stock_status'];
} elseif ($this->config->get('config_stock_display')) {
$stock_status = $result['quantity'];
} else {
$stock_status = 'In Stock';
}
////// End Stock Status ////////


$data['products'][] = array(
'product_id'  => $result['product_id'],
'thumb'       => $image,
'name'        => $result['name'],
'stock_status'=> $stock_status,  // Stock Status
'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
'price'       => $price,
'special'     => $special,
'tax'         => $tax,
'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating'      => $result['rating'],
'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);


Edit category.twig file

Open \opencart\catalog\view\theme\default\template\product\category.twig

Find following line

<h4><a href="{{ product.href }}">{{ product.name }}</a></h4>


after above line add following line

<div class="stock_label">{{ product.stock_status }}</div>


Now your scripts are ready to show stock status but you should refresh in admin panel

How to do it?
  1. Go to admin panel dashboard
  2. You can see "Setting icon" under Logut button (I checked with desktop version)
  3. CLick it
  4. Now popup will open
  5. In the popup you can see action field with refresh icon
  6. Click it in both rows

No comments:

Post a Comment