0

We want to display custom button "Generate bluedart shipment" in Sales > Order view page. so we installed custom module in fresh site, it worked fine.

here we used class Bluedart_Shipment_Block_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View

enter image description here

In another site we used same module, but here another module is already extending default Sales Order view to display Delete Order button as class Raveinfosys_Deleteorder_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View So here "Generate Bluedart shipment button" is not displaying....

enter image description here

app/code/community/Bluedart/Shipment/Block/Sales/Order/View.php :

class Bluedart_Shipment_Block_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View
    {
        function __construct()
        {
            $itemscount     = 0;
            $totalWeight    = 0;
            $_order = Mage::getModel('sales/order')->load($this->getRequest()->getParam('order_id'));               
            $itemsv = $_order->getAllVisibleItems();
            foreach($itemsv as $itemvv){
                if($itemvv->getQtyOrdered() > $itemvv->getQtyShipped()){
                    $itemscount += $itemvv->getQtyOrdered() - $itemvv->getQtyShipped();
                }
                if($itemvv->getWeight() != 0){
                    $weight =  $itemvv->getWeight()*$itemvv->getQtyOrdered(); 
                } else {
                    $weight =  0.5*$itemvv->getQtyOrdered();
                }
                $totalWeight    += $weight;
             }

             $shipments = Mage::getResourceModel('sales/order_shipment_collection')
                ->addAttributeToSelect('*') 
                ->addFieldToFilter("order_id",$_order->getId())->join("sales/shipment_comment",'main_table.entity_id=parent_id','comment')->addFieldToFilter('comment', array('like'=>"%{$_order->getIncrementId()}%"))->load();

                $bluedart_return_button = false;

                if($shipments->count()){
                    foreach($shipments as $key=>$comment){
                        if (version_compare(PHP_VERSION, '5.3.0') <= 0) {
                            $awbno=substr($comment->getComment(),0, strpos($comment->getComment(),"- Order No")); 
                        }
                        else{               
                            $awbno=strstr($comment->getComment(),"- Order No",true);
                        }
                        $awbno=trim($awbno,"AWB No.");                  
                        break;
                    }
                    if((int) $awbno)
                        $bluedart_return_button = true;
                }

            if($_order->canShip()){
             $this->_addButton('create_bluedart_shipment', array(
                            'label'     => Mage::helper('Sales')->__('Generate Blue Dart Shipment'),
                            'onclick'   => 'bluedartpop('.$itemscount.')',
                            'class'     => 'go'
                        ), 0, 100, 'header', 'header');
            }
            elseif(!$_order->canShip() && $bluedart_return_button){
                 $this->_addButton('create_bluedart_shipment', array(
                            'label'     => Mage::helper('Sales')->__('Return Blue Dart Shipment'),
                            'onclick'   => 'bluedartreturnpop('.$itemscount.')',
                            'class'     => 'go'
                  ), 0, 100, 'header', 'header');
            }

                parent::__construct();
        }
    }

app/code/community/Raveinfosys/Deleteorder/Block/Adminhtml/Sales/Order/View.php

class Raveinfosys_Deleteorder_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View 
{
    public function  __construct() {

        parent::__construct();
        $message = Mage::helper('sales')->__('Are you sure you want to delete this order?');
        $this->_addButton('button_id', array(
            'label'     => Mage::helper('Sales')->__('Delete Order'),
            'onclick'   => 'deleteConfirm(\''.$message.'\', \'' . $this->getDeleteUrl() . '\')',
            'class'     => 'go'
        ), 0, 100, 'header', 'header');
    }

    public function getDeleteUrl()
    {
        return $this->getUrl('*/deleteorder/delete', array('_current'=>true));
    }   

}

I tried this code in Bluedart module, but that didt worked for me : class Bluedart_Shipment_Block_Sales_Order_View extends Raveinfosys_Deleteorder_Block_Adminhtml_Sales_Order_View

2
  • Did you declare new class in your config.xml
    – Magento 2
    Commented Aug 22, 2017 at 7:06
  • @Kothari seems module developers already declared.... here is config.xml code : pastebin.com/b1kNYzsy Commented Aug 22, 2017 at 7:08

1 Answer 1

1

Since both modules are trying to rewrite the same class, you have 2 choices

  • Remove the rewrite in the Raveinfosys/Deleteorder config file and make sure your Bluedart_Shipment_Block_Sales_Order_View class inherits from Raveinfosys_Deleteorder_Block_Adminhtml_Sales_Order_View
  • Use the <depends> in your config xml in app/etc/module to make your module depend on the Raveinfosys/Deleteorder.

Edit: for below comments Clarity For the first option - remove

<rewrite>
<sales_order_view>Raveinfosys_Deleteorder_Block_Adminhtml_Sales_Order_View</sales_order_view>
</rewrite>

from the Raveinfosys config xml file.

14
  • I tried 2nd option and added code in bludedart module in app/etc/modules/Bluedart_Shipment.xml as <depends> <Mage_Shipping /> <Mage_Api /> <Raveinfosys_Deleteorder /> </depends> , but now delete order button not displaying in sales> order > view page, but generate bluedart shipment button displaying..... Commented Aug 22, 2017 at 7:43
  • full code for : app/etc/modules/Bluedart_Shipment.xml = > pastebin.com/KXrkBzis Commented Aug 22, 2017 at 7:46
  • Does your Bluedart_Shipment_Block_Sales_Order_View class still inherit from Raveinfosys_Deleteorder_Block_Adminhtml_Sales_Order_View ? Commented Aug 22, 2017 at 7:48
  • No, i guess now Bluedart_Shipment_Block_Sales_Order_View override the Raveinfosys_Deleteorder_Block_Adminhtml_Sales_Order_View Commented Aug 22, 2017 at 7:50
  • also you told me to add <depends> code in app/etc/module/config.xml but i added in app/etc/module/Bluedart_Shipment.xml file, is that cause the override ? Commented Aug 22, 2017 at 7:51

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.