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
Asked
Active
Viewed 132 times
-1
-
1Yeah, so... what's your question? Please read [this](https://stackoverflow.com/help/how-to-ask). – wonderb0lt Jun 30 '15 at 10:55
-
how can i show product 's availability on category pages? – Mona Jun 30 '15 at 10:59
-
and where is the code that you have tried? – Abdo Adel Jun 30 '15 at 13:02
1 Answers
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
-
-
so you can try this in tpl file like that .. availability: =$product['quantity']; ?> – Nipun Tyagi Jun 30 '15 at 12:59
-
-
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