I
I
imdeveloper2016-10-28 02:37:09
1C-Bitrix
imdeveloper, 2016-10-28 02:37:09

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 " шт."; 
}

But I get an error that the module is not connected. It seems that I found how to connect, but this code is not logical for my task, because here I need to set the id of some product, and I just need to get a list of all records from the collection. What ideas?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dev400, 2016-10-28
@dev400

dev.1c-bitrix.ru/api_help/iblock/classes/ciblockel...

A
Alexey Ukolov, 2016-10-28
@alexey-m-ukolov

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 question

Ask a Question

731 491 924 answers to any question