0

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!

7
  • have you checked your log files for the error ? Jul 19, 2016 at 13:06
  • No errors at all... Jul 19, 2016 at 13:07
  • Try to put your code within try and catch blocks like this: try{ //your code } catch(Exception $e) { Mage::log($e->getMessage()); } Delete old log files from /var/log folder and retest. Jul 19, 2016 at 13:07
  • Do you have log settings ON from System >> Configuration >> Advanced (Developer) >> Log Settings? Jul 19, 2016 at 13:08
  • Yes they are enabled. Jul 19, 2016 at 13:09

1 Answer 1

0

class VivasIndustries_AutomatedStatus_Model_Observer
{
   public function setStatus() {
        try {
             $orderId = "100005082";
             $order = Mage::getModel('sales/order')->load($orderId);
             // $order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);
             $order->addStatusHistoryComment("My comment why the status was changed", Mage_Sales_Model_Order::STATE_COMPLETE);
             $order->save();
             Mage::log("The order status was changed!");
        } catch(Exception $exception) {
            Mage::logException($exception);
            Mage::log($exception->getMessage());
        }
    }
}

try catch error in you save, and your orderId this increment_id and you need load order by attribute increment_id no entity_id for example load($orderId,'increment_id') or cal loadByAttribute() or loadByIncrementId.

see this answer https://stackoverflow.com/questions/14630707/magento-manually-change-order-status-to-complete

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.