Magento store id in cronjob

Is there a way to provide a store id as a parameter when running a model using cronjob?

+6
source share
1 answer

You cannot specify the storage area for the Magento Cron job, but you can add additional arguments that you can use inside it.

  • Specify an additional node that you can handle with your cron method:

    <crontab> <jobs> <job_name> <schedule> <cron_expr>* * * * * *</cron_expr> </schedule> <run> <model>module/observer::myJob</model> </run> <store>store_code</store> </job_name> </jobs> </crontab> 
  • And the method in which you get the schedule object with the current task code:

     public function myJob($schedule) { $jobsRoot = Mage::getConfig()->getNode('crontab/jobs'); $jobConfig = $jobsRoot->{$schedule->getJobCode()}; $yourStoreNode = (string) $jobConfig->store; // Here goes store related functionality } 

All store-related models can only download data for a specific store, so I hope it solves your problem.

+18
source

Source: https://habr.com/ru/post/885962/


All Articles