0

How can I programmatically build this url: http://127.0.0.1/magento2/sales/order/view/order_id/61/?

Im in a custom controller with the current Order object.

4
  • Can you please explain what you exactly need because Magento default gives the same URL whenever you view order details
    – Ankit
    Commented Apr 7, 2021 at 4:11
  • Just that, I want to send the view order URL to an external API. So I need to generate it dynamically. Commented Apr 7, 2021 at 15:30
  • So you do have Order Id right?
    – Ankit
    Commented Apr 7, 2021 at 15:37
  • Yes I have all the Order object. I can do $order->getId(); Commented Apr 7, 2021 at 16:00

1 Answer 1

0

Please get website's base URL from this code:

public $_storeManager; public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, ..... ) { ... $this->_storeManager=$storeManager; } $url = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB);

$orderUrl = $url.'sales/order/view/order_id/'.$orderId;

You can pass $orderUrl in your external API.

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.