Answer the question
In order to leave comments, you need to log in
How to display the quantity of all products in the template?
I welcome everyone. I have never encountered Bitrix before, and here it would seem that a simple task needs to be solved. It is necessary to display a list of products in the template, in the header, something like this:
There are 10,000 products on the site.
Found some code on the internet
$ar_res = CCatalogProduct::GetByID($arElement['ID']);
echo "<br>На складе: ";
print_r($ar_res['QUANTITY']);
echo " шт.";
}
Answer the question
In order to leave comments, you need to log in
You, most likely, will not understand what I mean, since you have no experience with Bitrix, but I will write anyway. Try to figure it out, it will be very helpful.
You can solve this problem head-on: make a CIBlockElement::GetList() request right in the site header , count the number of elements and display them. And it is after such decisions that Bitrix is called inhibitory, because it is completely wrong.
The number of products in the catalog changes extremely rarely, there is no point in counting it for each user. It would be possible to cache this selection for some time, then the request will not be made for each user, but only for some "lucky ones". But even that would be wrong.
This value can and should be read in the background, so the correct solution would be:
An alternative solution would be to use infoblock events instead of an agent, but it is more complicated and not more reliable - a race condition may occur, for example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question