0

I have created a module witch Generating order xml for ERP. I have created a Observer file but it gives me a Invalid method Mage_Sales_Model_Order. My code is :-

protected function sendFile($filePath, $fileName)
{
    $_helper = Mage::helper('Piyush_orderexport');
    $_helper->log('Uploading the file to the FTP server...');
    if ($ftpResource = ftp_connect(self::FTP_HOST, self::FTP_PORT))
    {
        if (ftp_login($ftpResource, self::FTP_USER, self::FTP_PASSWORD))
        {
            if (ftp_put($ftpResource, $fileName, $filePath, FTP_ASCII))
            {
                $_helper->log("Upload of remote file '$fileName' complete (source file is '$filePath').");
            } else {
                $_helper->log("Warning: error cannot upload the file!");
            }
        } else
        {
            $_helper->log("Warning: error cannot login to the FTP server! Can't upload the file.");
        }
    } else
    {
        $_helper->log("Warning: error connection to the FTP server! Can't upload the file.");
    }
}

public function exportOrder(Varien_Event_Observer $event=null)
{
    $_helper = Mage::helper('Piyush_orderexport');

    $importStartDateTime = date('Y-m-d H:i:s');
    $_helper->log('*** EXPORT ORDER START - ' . $importStartDateTime . ' ***');

    /* @var Mage_Sales_Model_Order $order */
    $order = $event->getOrder();
    //$order = Mage::getModel('sales/order')->loadByIncrementId('100000042');

    $orderIncrementId   = $order->getIncrementId();
    $orderTimestamp     = strtotime($order->getCreatedAt());
    $orderDate          = date("ymd", $orderTimestamp);
    $orderTime          = date("Hi", $orderTimestamp);
    $orderShipping      = number_format(round($order->getShippingInclTax(), 2),2);

    $_helper->log('Processing order '.$orderIncrementId);
    $_helper->log('Order state = '.$order->getState());
    $_helper->log('Order has been exported is '.$order->PiyushOrderExported());


   if ($order->PiyushOrderExported() != '1' && $order->getState() == $order::STATE_NEW) {

        $_helper->log('Exporting order '.$orderIncrementId);
        $_helper->log("\t- date = $orderDate");
        $_helper->log("\t- time = $orderTime");
        $_helper->log("\t- shipping = $orderShipping");

        $xmlFilePath = Mage::getBaseDir('base') .'/'. self::EXPORT_RELATIVE_PATH . self::EXPORT_FILE_NAME;
        $outputFileHandler = fopen($xmlFilePath,"w");

        $orderItems = $order->getAllVisibleItems();
        foreach ($orderItems as $item)
        {
            //$_helper->log("Item data: ".print_r($item->getData(),true));

            $itemSku                = $item->getSku();
            $itemQty                = number_format(round($item->getQtyOrdered(), 2),2);
            $itemRowTotal           = number_format(round($item->getRowTotal(), 2),2,'.','');
            $itemRowTotalInclTax    = number_format(round($item->getRowTotalInclTax(), 2),2,'.','');
            $itemTaxAmount          = number_format(round($item->getTaxAmount(), 2),2,'.','');
            $itemPlu                = Mage::getModel('catalog/product')->loadByAttribute('sku', $itemSku)->PiyushPlu();

            $_helper->log("\t- processing order item $itemSku:");
            $_helper->log("\t\t- qty = $itemQty");
            $_helper->log("\t\t- row total = $itemRowTotal");
            $_helper->log("\t\t- tow total incl tax = $itemRowTotalInclTax");
            $_helper->log("\t\t- tax amount = $itemTaxAmount");
            $_helper->log("\t\t- PLU = $itemPlu");

            $xmlString="";
            /* create your xml here */

            fputs($outputFileHandler,$xmlString);
            //$_helper->log("xmlString = $xmlString");

        }

        fclose($outputFileHandler);

        $this->sendFile($xmlFilePath, self::EXPORT_FILE_NAME);

        $order->setPiyushOrderExported('1');
        $order->save();

        $importEndDateTime = date('Y-m-d H:i:s');
        $_helper->log('*** EXPORT ORDER END - ' . $importEndDateTime . ' ***'.PHP_EOL.PHP_EOL);
    }
}

}

