【问题标题】:Adding an additional tab on Sales Order View page in Magento 2 Frontend在 Magento 2 前端的销售订单视图页面上添加一个附加选项卡
【发布时间】:2021-10-17 17:00:01
【问题描述】:

如何在 magento2 enter image description here 的自定义 phtml 中添加带有订单信息的自定义选项卡

到目前为止,我已经按照本教程 https://webkul.com/blog/adding-an-addition-tab-on-sales-order-view-page-frontend-magento-2/ 进行操作,但收到此错误 Call to a member function getRealOrderId() on null enter image description here

sales_order_info_links.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.info.links">
            <block class="Magento\Sales\Block\Order\Link" name="sales.order.info.links.new.tab">
                <arguments>
                    <argument name="key" xsi:type="string">tab_new</argument>
                    <argument name="path" xsi:type="string">subscription/index/index</argument>
                    <argument name="label" xsi:type="string" translate="true">Tab Label</argument>
                </arguments>
            </block>
        </referenceBlock>
      </body>
</page>

subscription_index_index.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">
    <update handle="customer_account"/>
    <update handle="sales_order_info_links"/>
    <body>
        <referenceContainer name="page.main.title">
            <block class="Magento\Sales\Block\Order\Info" name="order.status" template="Magento_Sales::order/order_status.phtml"/>
            <block class="Magento\Sales\Block\Order\Info" name="order.date" template="Magento_Sales::order/order_date.phtml"/>
            <container name="order.actions.container" htmlTag="div" htmlClass="actions-toolbar order-actions-toolbar">
                <block class="Magento\Sales\Block\Order\Info\Buttons" as="buttons" name="sales.order.info.buttons" cacheable="false"/>
            </container>
        </referenceContainer>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="tab_custom" template="Infopro_CustomSection::tab.phtml"/>
        </referenceContainer>
    </body>
</page>
Controller/Index/Index.php 

<?php
namespace Infopro\CustomSection\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
{
    public function execute()
    {
        $this->_view->loadLayout();
        $this->_view->renderLayout();
    }
}

tab.phtml

<h1>Demo</h1>

【问题讨论】:

  • 能否分享一下您的 Infopro_CustomSection 模块的代码?

标签: magento2


【解决方案1】:

我遇到了同样的问题。不过现在已经解决了。

问题出在您的Controller/Index/Index.php 文件中。

我用下面的代码替换了你的控制器代码,现在它工作正常了。

<?php
  namespace Infopro\CustomSection\Controller\Index;
  
  use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
  use Magento\Sales\Controller\OrderInterface;

  class Index extends \Magento\Sales\Controller\AbstractController\View implements OrderInterface, HttpGetActionInterface
  {
  }
?>

基本上,我是从Items Ordered 选项卡控制器格式中得到这个想法的。 您还可以在此处检查项目中的文件格式 /project/vendor/magento/module-sales/Controller/Order/View.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多