0

enter image description here

I am developing custom module, in which i'm adding custom block sales->order edit page with field price that update total paid price (Order Totals) block. But while refreshing

adminhtml/sales_order_totals
block, i got an error

Fatal error: Call to a member function getOrder() on a non-object \app\code\core\Mage\Sales\Block\Order\Totals.php on line 67

After clicking to "Add button", It call saveAction() controller

public function saveAction() 
{ 
    $modelOrder = Mage::getModel('sales/order')->load(100015)->setGrandTotal(300)->save(); 
    return $this->_forward('successajax'); 

}

and $this->_forward('successajax'); call to below controller

public function successajaxAction()
{ 
    $this->loadLayout();
    $this->getResponse()->setBody(
        Mage::app()->getLayout()->createBlock('adminhtml/sales_order_totals')->setTemplate('sales/order/totals.phtml')->toHtml()
    );        
}

On ajax response, We replace Order Totals block will showing me bellow error.

enter image description here

Please help me to resolve this error.

  • please provide full details about your custom module., like block, controllers, config etc – amit_game Aug 1 '15 at 7:44
  • I have custom form in admin->sales->order that submit price field to saveAction() controller. public function saveAction() { $modelOrder = Mage::getModel('sales/order') ->setGrandTotal(500)->save(); return $this->_forward('successajax'); } 'public function successajaxAction() { $this->loadLayout(); $this->getResponse()->setBody( Mage::app()->getLayout()->createBlock('adminhtml/sales_order_totals')->setTemplate('sales/order/totals.phtml')->toHtml() ); }' – Bhushan Gohel Aug 1 '15 at 7:51
  • We need to get that error, which is coming, so for that need full code and file description, after examine which we can go forward for solution, so please edit your question and add your code description on it – amit_game Aug 1 '15 at 8:20
0

With lots of crazy research and after spending full day on this, I found solution of my question.

I have to override OrderController.php file in config.xml

<admin>
    <routers>
        <!-- Override OrderController -->
        <adminhtml>     
            <use>admin</use>           
            <args>
                <orderupdate>
                    <NameSpace_ModuleName before="Mage_Adminhtml">NameSpace_ModuleName</NameSpace_ModuleName>
                </orderupdate>                    
            </args>
        </adminhtml>
    </routers>
</admin>

and override file in NameSpace/ModuleName/controllers/Adminhtml/OrderController.php

<?php 
require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php';
class NameSpace_ModuleName_Adminhtml_OrderController extends Mage_Adminhtml_Sales_OrderController
{    
    public function saveAction() {  
        if ($data = $this->getRequest()->getPost()) { 

            try {
                $modelOrder = Mage::getModel('sales/order')->load($data['order_id'])
                ->setGrandTotal($data['custom_price'])
                ->save();

                /** Initialize order **/
                $order = $this->_initOrder(true);                               
                $this->_initAction();

                $response = $this->getLayout()->createBlock('adminhtml/sales_order_totals')->setTemplate('sales/order/totals.phtml')->toHtml();

            } catch (Exception $e) {
                $response = array(
                'error'     => true,
                'message'   => $this->__('Cannot update price. Please refresh page.')
                );
                $response = Mage::helper('core')->jsonEncode($response);
            }
            $this->getResponse()->setBody($response);
        }
    }                    
} ?>

I think this may help other people that facing issue like this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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