Magento 1.6在后端为客户编辑添加标签

时间:2015-08-26 09:07:31

标签: php magento backend magento-1.6

我一直在尝试在Magento CE 1.6的“客户信息”页面中添加一个标签。

我尝试了以下示例:

最后一个是唯一一个甚至似乎接近的人。但是,它有两个问题。一个是它编辑核心文件,另一个是当我点击选项卡时它会旋转和染色。 Chrome DevTools显示服务器报告404。

有人能为我提供一些与Magento 1.6兼容的体面文档或代码吗?

编辑添加上一个链接中的文本,因为它似乎是唯一远程工作的文本。

  1. 覆盖文件/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)),
    ));
    
  2. 覆盖文件/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()   
    ); 
    
    }
    
  3. 创建文件/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');
    }
    }
    ?>
    
  4. 现在,您需要创建模板文件。转到/app/design/adminhtml/default/default/template/modulename/customer/tab/并创建custom.phtml

2 个答案:

答案 0 :(得分:2)

管理以跟踪一些开箱即用的代码,无需任何修改即可作为起点:

http://www.engine23.com/magento-how-to-create-custom-customer-tab-and-submit-a-form.html

应用程序的/ etc /模块/ Russellalbin_Customertab.xml

<?xml version="1.0"?>
<config>
<modules>
    <Russellalbin_Customertab>
        <active>true</active>
        <codePool>local</codePool>
    </Russellalbin_Customertab>
</modules>
</config>

应用程序的/ etc /本地/ 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>

应用程序/代码/本地/ Russellalbin / Customertab /砌块/ Adminhtml /客户/编辑/标签/ 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';
    }
}

应用程序/代码/本地/ Russellalbin / Customertab /控制器/ 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;
    }

}

应用程序/设计/ adminhtml /默认/默认/布局/ 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>

应用程序/设计/ adminhtml /默认/默认/模板/ 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>

答案 1 :(得分:0)

  1. 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>
    
  2. 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>
    
  3. app / code / local / Namespace / Module / Block / Adminhtml / Customer / Edit / Tab / Custom.php :这是你的块类

    <?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;
        }
    
    }
    
  4. app / design / adminhtml / default / default / template / namespace / module.phtml :标签内容:

    enter html code here