Answer the question
In order to leave comments, you need to log in
How to make random sorting in the catalog in 1C-Bitrix?
Good afternoon! There is a task:
in the catalog component, when displaying the elements of the section, make random sorting. Only not for all elements, but only for those whose sort index is greater than 23 (equal to 500 for example). How can this be implemented?
Answer the question
In order to leave comments, you need to log in
We do the usual sorting by SORT, and then:
1 in the template we display only elements with sorting less than 23, the rest are thrown out as data and rendered on the page with js (stupid option: output to a script tag with an unexecutable type, and from there add js ' ohm per page), the pages by the set of elements will be the same, but the order will be different each time. The cache is working.
2 Add 2-4 additional properties say SORT1, SORT2 etc. we fill these properties with random numbers and do the second sorting by one of them. At the same time, we choose which one randomly. We get 4 caches with different pages in composition.
3 Once a day at night, the agent rewrites these additional properties to other random values.
Total: the cache works, there is a semblance of randomness, and it is different with each update, and even hell you will understand that the pages are often the same in composition. The catalog will increase the volume of the cache - well, everything has a price.
UPD:
About the solution with two components - just hide the first 22 elements in the second component on the first page and that's it. Naturally the page should be more than 22 elements.
Perhaps you will immediately object that then the visitor in the page selection will not see these 22 elements, so I will answer right away - this should not bother you at all, since your visitor will not see almost half of the catalog at all (so 40-45% offhand) with a random selection + pagination. In general, pagination with a real random sample is completely meaningless.
I gave above a working solution close to your requirements.
If you want to get rid of the fact that some of the catalog elements will be invisible during pagination, pass in the pagination properties also the sorting property accidentally set on the first start page.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question