【问题标题】:How can i add new tab in sales order view in Magento如何在 Magento 的销售订单视图中添加新标签
【发布时间】:2014-06-06 11:58:09
【问题描述】:

Reference article


将上面的代码sn-p改成这个,在销售订单视图中添加一个标签

<?xml version="1.0"?>
 <layout>
    <adminhtml_sales_order_view>
       <reference name="sales_order_tabs">
           <action method="addTab">
               <name>my_custom_tab</name>
               <block>customtabs/adminhtml_sales_order_tab</block>
           </action>
       </reference>
    </adminhtml_sales_order_view>
</layout>

<?php

class Fishpig_Customtabs_Block_Adminhtml_Sales_Order_Tab
extends Mage_Adminhtml_Block_Template
implements Mage_Adminhtml_Block_Widget_Tab_Interface {

重要:一定要改变目录结构

【问题讨论】:

  • 你的问题是什么?
  • 这似乎是一个自我回答的问题。

标签: php xml magento


【解决方案1】:

在 Magento 2 中,管理面板中的销售订单页面中,许多选项卡都可以由本机使用,例如信息、发票、发货、贷项备忘录、交易和评论历史记录。

对于您的自定义要求,您需要在订单页面中添加额外的选项卡,您可以通过简单的模块在管理订单视图页面中添加自定义选项卡。

您需要创建简单的模块来添加额外的选项卡。

请参考下面的代码 sn-p 添加额外的选项卡, 为简单起见,我将 Rbj 作为包名称,将 OrderTab 作为模块名称。 您需要创建第一个 registration.phpmodule.xml 文件来定义我们的模块。

路径:app/code/Rbj/OrderTab/registration.php

<?php
   \Magento\Framework\Component\ComponentRegistrar::register(
   \Magento\Framework\Component\ComponentRegistrar::MODULE,
   'Rbj_OrderTab',
   __DIR__
);

创建module.xml文件,路径:app/code/Rbj/OrderTab/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Rbj_OrderTab" setup_version="2.0.0">
        <sequence>
            <module name="Magento_Sales"/>
        </sequence>
    </module>
</config>

我们添加了对 Magento 销售模块的依赖项以添加新选项卡。所以我们在上述 XML 文件的序列标签中定义了 Magento_Sales 模块。

现在来到模块的主要入口点, 对于添加新标签,我们必须覆盖 sales_order_view.xml 文件以添加我们添加自定义标签的逻辑。

参考块 sales_order_tabs 包含选项卡列表。所以我们需要在我们的模块中创建 sales_order_view.xml 文件,路径如下,

路径:app/code/Rbj/OrderTab/view/adminhtml/layout/sales_order_view.xml

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="sales_order_tabs">
            <action method="addTab">
                <argument name="name" xsi:type="string">custom_tabs</argument>
                <argument name="block" xsi:type="string">Rbj\OrderTab\Block\Adminhtml\OrderEdit\Tab\View</argument>
            </action>
        </referenceBlock>
    </body>
</page>

在上面的文件中,我们已经声明了块文件来设置你的自定义逻辑,你想在自定义选项卡中显示。

新建一个Block PHP文件,路径:app/code/Rbj/OrderTab/Block/Adminhtml/OrderEdit/Tab/View.php

<?php
namespace Rbj\OrderTab\Block\Adminhtml\OrderEdit\Tab;

/**
 * Order custom tab
 *
 */
class View extends \Magento\Backend\Block\Template implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
    protected $_template = 'tab/view/my_order_info.phtml';

    /**
     * View constructor.
     * @param \Magento\Backend\Block\Template\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Registry $registry,
        array $data = []
    ) {
        $this->_coreRegistry = $registry;
        parent::__construct($context, $data);
    }

    /**
     * Retrieve order model instance
     *
     * @return \Magento\Sales\Model\Order
     */
    public function getOrder()
    {
        return $this->_coreRegistry->registry('current_order');
    }
    /**
     * Retrieve order model instance
     *
     * @return \Magento\Sales\Model\Order
     */
    public function getOrderId()
    {
        return $this->getOrder()->getEntityId();
    }

    /**
     * Retrieve order increment id
     *
     * @return string
     */
    public function getOrderIncrementId()
    {
        return $this->getOrder()->getIncrementId();
    }
    /**
     * {@inheritdoc}
     */
    public function getTabLabel()
    {
        return __('My Custom Tab');
    }

    /**
     * {@inheritdoc}
     */
    public function getTabTitle()
    {
        return __('My Custom Tab');
    }

    /**
     * {@inheritdoc}
     */
    public function canShowTab()
    {
        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function isHidden()
    {
        return false;
    }
}

在上面的文件中,我们可以使用 $_template 变量来声明一个模板文件。

protected $_template = 'tab/view/my_order_info.phtml' 用于我们自定义标签的模板文件。

您可以通过getTabLabel() 设置自定义标签标签,并使用getTabTitle() 函数设置标题。您可以在上述文件中根据您的要求定义自定义函数。

您可以通过调用Magento\Framework\Registry对象获取当前订单数据。

现在我们需要创建模板文件, 路径:app/code/Rbj/OrderTab/view/adminhtml/templates/tab/view/my_order_info.phtml

<?php
/**
 * @var $block \Rbj\OrderTab\Block\Adminhtml\OrderEdit\Tab\View
 */
?>

<div class="fieldset-wrapper order-information">
    <div class="fieldset-wrapper-title">
        <span class="title"><?php /* @escapeNotVerified */
            echo __('Information for new Order tab') ?></span>
    </div>
    <table class="admin__table-secondary">
        <tbody>
        <?php echo $block->getChildHtml(); ?>
        <tr>
            <th><?php /* @escapeNotVerified */
                echo __('Order ID:') ?></th>
            <td><?php echo $block->getOrderIncrementId(); ?></td>
        </tr>
        <tr>
            <th><?php /* @escapeNotVerified */
                echo __('Last History:') ?></th>
            <td><?php echo __('History of order') ?></td>
        </tr>
        </tbody>
    </table>
</div>

现在运行升级命令来安装我们的模块。

php bin/magento 设置:升级 php bin/magento 缓存:刷新

现在转到管理面板,使用您的凭据登录, 点击左侧边栏,Sales -> Order 链接, 单击任何订单,您可以在订单视图页面中将最后一个选项卡作为新的自定义选项卡。

检查销售订单页面中的自定义选项卡,

Tnx

【讨论】:

    【解决方案2】:

    看看@Custom tab on sales order viewHow to create sales order custom tab in magento 1.8.0.1

    文件夹结构应该是(如果需要,请将 Fishpig 替换为您添加到 local 的文件夹名称

    Fishpig_Customtabs_Block_Adminhtml_Sales_Order_Tab /app/code/local/Fishpig/Customtabs/[Block/dminhtml/Sales/Order/Tab]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-13
      • 2017-04-17
      • 1970-01-01
      • 2013-06-07
      相关资源
      最近更新 更多