0

How can I add a custom link to 'sales/order/view/order_id/123456' adding an slash after the order_id with route name "download" so it becomes sales/order/view/order_id/6710/download

My current route.xml file is

<?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="admin">
        <route id="order_export" frontName="order_export">
            <module name="Vendor_OrderExport" before="Magento_Adminhtml" />
        </route>        
    </router>
</config>

It's redirecting to a new permalink showing as https://example.com/adminPanel/order_export/index/index/key/29847124871248214hjhsfh2bdhjsf21/

1 Answer 1

0

You would not want (admin users) to manually modify the URL to access that action, because URL in Admin also comes with a cryptic form key at the end.

enter image description here

Messing up with that will cause the following action to fail and eventually take you back to Dashboard.

Also, take admin as users with very low technical proficiency, thus we should not let them perform tricky actions like that.

Please consider adding a custom Action Button to the Admin Sales Order View page, it is more convenient and easy to do.

This guide can help you with creating a custom Action Button in Admin panel.

When declaring your button in PHP Block class, specify the path to your controller in on_click index like this:

$buttonList->add(
    'download_order',
    [
        'label' => __('Download Order'),
        'on_click' => 'setLocation(\'' . $this->getUrl('order_export/index/index') . '\')',
        'class' => 'download-order',
        'id' => 'download_order'
    ]
);

As a result, $this->getUrl('order_export/index/index') will return a fully constructed URL with order_id/6710 preserved from last location and attached to it, which you could easily retrieve inside your controller using:

$orderId = $this->getRequest()->getParam('order_id');

Happy coding!

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.