开发者

Magento store id in cronjob

Is there a way to give a store id as parameter when executin开发者_如何学Cg a model with cronjob ?


You cannot specify store scope for Magento Cron Job, but you can add additional arguments that you can use inside of it.

  1. Specify additional node that you can process via 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>
    
  2. And method where you receiving the schedule object with current job 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 the store related models can load data only for a particular store, so I hope it solves your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