Answer the question
In order to leave comments, you need to log in
How to make the correct display of prices for products with discounts when the cache is enabled?
Welcome all.
The site has a bitrix:catalog component with caching enabled. When displaying prices for goods without discounts, there are no problems, and when a rule for the basket (discount) is created, then in order to correctly display prices with a discount, you need to reset the cache. The option to reset the cache every time (automatically or manually) is not suitable, because. about 25,000 products are cached.
What needs to be done so that prices with discounts are displayed correctly, with frequently changing rules for the basket (discounts) with caching enabled.
Bitrix support did not help.
Answer the question
In order to leave comments, you need to log in
It looks like the general solution would be:
BXClearCache(false, "/s1/bitrix/catalog.section/");
(new \Bitrix\Main\Data\ManagedCache())->cleanAll();
(new \CStackCacheManager())->CleanAll();
And rightly so, that did not prompt.
Cart rules depend not only on the product, but also on other conditions.
The simplest and most clumsy way to do this is to subscribe to d7 events and update the component's cache.
Events you are interested in:
- \Bitrix\Modules\Sale\Internals\Discount::onAfterAdd (after creation)
- \Bitrix\Modules\Sale\Internals\Discount::onAfterUpdate (after update)
How to clear the cache:
- https://dev .1c-bitrix.ru/api_help/main/functions/o...
- https://dev.1c-bitrix.ru/api_help/main/reference/c...
Oh, dear friend, welcome to the world of perversions and crutches.
1. We start a highload block in which we write down the product id and its price at the time the catalog component is running, before the cache is formed, be sure to tag the cache. And we hang a handler on the cron that constantly runs through the catalog and checks prices (taking into account user groups), if the received price does not match the one recorded in the highload block, then we reset the corresponding cache by tag.
2. Add the date when the rule for working with the cart was changed to the product caching key. The date has changed => the cache is out of date.
3. Load all areas with price display in templates using Ajax (similar to composite mode).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question