Catalog price rules - update on schedule
-
15-04-2021 - |
Question
I have updated my web shop to Magento 2.4.2 version and i would like to set my cron job to update every 48h just for Catalog price rules (catalogrule_rule). Does anybody know how to do that?
Solution
I am not sure if you want to overwrite the magento default cronjob schedule or you simply need the schedule expression for your own custom cronjob.
However, I will answer both with the code below: I think overwriting a core cronjob's schedule should be doable by creating a custom module and creating the etc/crontab.xml
file that will overwrite the original one. The content should be the same, just a different schedule:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
<group id="default">
<job name="catalogrule_apply_all" instance="Magento\CatalogRule\Cron\DailyCatalogUpdate" method="execute">
<schedule>0 1 */2 * *</schedule>
</job>
</group>
</config>
The <schedule>0 1 */2 * *</schedule>
part will make the cronjob execute At 01:00 on every 2nd day-of-month. so you either use just this bit and adjust your own custom cronjob schedule or overwrite the core one, there you have it :)