Magento store id in cronjob

蓝咒 提交于 2019-12-04 12:00:16

问题


Is there a way to give a store id as parameter when executing a model with cronjob ?


回答1:


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.



来源:https://stackoverflow.com/questions/5673911/magento-store-id-in-cronjob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!