0

I added two button in order view it's working fine but i want to disable this button if order is complete and order is canceled time

My Abstract file

public function addOrderstatusAction($observer)
    {
        $block = $observer->getEvent()->getBlock();
        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {

            $message = Mage::helper('sales')->__('Are you sure you want to Change Status?');

            $block->addButton('rto', 
                array( 'label' => Mage::helper('sales')->__('RTO'), 
                    'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('orderstatus/adminhtml_index/rto')}')", 'class' => 'go' ));

           $block->addButton('in_shipment', 
            array( 'label' => Mage::helper('sales')->__('In Shipement'), 
                'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('orderstatus/adminhtml_index/in_shipment')}')", 'class' => 'go' ));  
        }


    }
2
  • order complete and order canceled? Dec 10 '15 at 5:29
  • yes @Qaisar....
    – Magento 2
    Dec 10 '15 at 5:30
1

Replace your code from

public function addOrderstatusAction($observer)
    {
        $block = $observer->getEvent()->getBlock();
        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {

            $message = Mage::helper('sales')->__('Are you sure you want to Change Status?');

            $block->addButton('rto', 
                array( 'label' => Mage::helper('sales')->__('RTO'), 
                    'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('orderstatus/adminhtml_index/rto')}')", 'class' => 'go' ));

           $block->addButton('in_shipment', 
            array( 'label' => Mage::helper('sales')->__('In Shipement'), 
                'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('orderstatus/adminhtml_index/in_shipment')}')", 'class' => 'go' ));  
        }


    }

TO

<?php

class Ar_Orderstatus_Model_Observer
{

    public function addOrderstatusAction($observer)
    {
        $block = $observer->getEvent()->getBlock();
        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
            $order = $this->_initOrder();
            if (!$order->isCanceled() && $order->canShip()) {
                $message = Mage::helper('sales')->__('Are you sure you want to Change Status?');

                $block->addButton('rto', 
                    array( 'label' => Mage::helper('sales')->__('RTO'), 
                        'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('orderstatus/adminhtml_index/rto')}')", 'class' => 'go' ));

               $block->addButton('in_shipment', 
                array( 'label' => Mage::helper('sales')->__('In Shipement'), 
                'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('orderstatus/adminhtml_index/in_shipment')}')", 'class' => 'go' ));  
            }
        }
    }

    protected function _initOrder()
    {
        $id = Mage::app()->getRequest()->getParam('order_id');
        $order = Mage::getModel('sales/order')->load($id);
        return $order;
    }
}
6
  • How to send a mail to customer for current state
    – Magento 2
    Dec 10 '15 at 5:48
  • $order->sendOrderUpdateEmail(true, ''); in your action file after$order->save()
    – Abdul
    Dec 10 '15 at 5:53
  • If your are add new qus then i will added with code
    – Abdul
    Dec 10 '15 at 5:54
  • ok i will post question
    – Magento 2
    Dec 10 '15 at 5:54
  • Can you please Check this link magento.stackexchange.com/questions/93268/…
    – Magento 2
    Dec 10 '15 at 5:57
1
 public function addOrderstatusAction($observer)
    {
      $order_id=Mage::app()->getRequest()->getParam('order_id');
    $order=Mage::getModel('sales/order')->load($order_id);
        $block = $observer->getEvent()->getBlock();
        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {

            $message = Mage::helper('sales')->__('Are you sure you want to Change Status?');
          if($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE  OR $order->getState() == Mage_Sales_Model_Order::STATE_CANCELED)
        {


          }else {
               $block->addButton('rto', 
                array( 'label' => Mage::helper('sales')->__('RTO'), 
                    'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('orderstatus/adminhtml_index/rto')}')", 'class' => 'go' ));

          }

          if($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE  OR $order->getState() == Mage_Sales_Model_Order::STATE_CANCELED)
        {


          }else {
             $block->addButton('in_shipment', 
            array( 'label' => Mage::helper('sales')->__('In Shipement'), 
                'onclick' => "confirmSetLocation('{$message}', '{$block->getUrl('orderstatus/adminhtml_index/in_shipment')}')", 'class' => 'go' ));  

          }
             }


    }
4
  • It working but i want to hide that button
    – Magento 2
    Dec 10 '15 at 5:41
  • remove the if code updated check it now Dec 10 '15 at 5:43
  • How to send a mail to customer for current state
    – Magento 2
    Dec 10 '15 at 5:48
  • you want send order update email or custom email? Dec 10 '15 at 5:54

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.