0

I am currently trying to add a tab called "Product in Range" under the My Account section. The tab is showing up on the My Account page but once I click, I get a page not found error.

Can someone please review the code that I currently have and advise what is causing this error?

Here is the structure of my file directory:

enter image description here

Here is the code that I currently have for the Productrange module I created:

In Index.php:

<?php

namespace TimsSuperstore\Productrange\Controller\Index;

use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\Context;

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

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="productrange" frontName="productrange">
            <module name="TimsSuperstore_Productrange" />
        </route>
    </router>
</config>

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="TimsSuperstore_Productrange" setup_version="2.1.1" active="true">
        <sequence>
        </sequence>
    </module>
</config>

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-custom">
                <arguments>
                    <argument name="path" xsi:type="string">productrange</argument>
                    <argument name="label" xsi:type="string">Products In Range</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

productrange_front_index.xml:

<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"/>
    <body>
        <referenceBlock name="page.main.title">
            <action method="setPageTitle">
                <argument translate="true" name="title" xsi:type="string">Products In Range</argument>
            </action>
        </referenceBlock>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="productrange" template="TimsSuperstore_Productrange::productrange.phtml" />
        </referenceContainer>
    </body>
</page>

productrange.phtml:

<?php echo "Custom Tab Content..!"; ?>

<h1>PHTML CONTENT!</h1>

composer.json:

{
  "name": "timssuperstore/productrange",
  "description": "N/A",
  "require": {
    "php": "~7.1.3||~7.2.0||~7.3.0"
  },
  "type": "magento2-module",
  "version": "0.0.1",
  "license": [
    "BSD-3-Clause"
  ],
  "autoload": {
    "files": [
      "registration.php"
    ],
    "psr-4": {
      "TimsSuperstore\\Productrange\\": ""
    }
  }
}

registration.php:

<?php

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'TimsSuperstore_Productrange', __DIR__);
0

The Only issue in You Code is with controller namespace

namespace TimsSuperstore\Productrange\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{

It Should be

namespace TimsSuperstore\Productrange\Controller\Front;
class Index extends \Magento\Framework\App\Action\Action
{

then in your customer_account.xml <arggument name="path"> should be ike this

 <arguments>
    <argument name="path" xsi:type="string">productrange/front</argument>
    <argument name="label" xsi:type="string">Products In Range</argument>
 </arguments>

But it won't have to affect tab in my account it is Appreaing fine for me

make sure you have enabled module

php bin/magento module:enable TimsSuperstore_Productrange

then

php bin/magento s:up

i have created a sample Module and its working fine you can compare it GitHub Module

1
  • Ah that did the trick! Thanks Waqar, much appreciated! – timpyy Jun 11 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.