2

I know this has been asked so many times before however I more so have a question.

I am copying the file

/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php

and putting it in

/app/code/local/Mage/Adminhtml/Block/Customer/Edit/Tabs.php

I then edit the Tabs.php to have a new tab however when I refresh my screen, I even logged out cleared my cache and logged back in Magento does not seem to read from the app/code/local/mage directory?

However if I make the same changes in the file located in the core folder my changes work? So why can I not more the file to the local file?

I am using Magento CE 1.9.1.0 Shouldn't I be able to copy any file into the local directory and as long as the folder structure is the same it should load it??

5

I think none of the other answers (at this time) does it 'the Magento way'. To know how to do it the Magento way, have a look at Magento's Billing Agreements. It adds a tab to the customer edit page as well.

First, app/design/adminhtml/default/default/layout/sales.xml:

<adminhtml_customer_edit>
    <reference name="customer_edit_tabs">
        <action method="addTab"><name>customer_edit_tab_agreements</name><block>sales/adminhtml_customer_edit_tab_agreement</block></action>
        ....
    </reference>
</adminhtml_customer_edit>

Now you wonder: I have no title or content! No problem. Have a look at the above referenced block Mage_Sales_Block_Adminhtml_Customer_Edit_Tab_Agreement (in app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php). I don't think it's useful to copy/paste the entire file here, but all the magic is there, like getTabLabel(), getTabTitle() and canShowTab(). It extends Mage_Sales_Block_Adminhtml_Billing_Agreement_Grid because there's a grid in it, but you could also extend the more general Mage_Adminhtml_Block_Widget.

You didn't mention the use of your tab, but you can even create a whole layout and then reference it by name:

<adminhtml_customer_edit>
    <reference name="customer_edit_tabs">
        <block type="my_module/adminhtml_customer_edit_tab_nameoftab" name="mytab">
            ... add some blocks here ...
        </block>
        <action method="addTab"><name>mytab</name><block>mytab</block></action>
    </reference>
</adminhtml_customer_edit>

So here's what you need to do:

  • create your own module (you've probably already done that)
  • create a layout file in the adminhtml area to add the tab, specifying the block class
  • create the block in your module and create the functions required by the interface (Mage_Adminhtml_Block_Widget_Tab_Interface)

No need for event observers, no need for local overrides, no need for editing the core!

2

Override the file /app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php,

Inside _beforeToHtml() method, add the following code:

$this->addTab('Custom',array(
    'label' =>Mage::helper('customer')->__('Custom'),
    'class' =>   'ajax',
    'url'   =>   $this->getUrl('*/*/custom',array('_current'=>true)),
));

Override the file /app/code/core/Mage/Adminhtml/controllers/CustomerController.php,

Add the following code:

public function customAction()
{
    $this->_initCustomer();
    $this->getResponse()->setBody(
        $this->getLayout()->createBlock('modulename/adminhtml_customer_edit_tab_custom','admin.customer.custom')->setCustomerId(Mage::registry('current_customer')->getId())
        ->setUseAjax(true)
        ->toHtml()
    );
}

Override the file /app/code/core/Mage/Adminhtml/controllers/CustomerController.php,

public function customAction()
{
    $this->_initCustomer();
    $this->getResponse()->setBody(
        $this->getLayout()->createBlock('modulename/adminhtml_customer_edit_tab_custom','admin.customer.custom')->setCustomerId(Mage::registry('current_customer')->getId())
        ->setUseAjax(true)
        ->toHtml()
    );
}

Create the file /app/code/core/Namespace/ModuleName/Block/Adminhtml/Customer/Edit/Tab/ and create Custom.php,

class Namespace_ModuleName_Block_Adminhtml_Customer_Edit_Tab_Custom extends Mage_Adminhtml_Block_Widget_Form
{
    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('modulename/customer/tab/custom.phtml');
    }
}

Now, you need to create a template file.

Go to /app/design/adminhtml/default/default/template/modulename/customer/tab/ and create custom.phtml,

Write your code here.

Please visit link for more methods to add custom TAB.

http://www.nextbits.eu/blog/how-to-add-tab-in-customer-information-in-magento-admin/

I hope this will help you.

0

Shouldn't I be able to copy any file into the local directory and as long as the folder structure is the same it should load it?

No, not if you have compilation enabled. Look at top of /app/Mage.php

  • Check in backend for 'Compilation' is disabled (Or re-compile).
  • Check /includes/Config.php, if everything is commented out.

Good luck with overriding Magento Core Files.

Ps: Magento is configuration based and event driven system.

<adminhtml>
    ...
    <events>
       <core_block_abstract_prepare_layout_after>
            <observers>
                <[namespace]_[module]_product>
                    <type>singleton</type>
                    <class>[module]/adminhtml_observer</class>
                    <method>addProductTabBlock</method>
                </[namespace]_[module]_product>
            </observers>
       </core_block_abstract_prepare_layout_after>
    </events>
    ....
</adminhtml>
0

Add new custom tab in the Magento Customer Grid by overriding it in our custom module.

To override magento customer grid go to your custom module config.xml

<config>
 <global>
  <blocks>
   <adminhtml>
    <rewrite>
   <customer_edit_tabs>Stack_modulename_Block_Adminhtml_Customer_Edit_Tabs</customer_edit_tabs>
    </rewrite>
   </adminhtml>
  </blocks>
 </global>
</config>
  1. Create a file tabs.php at following path

app/code/local/Webkul/Modulename/Block/Adminhtml/Customer/Edit/

  1. Copy the entire code from this file

app/code/core/Mage/Adminhtml/Block/Customer/Edit/tabs.php

to your tabs.php (app/code/local/Webkul/Modulename/Block/Adminhtml/Customer/Edit/)

  1. Add this code to create new tab

$this->addTab('payment', array( 'label' => Mage::helper('customer')->__('Payment Mode'), 'content' => $this->paymentmode(), ));

protected function _beforeToHtml() {  
  if (Mage::registry('current_customer')->getId()) 
        {
         $this->addTab('payment', array(
                'label'=> Mage::helper('customer')->__('Payment Mode'),
                'content'=> $this->paymentmode(),
            ));    
         }
       }

/note: in 'content' you can pass a string or function/

/* write these line after completion of function

protected function _beforeToHtml(){}

protected function paymentmode()
{ 
 return 'Your content Come Here';
}

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.