How to display the number of products in the ocStore category 2.3.0.2.3
Let's say there is a page of the category " apple".
My-site.ru/apple
This page displays products only from the corresponding category.
Let's say under the heading <h1>Apple</h1>
in the tag <p></p>
I want to display the number of products in this category
To make it clear, here is an example:
<h1>Apple</h1>
<p class="goods-count"><span>100</span> товаров</p> // в span вывели кол-во
On the category pages in the diagrams, I display all the categories for site navigation in the left column. In this column, THE OUTPUT is the number of products next to the category names. This one I made in
Admin panel-system-settings-options-product counter in the category-yes.
But I can't figure out how to display the number of products in the viewed category to another place on the site. Who-thread will help? In which file to search?
3 answers
So, the fact that you put a check mark, it's all true.
Then there will be a guide on how to do this. Please note I am doing on a standard template, so some points may differ.
Now open the file catalog\controller\product\category.php
Looking for a string that starts like this: $data['results'] =
. She's supposed to be alone there. Below this line, add a new one:
$data['product_total'] = $product_total;
The $product_total
variable stores the total quantity of the product in the category and we needed to pass it to the template.
Must it will turn out like this:
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
$data['product_total'] = $product_total;
Now open the file catalog\view\theme\default\template\product\category.tpl
(category page template).
Please note, I am editing the "default template". In your case, edit your own.
Look for the line where the category name is displayed. In my case, this is <h1><?php echo $heading_title; ?></h1>
. Now I add the quantity of the product there, for example:
<h1><?php echo $heading_title; ?> (<?php echo $product_total; ?>)</h1>
It should have been something like this:
If it helps anyone:
Made a script
<script>
var count = $('.list-group-item.active').text();
var r = /\d+/;
$('.goods_counter span').text($('.list-group-item.active').text().match(r));
</script>
In short - the active category has a class .active
from it, I copied the text to the right place and removed everything from there except the numbers (letters, brackets, punctuation marks)
I may have misunderstood something. But I'll try to answer it anyway.
Why not just create a folder in the root with a name of some kind. For example, include
and in it apple.php
and in it store the number of apples. And on the page itself, connect this file.
<?php
include ('../include/apple.php')
?>
Apple.php
<?php
$apple = 15;
?>
And in the file itself
<p>На складе <?php echo $apple ?> яблок.</p> // На складе 15 яблок.
Well, or in other parts of the page.