0

I have to rename "Cancel" button to "Cancel Whole Order" in sales->order->view in admin panel. Currently "Cancel" button is being created in

class Mage_Adminhtml_Block_Sales_Order_View extends Mage_Adminhtml_Block_Widget_Form_Container {......}

and I am adding some new buttons to grid as following

class AG_ABC_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {

public function __construct() {

    parent::__construct();
    $this->_addButton('button_id', array(
        'label' => Mage::helper('ag_abc')->__('ABC - Generate All'),
        'onclick' => "pdfAllClick('" . $this->getOrder()->getIncrementId() . "','" . Mage::helper('ag_abc/abc')->getItemDataUrl() . "','" . Mage::helper('ag_abc/abc')->getUrl() . "')",
        'class' => 'go'
            ), 0, 100, 'header', 'header');
    $this->_addButton('delete_order_id', array(
        'label' => Mage::helper('sales')->__('Delete selected line item(s)'),
        'onclick' => "deleteOrderItem('" . $this->getOrder()->getIncrementId() . "','" . Mage::helper("adminhtml")->getUrl("/custom/deleteOrderItem/") . "')",
        'class' => 'go'
    ));
}}

What should I do. I don't want to override the functionality.I just need to change the label of button. How can I override label.

9
  • I have seen some articles about rename/remove "Add new" button, But those techniques are not working for me. Dec 15, 2015 at 11:49
  • 1
    If you just want to rename, try with translation files.
    – Prateek
    Dec 15, 2015 at 12:14
  • That's not helping me Dec 15, 2015 at 12:39
  • Then, please elaborate, what have you tried so far, and what errors you are facing in that.
    – Prateek
    Dec 15, 2015 at 12:59
  • 1
    That label comes from Mage_Adminhtml_Block_Sales_Order_View class. If you take a look at it, you can see that the label is parsed via Sales helper. So, in case of just a rename, all you have to do is, create your own translation file and map the word "Cancel" to whatever you want. If you don't want that way, then you can extend the class and re-write the constructor and in there you can change the label of the button.
    – Prateek
    Dec 15, 2015 at 13:20

1 Answer 1

0

@Prateek thank you man. You guided me to right direction. What I have found is that I was missing to add

$this->setId('sales_order_view');

in my class before rewiring this button. So now my class look like this.

class AG_ABC_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {

public function __construct() {

    parent::__construct();

    $this->setId('sales_order_view');
    $order = $this->getOrder();
    $this->_removeButton('order_cancel'); // Remove old button having label "Cancel" placed in parent class

    if ($this->_isAllowedAction('cancel') && $order->canCancel()) {
        $message = Mage::helper('sales')->__('Are you sure you want to cancel this order?');
        $this->_addButton('order_cancel', array(
            'label' => Mage::helper('sales')->__('Cancel entire order'),
            'onclick' => 'deleteConfirm(\'' . $message . '\', \'' . $this->getCancelUrl() . '\')',
        ));
    }
    $this->_addButton('button_id', array(
        'label' => Mage::helper('ag_abc')->__('ABC - Generate All'),
        'onclick' => "pdfAllClick('" . $this->getOrder()->getIncrementId() . "','" . Mage::helper('ag_abc/abc')->getItemDataUrl() . "','" . Mage::helper('ag_abc/abc')->getUrl() . "')",
        'class' => 'go'
            ), 0, 100, 'header', 'header');
    $this->_addButton('delete_order_id', array(
        'label' => Mage::helper('sales')->__('Delete selected line item(s)'),
        'onclick' => "deleteOrderItem('" . $this->getOrder()->getIncrementId() . "','" . Mage::helper("adminhtml")->getUrl("/custom/deleteOrderItem/") . "')",
        'class' => 'go'
    ));
}}

Label of button has been chnaged from "Cancel" to "Cancel entire order"

1
  • Feel free to accept your own answer, so that the question does not count as unanswered anymore Jan 17, 2016 at 23:15

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.