Answer the question
In order to leave comments, you need to log in
Bitrix, discounts for different users + sorting?
Hello.
You need to make several discount options for different user groups.
Purely theoretical, they are ready, but there is a problem.
Sort items by discounted price.
Now it works like this: I created a new property (numeric), and there I write down the final price with a discount.
And sorted by it. But now the question. How to do if I have several groups?
Do not create a new property for each group and sort by it?
Answer the question
In order to leave comments, you need to log in
Since we didn't wait for anything, here's my answer:
Since discounts are calculated at PHP runtime, there's no way you can order items by discounted price in the query, and sorting must be done AFTER the discount price is calculated.
Worse, to build each page, you have to extract ALL products, calculate the discounted price for ALL products, sort the array at runtime, and select the products for the page from it.
This is a very expensive operation that cannot be bypassed in any way. Everything will be fine until you have a lot of goods or very rare changes in them, but as soon as there are a lot of goods, all these calculations of yours will cause the server to consume all the memory and processor.
Therefore, we need a cache. And it was not bad to make this cache as narrow as possible in order to update it as rarely as possible. And it is better to calculate directly when adding a new product and preferably only for it.
What to store in this cache? It turns out just pre-calculated prices with a discount ...
And now we are back exactly here:
How to do if I have several groups?
Do not create a new property for each group and sort by it?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question