Wednesday, April 15, 2020

Add custom tab in logged user account in magento 2

Hello All,

Today I saw you How to create custom tab in logged in user account in magento 2.

Custom tab will display like this:



app\code\Chirag\Customproduct\registration.php

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


app\code\Chirag\Customproduct\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="Chirag_Customproduct" setup_version="1.0.0" >
<sequence>
        <module name="Magento_Customer"/>
    </sequence>
</module>
</config>


app\code\Chirag\Customproduct\etc\di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Model\Order\Pdf\Invoice"
                type="Czargroup\Pdfinvoice\Model\Order\Pdf\Invoice"/>
</config>


app\code\Chirag\Customproduct\etc\frontend\routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="customproduct" frontName="customproduct">
            <module name="Chirag_Customproduct" />
        </route>
    </router>
</config>


app\code\Chirag\Customproduct\Controller\Customer\Index.php

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


app\code\Chirag\Customproduct\view\frontend\layout\customer_account.xml

<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-customproduct">
            <arguments>
               <argument name="path" xsi:type="string">customproduct/customer/index</argument>
               <argument name="label" xsi:type="string">Custom Product</argument>
            </arguments>
         </block>
      </referenceBlock>
   </body>
</page> 


app\code\Chirag\Customproduct\view\frontend\layout\customproduct_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">Custom Product</argument>
            </action>
     </referenceBlock>
     <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template" name="customproduct" template="Chirag_Customproduct::customproduct.phtml">
        </block>
    </referenceContainer>
</body>
</page>   


app\code\Chirag\Customproduct\view\frontend\templates\customproduct.phtml

<?php
 // Add Some Code Here 
echo "This is custom Product List";
?> 


No comments:

Post a Comment