0

I want to create new customer section example sampleorder

url like : customer/account/sampleorders/

I tried below method that is working but it is the wrong way to modify core Magento files, what I tried is below, but I want to do it via module

1: create a file Sampleorders.php

vendor/magento/module-customer/Controller/Account/Sampleorders.php

<?php
namespace Magento\Customer\Controller\Account;

class Sampleorders extends \Magento\Customer\Controller\AbstractAccount
{

   /**
  * Index Action*
  * @return void
  */
  public function execute()
  {
       echo "hellow";
      exit();

  }
}
1
  • i have post here so please check and update me.
    – Msquare
    Mar 27, 2020 at 8:07

1 Answer 1

1

app/code/VendoreName/ModuleName/Controller/Account

Sampleorders.php

<?php

namespace VendoreName\ModuleName\Controller\Account;

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

class Sampleorders extends \Magento\Customer\Controller\AbstractAccount implements HttpGetActionInterface
{
    /**
     * @var PageFactory
     */
    protected $resultPageFactory;

    /**
     * @param Context $context
     * @param PageFactory $resultPageFactory
     */
    public function __construct(
        Context $context,
        PageFactory $resultPageFactory
    ) {
        $this->resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }

    /**
     * Default customer account page
     *
     * @return \Magento\Framework\View\Result\Page
     */
    public function execute()
    {
        echo "hellow";
        exit();
        //return $this->resultPageFactory->create();
    }
}

app/code/VendoreName/ModuleName/view/frontend/layout

customer_account_sampleorders.xml

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" 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">Sample Orders</argument>
            </action>
        </referenceBlock>
        <referenceContainer name="content">

        </referenceContainer>
    </body>
</page>

app/code/VendoreName/ModuleName/etc/frontend

routes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">    
        <route id="customer">
            <module name="VendoreName_ModuleName" after="Magento_Customer"/>
        </route>
    </router>
</config>

Now run Magento command

php bin/magento s:up

php bin/magento s:s:d -f

php bin/magento c:c

php bin/magento c:f

and Clear your browser cache

url like : customer/account/sampleorders

I Hope This Helps You.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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