【问题标题】:Magento - Add new tab to admin Customer Edit & include form from modelMagento - 将新选项卡添加到管理员客户编辑并包含模型中的表单
【发布时间】:2023-03-07 06:08:01
【问题描述】:

我正在尝试在 Magento 管理员的“客户编辑”页面中添加一个新选项卡,并且该选项卡上有一个使用模型加载和保存数据的表单。

我的标签可以像这样正常工作(但我很确定这种方式真的很糟糕):

Sulman/Tabtest/Block/Adminhtml/Customer/Edit/Tab/Action.php

    public function __construct()
    {
        $this->setTemplate('tabtest/action.phtml');
    }

    public function getCustomtabInfo(){
        $customer = Mage::registry('current_customer');
        $customtab='My test tab';
        return $customtab;
    }
    /**
     * Return Tab label
     *
     * @return string
     */
    public function getTabLabel()
    {
        return $this->__('Sulman Test Tab');
    }
    /**
     * Return Tab title
     *
     * @return string
     */
    public function getTabTitle()
    {
        return $this->__('Sulman Test Tab Title');
    }
    /**
     * 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';
    }
}

然后我的 etc/config.xml 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Sulman_Tabtest>
            <version>0.0.1</version>
        </Sulman_Tabtest>
    </modules>
    <adminhtml>
        <layout>
            <updates>
                <tabtest>
                    <file>tabtest.xml</file>
                </tabtest>
            </updates>
        </layout>
    </adminhtml>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <sulman_tabtest before="Mage_Adminhtml">Sulman_Tabtest_Adminhtml</sulman_tabtest>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <global>
        <blocks>
            <tabtest>
                <class>Sulman_Tabtest_Block</class>
            </tabtest>
        </blocks>
    </global>
</config>

最后我的 tabtest/action.phtml 看起来像这样(可怕的权利......):

<?php
$customer = Mage::registry('current_customer');
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = "SELECT * FROM mytable WHERE entity_id = '".$customer->getId()."'";
$results = $read->fetchAll($sql);
?>
<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">My title</h4>
        </div>
        <div id="group_fields4" class="fieldset fieldset-wide">
            <div class="hor-scroll">
                <h3>My title</h3>
                <div>
                    <form action="<?php echo $this->getUrl('adminhtml/tabtest/update/', array('customer_id' => $customer_id)); ?>;" method="get">
                        <?php foreach($results as $result):?>
                            <p>
                                <strong><?php echo $result['email']?></strong><br/>
                                Max Order Amount: <input type="text" name="max_order_amount" value="<?php echo $result['max_order_amount']?>"><br/>
                            </p>
                        <?php endforeach; ?>
                        <input type="submit" value="Post This Form"/>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

然后我将设置一个 updateAction 控制器来处理帖子,更新数据库等并重定向......

坦率地说,这一切看起来都是一种非常糟糕的做法...... 我已经在谷歌和这里搜索过,但找不到真正的解决方案。我也试图通过 Magento Core 追踪。我也试图找到一个 Magento 连接模块,这样我就可以研究它!

我确实需要一个 tab_form 并以这种方式设置它,但我找不到这样做的方法。

有人指出我正确的方向吗?谢谢。

【问题讨论】:

    标签: magento


    【解决方案1】:

    您可以通过应用下面文章中给出的代码来尝试。

    http://mydons.com/how-to-add-custom-tabs-to-magento-customer-edit-page/

    【讨论】:

    • 谢谢,但这和我的几乎一模一样(我也用过),我确信实现这一目标的方法完全错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 2019-03-13
    • 2013-05-13
    • 1970-01-01
    相关资源
    最近更新 更多