0

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?

1 Answer 1

0

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 :)

4
  • Thanks for the reply and code sample. I will try to create my own module that overrides the cronjob schedule. My genuine problem is that i want to keep discounts for a longer period of time using the catalog price rule, but they automatically expire after 2 days. Do you know something about that?
    – Lucci
    Mar 26, 2021 at 11:35
  • that's weird.. unfortunately i didn't encounter this behavior in any of my projects, but isn't it maybe related to the expiration date of the rules?
    – Diana
    Mar 26, 2021 at 11:51
  • I envy you if that is the case with your projects. I have 3 stores, and on each store every 2 days catalog price rules just vanish. Expiration dates are set for a year in advance so i don't think that is the problem.
    – Lucci
    Mar 26, 2021 at 12:04
  • yeah, that's probably not it then. hmmm, are you on EE? if so, are using content staging? i would probably look into that aaand also any other 3rd party module (disable them all on a test env and see if the issue still appears).
    – Diana
    Mar 26, 2021 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.