0

I want my order success page URL(checkout/onepage/success/) to be changed to order/?ORDERID

And I need to display some order details in that success page. That should be shown even after the reload.

I have tried to get some details by calling a phtml in checkout_onepage_success.xml

But this is not exactly I want.

Any suggestions are welcome. Thanks in Advance.

1

Yes, you could do that.

First, You have to build a module which frontName is order.Check What is a frontName?

Second is that redirect to checkout/onepage/success/ to order/?ORDERID

Create URL:

First, As you want to start url with order, So the routes.xml code at app/code/{Vendorname}/{Modulename}/etc/frontend.Will be like this:

<?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">
    <!-- frontname is Order as you want to uRL is Frontend -->
        <route id="order" frontName="order">
            <module name="{Vendorname}_{Modulename}" />
        </route>
    </router>
</config>

and You have to create Action file Index.php at app/code/{Vendorname}/{Modulename}/Controller/Index

And Code Should be like:

<?php
namespace {Vendorname}\{Modulename}\Controller\Index;

class Index extends \Magento\Checkout\Controller\Onepage
{
    /**
     * Order success action
     *
     * @return \Magento\Framework\Controller\ResultInterface
     */
    public function execute()
    {
        $session = $this->getOnepage()->getCheckout();
        if (!$this->_objectManager->get(\Magento\Checkout\Model\Session\SuccessValidator::class)->isValid()) {
            return $this->resultRedirectFactory->create()->setPath('checkout/cart');
        }
        $session->clearQuote();
        //@todo: Refactor it to match CQRS
        $resultPage = $this->resultPageFactory->create();
        $this->_eventManager->dispatch(
            'checkout_onepage_controller_success_action',
            ['order_ids' => [$session->getLastOrderId()]]
        );
        return $resultPage;
    }
}

Redirect checkout/onepage/success/ to order/?ORDERID

On this case, you have to create a plugin over Magento\Checkout\Controller\Onepage\Success , create around plugin on execute()

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.