Hello dear friends.
In this article, I would like to describe several different ways and manipulations on products that are not available in opencart.
- Add status of availability to category
- The product of which is not available at the very end of the list
- Hide the goods which are not in stock
Task β1
First of all, let's talk about how to display (display) the availability of goods in the list of products in categories and similar pages such as search, stocks, manufacturers, etc.
By default, Opencart does not display the status of the availability of goods in the general list of products, well, let's fix it.
And so before us there is opencart version 1.5.5.1 or any other version of this branch, well, we will use the template by default.
In order to display the availability of goods in the category, do the following:
1.To a file /catalog/language/russian/product/category.php
In any place we add:
1 |
$_['text_instock'] = 'In stock'; |
I added this line after ($_['text_manufacturer'] = 'Manufacturer:';) But this is not a principle and you can leave it anywhere, between tags <?php and ?> Also do not forget to do the same with other language files if you have a store in several languages.
The text we added, now we need to correct a bit of the controller itself namely:
2. In file catalog/controller/product/category.php
After the line:
1 |
'special' => $special, |
Adding:
1 2 3 |
'stock' => $result['quantity'], 'stock_status'=> $result['stock_status'], 'instock' => $this->language->get('text_instock'), |
Everything with the controller is also finished.
3. Well, our last step is to display all this construction in the file of our template :
Namely, we open:
catalog/view/theme/default/template/product/category.tpl
And in the right place you add the code:
1 2 |
<span style="font-weight: 700; color:#E10606;"><?php if ($product['stock'] <= 0) { ?> <?php echo $product['stock_status']; } ?></span> <span style="font-weight: 700; color:#428d2f;"><?php if ($product['stock'] > 0) { ?> <?php echo $product['instock']; } ?></span> |
I added it immediately under the price namely before the last div after the code:
1 2 |
<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span> <?php } ?> |
That's all, in such a simple way we added to the list of products the display of its availability, as all this looks like you can see in the photo below.
Task β2
Now we proceed to consider the second question, sometimes we still need to do so that the product of which is not available was always at the very end of the list of goods.
The solution of this task is even easier, open the file catalog\model\catalog\product.php And change the code in it:
1 2 3 4 5 6 7 8 9 10 11 |
Β Β Β Β Β Β if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { Β Β Β Β Β Β Β Β Β if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') { Β Β Β Β Β Β Β Β Β Β Β Β $sql .= " ORDER BY LCASE(" . $data['sort'] . ")"; Β Β Β Β Β Β Β Β Β } elseif ($data['sort'] == 'p.price') { Β Β Β Β Β Β Β Β Β Β Β Β $sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)"; Β Β Β Β Β Β Β Β Β } else { Β Β Β Β Β Β Β Β Β Β Β Β $sql .= " ORDER BY " . $data['sort']; Β Β Β Β Β Β Β Β Β } Β Β Β Β Β Β } else { Β Β Β Β Β Β Β Β Β $sql .= " ORDER BY p.sort_order";Β Β Β Β Β Β Β Β Β } |
To the following code:
1 2 3 4 5 6 7 8 9 10 11 |
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { $sort = $data['sort']; } else { $sort = 'p.sort_order'; } $append_order = 'p.price = 0, p.quantity = 0,'; if ($sort == 'pd.name' || $sort == 'p.model') { $sql .= " ORDER BY $append_order LCASE($sort)"; } else { $sql .= " ORDER BY $append_order $sort"; } |
All, now all products in which the quantity indicated 0 will be displayed at the very end of the list of all products of the category.
Task β3
I am often asked how you can remove products that are not available from the OpenCart product list, but that they are available for search engines.
That is, the problem is that users would not visually see such goods, but that they could go to them by direct links, because it's a pity to remove the goods completely from the store because they could be indexed by search engines, and there is no traffic on them , Sometimes even very good traffic, of course the client who will go to this link to your site will not buy it because it is not available, but it can be bought from you by any other product that is available in the warehouse.
And so let's consider how all the same you can hide the missing goods from the category, but leave them to access by direct link.
And the solution as always is very simple, we find the file catalog/controller/product/category.php
And before the line:
1 |
if ($result['image']) { |
Add the following:
1 |
if ($result['quantity'] > 0) { |
Well and it is obligatory after a line:
1 2 |
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url) ); |
We close the bracket, that is, add:
1 |
} |
That's basically all, now when viewing the list of products in the category the user will not see the goods in which the value of the quantity is zero.
But the product will be available to users who come to you from search engines. In this revision there is one not significant minus, the amount of general goods in the category will be displayed all, as well as goods in stock and goods which are not available, but I think that this is not a significant minus.
Well, that's all I wanted to describe here. I will be glad if this note will be useful to someone!
No Comment
You can post first response comment.