I get following exception ;

2017-11-06T07:07:28+00:00 ERR (3): 
exception 'Varien_Exception' with message 'Invalid method Mage_Sales_Model_Order::PiyushOrderExported(Array
(
)
)' in D:\Ashok\htdocs\new1\lib\Varien\Object.php:653
Stack trace:
#0 D:\Ashok\htdocs\new1\app\code\local\Piyush\OrderExport\Model\Observer.php(54): Varien_Object->__call('PiyushOrderExpo...', Array)
#1 D:\Ashok\htdocs\new1\app\code\local\Piyush\OrderExport\Model\Observer.php(54): Mage_Sales_Model_Order->PiyushOrderExported()
#2 D:\Ashok\htdocs\new1\app\code\core\Mage\Core\Model\App.php(1338): Piyush_OrderExport_Model_Observer->exportOrder(Object(Varien_Event_Observer))
#3 D:\Ashok\htdocs\new1\app\code\core\Mage\Core\Model\App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Piyush_OrderExport_Model_Observer), 'exportOrder', Object(Varien_Event_Observer))
#4 D:\Ashok\htdocs\new1\app\Mage.php(448): Mage_Core_Model_App->dispatchEvent('sales_order_sav...', Array)
#5 D:\Ashok\htdocs\new1\app\code\core\Mage\Core\Model\Abstract.php(466): Mage::dispatchEvent('sales_order_sav...', Array)
#6 D:\Ashok\htdocs\new1\app\code\core\Mage\Sales\Model\Order.php(2174): Mage_Core_Model_Abstract->_afterSave()
#7 D:\Ashok\htdocs\new1\app\code\core\Mage\Core\Model\Abstract.php(319): Mage_Sales_Model_Order->_afterSave()
#8 D:\Ashok\htdocs\new1\app\code\core\Mage\Core\Model\Resource\Transaction.php(151): Mage_Core_Model_Abstract->save()
#9 D:\Ashok\htdocs\new1\app\code\core\Mage\Adminhtml\controllers\Sales\Order\ShipmentController.php(120): Mage_Core_Model_Resource_Transaction->save()
#10 D:\Ashok\htdocs\new1\app\code\core\Mage\Adminhtml\controllers\Sales\Order\ShipmentController.php(220): Mage_Adminhtml_Sales_Order_ShipmentController->_saveShipment(Object(Mage_Sales_Model_Order_Shipment))
#11 D:\Ashok\htdocs\new1\app\code\core\Mage\Core\Controller\Varien\Action.php(418): Mage_Adminhtml_Sales_Order_ShipmentController->saveAction()
#12 D:\Ashok\htdocs\new1\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('save')
#13 D:\Ashok\htdocs\new1\app\code\core\Mage\Core\Controller\Varien\Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#14 D:\Ashok\htdocs\new1\app\code\core\Mage\Core\Model\App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#15 D:\Ashok\htdocs\new1\app\Mage.php(684): Mage_Core_Model_App->run(Array)
#16 D:\Ashok\htdocs\new1\index.php(87): Mage::run('', 'store')
#17 {main}
11
  • your issue is with this code $order->PiyushOrderExported(), what is PiyushOrderExported here?
    – Piyush
    Nov 6, 2017 at 8:07
  • I don't know. a developer suggest me this code. Please help me to sort out this.thanks
    – Piyush
    Nov 6, 2017 at 8:44
  • searched find that It is the value from the piyush_order_exported column in sales_flat_order table
    – Piyush
    Nov 6, 2017 at 10:06
  • 1
    okay, then try $order->getPiyushOrderExported() instead of $order->PiyushOrderExported()
    – Piyush
    Nov 6, 2017 at 10:07
  • 1
    check this answer stackoverflow.com/questions/12936470/…
    – Piyush
    Nov 6, 2017 at 10:42

1 Answer 1

0

finale i found the bug it is in Observer.php. I'm updating a wrong variable.

2
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    – Piyush
    Nov 7, 2017 at 9:06
  • Hi Piyush ! i want a last invoice id, how can i get it
    – Piyush
    Nov 10, 2017 at 6:32

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.