1

After adding <crontab></crontab> in mymodule's config.xml file I got error:

Fatal error: Class 'Mage_Mymodule_Helper_Data' not found in **/app/Mage.php on line 547

in my config.xml

<helpers>
    <mymodule>
     <class>Mypackage_Mymodule_Helper</class>
    </mymodule>
</helpers>

and cron tag

<crontab>
    <jobs>
      <mycron>
        <schedule><cron_expr>*/1 * * * *</cron_expr></schedule>
        <run><model>mymodule/observer::cancelOrders</model></run>
            </mycron>
    </crontab>

Please suggest in which direction i have to check the error. Thank you for help in adv..

  • make sure you have created Data.php file in module's helper Directory – Piyush Apr 17 '17 at 10:57
  • @Piyush Data.php is available in Helper directory. – P_U Apr 17 '17 at 10:59
  • Please share full config.xml code? – Amit Bera Apr 17 '17 at 11:09
  • also folder share the path location of `Data.php' of Mypackage_Mymodule – Amit Bera Apr 17 '17 at 11:11
  • Please create Helper directory and inside directory create Data.php – Soumik Rana Apr 17 '17 at 11:13
0

app/etc/modules/Mypackage_Mymodule.xml

<?xml version="1.0"?>
    <config>
      <modules>
        <Mypackage_Mymodule>
          <active>true</active>
          <codePool>local</codePool>
          <version>0.1.0</version>
        </Mypackage_Mymodule>
      </modules>
    </config>

app/code/local/Mypackage/Mymodule/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Mypackage_Mymodule>
      <version>0.1.0</version>
    </Mypackage_Mymodule>
  </modules>
  <global>
    <helpers>
      <mymodule>
        <class>Mypackage_Mymodule_Helper</class>
      </mymodule>
    </helpers>
    <models>
      <mymodule>
        <class>Mypackage_Mymodule_Model</class>
      </mymodule>
    </models>
  </global>    
    <crontab>
        <jobs>            
            <mymodule_cancelorders>
                <schedule><cron_expr>*/1 * * * *</cron_expr></schedule>
                <run><model>mymodule/cron::cancelOrders</model></run>
            </mymodule_cancelorders>
        </jobs>
    </crontab>
</config> 

app/code/local/Mypackage/Mymodule/Helper/Data.php

class Mypackage_Mymodule_Helper_Data extends Mage_Core_Helper_Abstract
{
}

app/code/local/Mypackage/Mymodule/Model/Cron.php

class Mypackage_Mymodule_Model_Cron{    

        public function cancelOrders(){
            //do something
        } 
}
  • I have created Observer.php inside Model. – P_U Apr 17 '17 at 11:34
  • Why? Are you using any event? – Soumik Rana Apr 17 '17 at 12:37
  • I want to cancel pending orders using cron as per schedule. – P_U Apr 18 '17 at 6:03
  • So that you can use cron.php as well as please use one free module cron doctor to check which cron process is running or which cron process is dead or pending from magento admin section. link of cron doctor - magentocommerce.com/magento-connect/cron-doctor.html – Soumik Rana Apr 18 '17 at 6:29
0

Remove following code from config.xml if you are not using any helper class method.

<helpers>
    <mymodule>
     <class>Mypackage_Mymodule_Helper</class>
    </mymodule>
</helpers>

or create Helper directory and inside that directory create Data.php

<?php
class Mypackage_Mymodule_Helper_Data extends Mage_Core_Helper_Abstract{

}
  • Data.php is inside Helper directory. – P_U Apr 17 '17 at 11:35
  • in my Data.php class name should be Mypackage_Mymodule_Helper or Mypackage_Mymodule_Helper_Data? – P_U Apr 17 '17 at 11:48
  • Mypackage_Mymodule_Helper_Data – Kishan Patadia Apr 17 '17 at 12:20
0

Here we can mention the config.xml file mention the following code

<config>
<crontab>
    <jobs>
        <my_cron>
            <schedule>
                <cron_expr>*/5 * * * *</cron_expr>
            </schedule>
            <run>
                <model>mymodule/observer::functionName</model>
            </run>
        </my_cron>
    </jobs>
</crontab>

Then call that function in observer.php file

class Firstname_MyModule_Model_Observer
{
  public function functionName()
  {
     // Do the operations here
  }
}
0

Below cronjob code will execute at 12:30PM every day.

<job name="test_customer_export" instance="Vendorname\modulename\Cron\Customer" method="execute">
    <schedule>30 12 * * *</schedule>
</job>

30 is minute 12 is hours

  • If you want to run cronjob at 12:30 am every night than schedule format should be: <schedule>0 0 * * *</schedule> – P_U Mar 9 '18 at 13:10
  • for reference please refer examples from this link: crontab.guru/examples.html – P_U Mar 9 '18 at 13:11
  • 1
    Question was for Magento 1. – Julien Loizelet Mar 9 '18 at 13:23

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.