create magento cron job : How to create custom cron job in magento
In this post we will show you how to create magento cron job. here in give code we will create cron job at given your time and execute it.
default Magento have a cron.php
file located at your root directory. for execute cron in magento first we have to create your own module, and in the config.xml
we 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 ::
<?xml version="1.0"?> <config> <modules> <Onlinecode_Cronset> <version>0.1.0</version> </Onlinecode_Cronset> </modules> <crontab> <jobs> <Onlinecode_Cronset> <schedule> <cron_expr>08 00 * * *</cron_expr> </schedule> <run> <model>cronset/expired::productExpireds</model> </run> </Onlinecode_Cronset> </jobs> </crontab> <global> <models> <cronset> <class>Onlinecode_Cronset_Model</class> </cronset> </models> </global> </config>
As per mentioned in this xml your cron will be execute or run every day @ night 00:08 min
::
Now we have to write over own functionality(code) in your Model module file, Here over model file name is Expired and the function which will trigger is productExpireds()
.
<?php // add your create magento cron job code hear class Onlinecode_Cronset_Model_Expired extends Mage_Core_Model_Abstract { public function productExpireds() { // ADD YOUR CODE HEAR } } ?>
Now we need login to server to call the magento root cron.php
You also like ::magento product from category id