【发布时间】: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