Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

在Magento 2中的客户帐户中添加自定义选项卡的4个步骤

关于Magento 2的默认设置,客户将在注册或登录后自动重定向到其帐户仪表板。在此仪表板中,有各种选项卡,例如“我的帐户”,“我的订单”,“我的愿望清单”。

但是,在某些特定情况下,为了增强客户购物体验,需要将多个功能(如检查演示产品,请求退款或其他自定义要求)添加到客户帐户信息中心。遗憾的是,默认的Magento 2没有提供这些功能。因此,在今天的帖子中,我将向您展示4个简单的阶段,在客户帐户中添加自定义选项卡

如何在客户帐户中添加自定义标签

  • 第1步:创建客户帐户布局
  • 第2步:创建索引布局
  • 第3步:创建索引页面
  • 第4步:创建模板文件

第1步:创建客户帐户布局

首先,您需要customer_account.xml在路径中创建文件Mageplaza/Module/view/frontend/layout

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-custom">
<arguments>
<argument name="path" xsi:type="string">routename/customer/index</argument>
<argument name="label" xsi:type="string">My Custom Tab</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>

第2步:创建索引布局

创建上述文件后,也在路径Mageplaza/Module/view/frontend/layout中创建routename_customer_index.xml包含以下代码的文件:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> 
<update handle="customer_account"/> 
<body> 
<referenceBlock name="page.main.title"> 
<action method="setPageTitle"> 
<argument translate="true" name="title" xsi:type="string">My Custom Tab</argument> 
</action> 
</referenceBlock> 
<referenceContainer name="content"> 
<block class="Magento\Framework\View\Element\Template" name="my_tab" template="Vendor_Module::mytab.phtml"> 
</block> 
</referenceContainer> 
</body> 
</page>

第3步:创建索引页面

然后去Mageplaza/Module/Controller/Customer,并创建Index.php

<?php 
namespace Mageplaza/Module\Controller\Customer;  
class Index extends \Magento\Framework\App\Action\Action { 
public function execute() { 
$this->_view->loadLayout(); 
$this->_view->renderLayout(); 
} 
} 
?>

第4步:创建模板文件

最后,要在客户帐户信息中心中添加自定义标签,您只需按照路径Mageplaza/Module/view/frontend/templates创建即可mytab.phtml

<?php 
// Add Some Code Here for design
?>
<span> My Custom Tab.. </span>

结论

以上是如何在Magento 2 中的客户帐户仪表板添加自定义选项卡的过程。我希望本文对您有所帮助

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论