Magento store id in cronjob

前端 未结 1 1407
孤独总比滥情好
孤独总比滥情好 2021-02-09 15:50

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

1条回答
  •  闹比i
    闹比i (楼主)
    2021-02-09 16:04

    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:

      
         
             
                 
                     * * * * * *     
                 
                 
                     module/observer::myJob
                 
                 store_code
             
         
      
      
    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 讨论(0)
提交回复
热议问题