I am using Magento 1.9.2 and I am developing a custom extension.
Here is my config file of the extension:
<?xml version="1.0"?>
<config>
<frontend>
<layout>
<updates>
<automatedstatus>
<file>automatedstatus.xml</file>
</automatedstatus>
</updates>
</layout>
</frontend>
<modules>
<VivasIndustries_AutomatedStatus>
<version>1.0.0</version>
</VivasIndustries_AutomatedStatus>
</modules>
<global>
<models>
<automatedstatus>
<class>VivasIndustries_AutomatedStatus_Model</class>
<resourceModel>vivasindustries_automatedstatus_resource</resourceModel>
</automatedstatus>
<vivasindustries_automatedstatus_resource>
<class>VivasIndustries_AutomatedStatus_Model_Resource</class>
<entities>
<automatedstatus>
<table>VivasIndustries_AutomatedStatus</table>
</automatedstatus>
</entities>
</vivasindustries_automatedstatus_resource>
</models>
<resources>
<automatedstatus_setup>
<setup>
<module>VivasIndustries_AutomatedStatus</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</automatedstatus_setup>
<automatedstatus_read>
<connection>
<use>core_read</use>
</connection>
</automatedstatus_read>
<automatedstatus_write>
<connection>
<use>core_write</use>
</connection>
</automatedstatus_write>
</resources>
<helpers>
<automatedstatus>
<class>VivasIndustries_AutomatedStatus_Helper</class>
</automatedstatus>
</helpers>
<blocks>
<automatedstatus>
<class>VivasIndustries_AutomatedStatus_Block</class>
</automatedstatus>
</blocks>
</global>
<crontab>
<jobs>
<automatedstatus>
<schedule>
<cron_expr>*/1 * * * *</cron_expr>
</schedule>
<run>
<model>automatedstatus/observer::setStatus</model>
</run>
</automatedstatus>
</jobs>
</crontab>
<adminhtml>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<system>
<children>
<config>
<children>
<automatedstatusadmin>
<title>Vivas - All</title>
</automatedstatusadmin>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<VivasIndustries_AutomatedStatus before="Mage_Adminhtml">VivasIndustries_AutomatedStatus_Adminhtml</VivasIndustries_AutomatedStatus>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
For developing purpose, I have set the cron job to run every minute. Here is my observer.php:
class VivasIndustries_AutomatedStatus_Model_Observer
{
public function setStatus() {
Mage::log("The order status was changed!");
}
}
Every minute I can see that the cron job is done by seeing that The order status was changed!
message is added to my system.log file.
However when I change it to this:
<?php
class VivasIndustries_AutomatedStatus_Model_Observer
{
public function setStatus() {
try{
$orderId = 100005082;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);
$order->save();
Mage::log("The order status was changed!");}
catch(Exception $e)
{
Mage::log($e->getMessage());
}
}
}
In the system.log file there are no longer The order status was changed!
message added and also the order status is not changed.
I am pretty sure the problem comes from the code for order status changing.
Where is my mistake? How can i fix it?
Thanks in advance!