Magento News
cron job in magento
I wont to make one minute cron job in magento so i have folow below information
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job
so with the help of above i have made new moduli for this cron setup this moduli is acitve and displayed in magento admin panel but cron is not fire
my code for configuration file is
<?xml version="1.0"?>
<config>
<modules>
<Apprika_Cron>
<active>true</active>
<codePool>local</codePool>
</Apprika_Cron>
</modules>
<crontab>
<jobs>
<Apprika_Cron>
<schedule>
<cron_expr>*/1 * * * *</cron_expr>
</schedule>
<run>
<model>Cron/Observer::setLifeCycleStatus</model>
</run>
</Apprika_Cron>
</jobs>
</crontab>
</config>
and the model i have create in C:xampphtdocsceappcodelocalApprikaCronModelObserver.php
the code for this is
class Apprika_Cron_Model_Observer extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->setLifeCycleStatus();
}
public function setLifeCycleStatus()
{
$products = Mage::getModel('catalog/product');
$live_concluded=$this->getProductInfoforLifecycle();
$product = Mage::getModel('catalog/product');
if(count($live_concluded)>0){
foreach($live_concluded as $status=>$value)
{
if($status=='live')
{
for($i=0;$i<count($value);$i++)
{
$productId=$value[$i];
if($productId)
{
try
{
$product->load($productId);
$product->setData('offer_stage','3');
$product->save();
}catch(Exception $e)
{
Mage::printException($e);
}
}
}
}
if($status=='concluded')
{
for($j=0;$j<count($value);$j++)
{
$productId=$value[$j];
if($productId)
{
try
{
$product->load($productId);
$product->setData('offer_stage','4');
$product->save();
}catch(Exception $e)
{
Mage::printException($e);
}
}
}
}
}
}
}
public function getProductInfoforLifecycle()
{
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*');
$current_date=Date('Y-m-d H:i');
$current_date_ts=strtotime($current_date);
$productarr=array();
foreach($products as $product)
{
$offer_stage=$product->getOffer_stage();
$offer_start_date= $product->getOffer_start_date();
$offer_start_date_ts=strtotime($offer_start_date);
$offer_end_date= $product->getOffer_end_date();
$offer_end_date_ts=strtotime($offer_end_date);
$entity_id=$product->getEntity_id();
if($offer_stage==2 && $offer_start_date!="" && $offer_end_date!="" && $offer_start_date_ts <=$current_date_ts)
{
$productarr['live'][]=$entity_id;
}if($offer_stage==2 && $offer_start_date!="" && $offer_end_date!="" && $offer_end_date_ts <=$current_date_ts)
{
$productarr['concluded'][]=$entity_id;
}
}
return $productarr;
}
}
but this cron is not call so this records are not update
if i call http://xyz.com/cron.php
then records updated but with the help of cron records not updated
Thanks in advance
Possibly Related Posts:
- Database query different results
- Menu highlight in magento under admin
- magento disable a banner on certain category pages or have a banner with multiple links
- Magento, using ACL for frontend. Possible?
- Magento IE-7 Fix In Windows XP
RSS Feed