Magento 1.6 在后端为客户编辑添加选项卡
Magento 1.6 add tab to customer edit on back end
我一直在尝试向 Magento CE 1.6 中的“客户信息”页面添加一个选项卡。
我尝试了以下示例:
- how to add custom tabs to magento customer edit page 在 mydons.com
- how to add tab in customer information in magento admin 在 nextbits.eu
- how to add tab in customer information 在 ankursphp.blogspot.com
最后一个是唯一一个似乎接近的。然而,它有两个问题。一是它编辑核心文件,二是当我单击选项卡时它会旋转和染色。 Chrome DevTools 显示服务器报告 404。
任何人都可以向我提供一些与 Magento 1.6 兼容的体面的文档或代码吗?
编辑 添加最后一个 link 的文本,因为这似乎是唯一一个远程工作的文本。
覆盖文件/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php
,在_beforeToHtml()
方法里面,添加如下代码:
$this->addTab('Custom',array(
'label' =>Mage::helper('customer')->__('Custom'),
'class' => 'ajax',
'url' => $this->getUrl('*/*/custom',array('_current'=>true)),
));
覆盖文件/app/code/core/Mage/Adminhtml/controllers/CustomerController.php
,添加以下代码:
public function customAction()
{ $this->_initCustomer();
$this->getResponse()->setBody(
Mage::app()->getLayout()->createBlock('core/template')->setTemplate('custom/customer/tab/custom.phtml')->setCustomerId(Mage::registry('current_customer')->getId())
->setUseAjax(true)->toHtml()
);
}
创建文件/app/code/core/Namespace/ModuleName/Block/Adminhtml/Customer/Edit/Tab/
并创建Custom.php
,在文件中添加以下源代码:
<?php
class Custom_Custom_Block_Adminhtml_Customer_Edit_Tab_Custom extends Mage_Adminhtml_Block_Widget_Form
{
public function __construct()
{
parent::__construct();
$this->setTemplate('custom/customer/tab/custom.phtml');
}
}
?>
现在,您需要创建一个模板文件。转到 /app/design/adminhtml/default/default/template/modulename/customer/tab/
并创建 custom.phtml
、
app/code/local/Namespace/Module/etc/config.xml:确保你声明了你的块别名和你的 adminhtml 布局文件:
<config>
...
<global>
...
<blocks>
<namespace_module>
<class>Namespace_Module_Block</class>
</namespace_module>
</blocks>
...
</global>
...
<adminhtml>
...
<layout>
<updates>
<namespace_module>
<file>namespace/module.xml</file>
</namespace_module>
</updates>
</layout>
...
</adminhtml>
...
</config>
app/design/adminhtml/default/default/layout/namespace/module.xml: 声明你的新标签
<layout version="0.1.0">
...
<adminhtml_customer_edit>
<reference name="customer_edit_tabs">
<action method="addTabAfter">
<name>custom_tab</name><!--can be anything you want-->
<block>namespace_module/adminhtml_customer_edit_tab_custom</block>
<after>account</after><!-- after which tab do you want it -->
</action>
</reference>
</adminhtml_customer_edit>
...
</layout>
app/code/local/Namespace/Module/Block/Adminhtml/Customer/Edit/Tab/Custom.php: 这是你的街区 class
<?php
class Namespace_Module_Block_Adminhtml_Customer_Edit_Tab_Custom
extends Mage_Adminhtml_Block_Widget_Form
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
public function __construct()
{
parent::__construct();
$this->setTemplate('namespace/module.phtml');
}
public function getTabLabel()
{
return Mage::helper('namespace_module')->__('Tab Label');
}
public function getTabTitle()
{
return Mage::helper('namespace_module')->__('Tab Title');
}
public function canShowTab()
{
return true;
}
public function isHidden()
{
return false;
}
}
app/design/adminhtml/default/default/template/namespace/module.phtml:选项卡内容:
enter html code here
设法找到一些无需任何修改即可工作的开箱即用代码作为起点:
http://www.engine23.com/magento-how-to-create-custom-customer-tab-and-submit-a-form.html
app/etc/modules/Russellalbin_Customertab.xml
<?xml version="1.0"?>
<config>
<modules>
<Russellalbin_Customertab>
<active>true</active>
<codePool>local</codePool>
</Russellalbin_Customertab>
</modules>
</config>
app/etc/local/Russellalbin/Customertab/etc/config.xml
<config>
<modules>
<Russellalbin_Customertab>
<version>0.0.1</version>
</Russellalbin_Customertab>
</modules>
<adminhtml>
<layout>
<updates>
<customertab>
<file>customertab.xml</file>
</customertab>
</updates>
</layout>
</adminhtml>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<russellalbin_customertab before="Mage_Adminhtml">Russellalbin_Customertab_Adminhtml</russellalbin_customertab>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<global>
<blocks>
<customertab>
<class>Russellalbin_Customertab_Block</class>
</customertab>
</blocks>
</global>
</config>
app/code/local/Russellalbin/Customertab/Block/Adminhtml/Customer/Edit/Tab/Action.php
/**
* Adminhtml customer action tab
*
*/
class Russellalbin_Customertab_Block_Adminhtml_Customer_Edit_Tab_Action
extends Mage_Adminhtml_Block_Template
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
public function __construct()
{
$this->setTemplate('customertab/action.phtml');
}
public function getCustomtabInfo()
{
$customer = Mage::registry('current_customer');
$customtab = 'Mail Order Comics Pull List';
return $customtab;
}
/**
* Return Tab label
*
* @return string
*/
public function getTabLabel()
{
return $this->__('Customer Pull List');
}
/**
* Return Tab title
*
* @return string
*/
public function getTabTitle()
{
return $this->__('Pull List Tab');
}
/**
* Can show tab in tabs
*
* @return boolean
*/
public function canShowTab()
{
$customer = Mage::registry('current_customer');
return (bool)$customer->getId();
}
/**
* Tab is hidden
*
* @return boolean
*/
public function isHidden()
{
return false;
}
/**
* Defines after which tab, this tab should be rendered
*
* @return string
*/
public function getAfter()
{
return 'tags';
}
}
app/code/local/Russellalbin/Customertab/controllers/Adminhtml/CustomertabController.php
class Russellalbin_Customertab_Adminhtml_CustomertabController extends Mage_Adminhtml_Controller_Action
{
function resetAction()
{
$params = array();
$path = 'customer';
$customer_id = (int)$this->getRequest()->getParam('customer_id');
if($customer_id)
{
// Do your stuff here
$params['id'] = $customer_id;
$params['back'] = 'edit';
$params['tab'] = 'customer_edit_tab_action';
$path = 'adminhtml/customer/edit/';
}
$params['_store'] = Mage::getModel('core/store')->load(0);
$url = Mage::getModel('adminhtml/url')->getUrl($path, $params);
Mage::app()
->getResponse()
->setRedirect($url);
Mage::app()
->getResponse()
->sendResponse();
exit;
}
}
app/design/adminhtml/default/default/layout/customertab.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<adminhtml_customer_edit>
<reference name="customer_edit_tabs">
<action method="addTab">
<name>customer_edit_tab_action</name>
<block>customertab/adminhtml_customer_edit_tab_action</block>
</action>
</reference>
</adminhtml_customer_edit>
</layout>
app/design/adminhtml/default/default/template/customertab/action.phtml
<div id="customer_info_tabs_customer_edit_tab_action_content">
<div class="entry-edit">
<div class="entry-edit-head">
<h4 class="icon-head head-edit-form fieldset-legend">Pull List</h4>
</div>
<div id="group_fields4" class="fieldset fieldset-wide">
<div class="hor-scroll">
<h2>This is my form and content that I can submit and return back to this page and tab</h2>
<div><form action="<?php echo $this->getUrl('adminhtml/customertab/reset/', array('customer_id'=> $customer_id)); ?>" method="get"><input type="submit" value="Post This Form" /></form></div>
</div>
</div>
</div>
</div>
我一直在尝试向 Magento CE 1.6 中的“客户信息”页面添加一个选项卡。
我尝试了以下示例:
- how to add custom tabs to magento customer edit page 在 mydons.com
- how to add tab in customer information in magento admin 在 nextbits.eu
- how to add tab in customer information 在 ankursphp.blogspot.com
最后一个是唯一一个似乎接近的。然而,它有两个问题。一是它编辑核心文件,二是当我单击选项卡时它会旋转和染色。 Chrome DevTools 显示服务器报告 404。
任何人都可以向我提供一些与 Magento 1.6 兼容的体面的文档或代码吗?
编辑 添加最后一个 link 的文本,因为这似乎是唯一一个远程工作的文本。
覆盖文件
/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tabs.php
,在_beforeToHtml()
方法里面,添加如下代码:$this->addTab('Custom',array( 'label' =>Mage::helper('customer')->__('Custom'), 'class' => 'ajax', 'url' => $this->getUrl('*/*/custom',array('_current'=>true)), ));
覆盖文件
/app/code/core/Mage/Adminhtml/controllers/CustomerController.php
,添加以下代码:public function customAction() { $this->_initCustomer(); $this->getResponse()->setBody( Mage::app()->getLayout()->createBlock('core/template')->setTemplate('custom/customer/tab/custom.phtml')->setCustomerId(Mage::registry('current_customer')->getId()) ->setUseAjax(true)->toHtml() ); }
创建文件
/app/code/core/Namespace/ModuleName/Block/Adminhtml/Customer/Edit/Tab/
并创建Custom.php
,在文件中添加以下源代码:<?php class Custom_Custom_Block_Adminhtml_Customer_Edit_Tab_Custom extends Mage_Adminhtml_Block_Widget_Form { public function __construct() { parent::__construct(); $this->setTemplate('custom/customer/tab/custom.phtml'); } } ?>
现在,您需要创建一个模板文件。转到
/app/design/adminhtml/default/default/template/modulename/customer/tab/
并创建custom.phtml
、
app/code/local/Namespace/Module/etc/config.xml:确保你声明了你的块别名和你的 adminhtml 布局文件:
<config> ... <global> ... <blocks> <namespace_module> <class>Namespace_Module_Block</class> </namespace_module> </blocks> ... </global> ... <adminhtml> ... <layout> <updates> <namespace_module> <file>namespace/module.xml</file> </namespace_module> </updates> </layout> ... </adminhtml> ... </config>
app/design/adminhtml/default/default/layout/namespace/module.xml: 声明你的新标签
<layout version="0.1.0"> ... <adminhtml_customer_edit> <reference name="customer_edit_tabs"> <action method="addTabAfter"> <name>custom_tab</name><!--can be anything you want--> <block>namespace_module/adminhtml_customer_edit_tab_custom</block> <after>account</after><!-- after which tab do you want it --> </action> </reference> </adminhtml_customer_edit> ... </layout>
app/code/local/Namespace/Module/Block/Adminhtml/Customer/Edit/Tab/Custom.php: 这是你的街区 class
<?php class Namespace_Module_Block_Adminhtml_Customer_Edit_Tab_Custom extends Mage_Adminhtml_Block_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface { public function __construct() { parent::__construct(); $this->setTemplate('namespace/module.phtml'); } public function getTabLabel() { return Mage::helper('namespace_module')->__('Tab Label'); } public function getTabTitle() { return Mage::helper('namespace_module')->__('Tab Title'); } public function canShowTab() { return true; } public function isHidden() { return false; } }
app/design/adminhtml/default/default/template/namespace/module.phtml:选项卡内容:
enter html code here
设法找到一些无需任何修改即可工作的开箱即用代码作为起点:
http://www.engine23.com/magento-how-to-create-custom-customer-tab-and-submit-a-form.html
app/etc/modules/Russellalbin_Customertab.xml
<?xml version="1.0"?>
<config>
<modules>
<Russellalbin_Customertab>
<active>true</active>
<codePool>local</codePool>
</Russellalbin_Customertab>
</modules>
</config>
app/etc/local/Russellalbin/Customertab/etc/config.xml
<config>
<modules>
<Russellalbin_Customertab>
<version>0.0.1</version>
</Russellalbin_Customertab>
</modules>
<adminhtml>
<layout>
<updates>
<customertab>
<file>customertab.xml</file>
</customertab>
</updates>
</layout>
</adminhtml>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<russellalbin_customertab before="Mage_Adminhtml">Russellalbin_Customertab_Adminhtml</russellalbin_customertab>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<global>
<blocks>
<customertab>
<class>Russellalbin_Customertab_Block</class>
</customertab>
</blocks>
</global>
</config>
app/code/local/Russellalbin/Customertab/Block/Adminhtml/Customer/Edit/Tab/Action.php
/**
* Adminhtml customer action tab
*
*/
class Russellalbin_Customertab_Block_Adminhtml_Customer_Edit_Tab_Action
extends Mage_Adminhtml_Block_Template
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
public function __construct()
{
$this->setTemplate('customertab/action.phtml');
}
public function getCustomtabInfo()
{
$customer = Mage::registry('current_customer');
$customtab = 'Mail Order Comics Pull List';
return $customtab;
}
/**
* Return Tab label
*
* @return string
*/
public function getTabLabel()
{
return $this->__('Customer Pull List');
}
/**
* Return Tab title
*
* @return string
*/
public function getTabTitle()
{
return $this->__('Pull List Tab');
}
/**
* Can show tab in tabs
*
* @return boolean
*/
public function canShowTab()
{
$customer = Mage::registry('current_customer');
return (bool)$customer->getId();
}
/**
* Tab is hidden
*
* @return boolean
*/
public function isHidden()
{
return false;
}
/**
* Defines after which tab, this tab should be rendered
*
* @return string
*/
public function getAfter()
{
return 'tags';
}
}
app/code/local/Russellalbin/Customertab/controllers/Adminhtml/CustomertabController.php
class Russellalbin_Customertab_Adminhtml_CustomertabController extends Mage_Adminhtml_Controller_Action
{
function resetAction()
{
$params = array();
$path = 'customer';
$customer_id = (int)$this->getRequest()->getParam('customer_id');
if($customer_id)
{
// Do your stuff here
$params['id'] = $customer_id;
$params['back'] = 'edit';
$params['tab'] = 'customer_edit_tab_action';
$path = 'adminhtml/customer/edit/';
}
$params['_store'] = Mage::getModel('core/store')->load(0);
$url = Mage::getModel('adminhtml/url')->getUrl($path, $params);
Mage::app()
->getResponse()
->setRedirect($url);
Mage::app()
->getResponse()
->sendResponse();
exit;
}
}
app/design/adminhtml/default/default/layout/customertab.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<adminhtml_customer_edit>
<reference name="customer_edit_tabs">
<action method="addTab">
<name>customer_edit_tab_action</name>
<block>customertab/adminhtml_customer_edit_tab_action</block>
</action>
</reference>
</adminhtml_customer_edit>
</layout>
app/design/adminhtml/default/default/template/customertab/action.phtml
<div id="customer_info_tabs_customer_edit_tab_action_content">
<div class="entry-edit">
<div class="entry-edit-head">
<h4 class="icon-head head-edit-form fieldset-legend">Pull List</h4>
</div>
<div id="group_fields4" class="fieldset fieldset-wide">
<div class="hor-scroll">
<h2>This is my form and content that I can submit and return back to this page and tab</h2>
<div><form action="<?php echo $this->getUrl('adminhtml/customertab/reset/', array('customer_id'=> $customer_id)); ?>" method="get"><input type="submit" value="Post This Form" /></form></div>
</div>
</div>
</div>
</div>