How To Creat cron script in Magento

Some friends don’t know how to creat cron script in magento.Creating Magento cron script is very simple thing. First of all we have to create the module, (I hope that you know how to create magento module) and add in config.xml file next code:


        
            
                0 1 * * *
                birthday/observer::sendBirthayEmail
            
        

Next step, we have to create model file observer.php (in folder model) with method sendBirthayEmail

class Inchoo_Birthday_Model_Observer
{

    public function sendBirthayEmail()
    {
        //this collection get all users which have birthday on today
     	$customer = Mage::getModel("customer/customer")->getCollection();
    	$customer->addFieldToFilter('dob', array('like' => '%'.date("m").'-'.date("d").' 00:00:00'));
    	$customer->addNameToSelect();
    	$items = $customer->getItems();

    	foreach($items as $item)
    	{
        // send email or do something
    	}

        return $this;
    }

}

Related Posts

Speak Your Mind