Tuesday , December 12 2017
Home >> All tutorial >> How to create custom cron job in magento

How to create custom cron job in magento

Magento default have a cron.php file located in the root directory. To set a cron in magento you have to create your own module first, and in the config.xml you have to declare the method which will fired and the time. Below is a dump of a etc/config.xml file of a custom cron module

  1. <?xml version=“1.0”?>
  2. <config>
  3. <modules>
  4. <Wl_Cronset>
  5. <version>0.1.0</version>
  6. </Wl_Cronset>
  7. </modules>
  8. <crontab>
  9. <jobs>
  10. <Wl_Cronset>
  11. <schedule>
  12. <cron_expr>01 00 * * *</cron_expr>
  13. </schedule>
  14. <run>
  15. <model>cronset/expired::productExpired</model>
  16. </run>
  17. </Wl_Cronset>
  18. </jobs>
  19. </crontab> 
  20. <global>
  21. <models>
  22. <cronset>
  23. <class>Wl_Cronset_Model</class> 
  24. </cronset> 
  25. </models> 
  26. </global>
  27. </config>

As per mentioned in this xml your cron will be fired every day @ night 00:01 min

Now you have to write your own functionality in your module Model file, Here my model file name is Expired and the function which will trigger is productExpired().

  1. <?php
  2. class Wl_Cronset_Model_Expired extends Mage_Core_Model_Abstract
  3. {
  4. public function productExpired()
  5. {
  6. // Your code goes here
  7. }
  8. }
  9. ?>
Now login to your server to call the magento root cron.php and set to be fired in every minute.

We also contribute great content of Magento Download for FREE (all versions)

DON'T MISS THE CHANCE!

magento download

About Champ

Leave a Reply

Your email address will not be published. Required fields are marked *

Heap | Mobile and Web Analytics