-1

I'm working with opencart 2.0 and I need to adjust the availability of products according to the quantity . I arrived to do that on product pages but now I have to show products ' availability on category pages as well

Mona
  • 23
  • 6

1 Answers1

0

Go to your category controller

catalog->controller->category.php

Here approx line no 231, there would be a array named $data['products'] replace this one with this code

$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, $this->config->get('config_product_description_length')) . '..',
    'price'       => $price,
    'special'     => $special,
    'tax'         => $tax,
    'rating'      => $result['rating'],
    'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url),
    'quantity' => $result['quantity'] // add another key for quantity in this array 
);

And in category.tpl file in your theme you can access the quantity by this variable under products loop

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

I hope this will help you .:)

HDP
  • 4,005
  • 2
  • 36
  • 58
Nipun Tyagi
  • 878
  • 9
  • 26
  • thx for your answer but this will show just the quantity (i mean by this 10 units, 5 units) not the text available, last one ... – Mona Jun 30 '15 at 12:44
  • sorry I am not getting you, can you please explain little bit more what you wants exactly ? – Nipun Tyagi Jun 30 '15 at 12:48
  • or availability : last one according to the quantity – Mona Jun 30 '15 at 12:53
  • so you can try this in tpl file like that .. availability: =$product['quantity']; ?> – Nipun Tyagi Jun 30 '15 at 12:59
  • this will give me availability: 100 or availability :10 and so on – Mona Jun 30 '15 at 13:01
  • You have to print this variable in loop (products loop) in tpl file. – Nipun Tyagi Jun 30 '15 at 13:01
  • why can't add this :if ($product_info['quantity'] <= 0) { $data['stock'] = $result['stock_status']; }elseif($product_info['quantity'] == 10) { $data['stock'] = $this->language->get('text_instock'); } and in the tpl file write even i add 'stock' => $this->data['stock'], to the $data['products'] array – Mona Jun 30 '15 at 13:30