0

I want add a new button in customer edit page.

Here: Add button

Between Reset and Create Order.

I try override "Mage_Adminhtml_Block_Customer_Edit" but when go to the customer edit page return this error:

error

This is my config.xml:

    <?xml version="1.0"?>
<config>
    <modules>
        <company_unblock>
            <version>1.0.0</version>
            <depends>
                <!-- no dependencies -->
            </depends>
        </company_unblock>
    </modules>
    <global>
        <models />
        <blocks>
            <adminhtml>
                <rewrite>                   
                    <customer_edit>Company_Unblock_Block_Adminhtml_Customer_Edit</customer_edit>
                </rewrite>
            </adminhtml>
        </block>
        <resources />
        <extraconfig />
        <helpers>
            <unblock>
                <class>Company_Unblock_Helper</class>
            </unblock>
        </helpers>
    </global>
    <admin>
        <routers>
            <company_unblock>
                <use>admin</use>
                <args>
                    <module>Company_Unblock</module>
                    <frontName>unblock</frontName>
                </args>
            </company_unblock>
        </routers>
    </admin>
</config>

In the Block override only modify function construct:

class Company_Unblock_Block_Adminhtml_Customer_Edit extends Mage_Adminhtml_Block_Customer_Edit
{
    public function __construct()
    {
        $this->_objectId = 'id';
        $this->_controller = 'customer';

        if ($this->getCustomerId() && 
            Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/create')) {
            $this->_addButton('order', array(
                'label' => Mage::helper('customer')->__('Create Order'),
                'onclick' => 'setLocation(\'' . $this->getCreateOrderUrl() . '\')',
                'class' => 'add',
            ), 0);

        }

        parent::__construct();

        $this->_updateButton('save', 'label', Mage::helper('customer')->__('Save Customer'));
        $this->_updateButton('delete', 'label', Mage::helper('customer')->__('Delete Customer'));

        if (Mage::registry('current_customer')->isReadonly()) {
            $this->_removeButton('save');
            $this->_removeButton('reset');
        }

        if (!Mage::registry('current_customer')->isDeleteable()) {
            $this->_removeButton('delete');
        }
    }
}

Can you help me?

0
1

Can I add a custom button without override? – str_lml

You can add buttons via event/observer ...

<adminhtml_widget_container_html_before>
    <observers>
        <add_some_buttons>
            <class>[module]/observer</class>
            <method>addButton</method>
        </add_some_buttons>
    </observers>
</adminhtml_widget_container_html_before>

Observer:

public function addButton(Varien_Event_Observer $observer)
{
    if ($observer->getBlock()->getType() != 'adminhtml/customer_edit') {
        return;
    }

    $data = array(
        'label'     => '...',
        'onclick'   => '...',
    );
    $observer->getBlock()->addButton('your_button', $data);
}

For the correct position, see Mage_Adminhtml_Block_Widget_Container::addButton()

public function addButton($id, $data, $level = 0, $sortOrder = 0, $area = 'header')
0
1

In your config.xml below code is there if its not used then remove it

<helpers>
    <unblock>
    <class>Company_Unblock_Helper</class>
    </unblock>
</helpers>

or create a helper classs

in app/code/[codePool]/Company/Unblock/Helper and put below code in Data.php

<?php

class Company_Unblock_Helper_Data extends Mage_Core_Helper_Abstract
{

}
6
  • The helper class will be needed anyway for module's translations Jun 29 '18 at 11:22
  • @simonthesorcerer , that's depends on his requirement , if he wants to translate text then yes its needed Jun 29 '18 at 11:23
  • I remove the Helper code in config.xml and in my construct i have $this->_addBUtton(".....") but don't show the new button is like don't override the function.
    – str_lml
    Jun 29 '18 at 11:31
  • Can I add a custom button without override?
    – str_lml
    Jun 29 '18 at 11:39
  • @str_lml is order is your button ??? Jun 29 '18 at 11:49

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.