Skip to main content
added 1 character in body
Source Link

I have a controller for adminhtml area like this:

namespace Namespace\Module\Controller\Adminhtml\Order;

use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\Order;
 
class Complete extends \Magento\Backend\App\Action
{
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
    \Magento\Sales\Api\OrderRepositoryInterface $order
    )
    {
    $this->order = $order;
        parent::__construct($context);
    }

    public function execute()
    {
    $orderId = $this->request->getParam('order_id');
    $order = $this->order->get($orderId);
    if(!empty($order->getId())){
      try {
        $orderState = Order::STATE_COMPLETE;
        $order->setState($orderState)->setStatus(Order::STATE_COMPLETE);
        $this->messageManager->addSuccess(__("Successfully completed the order"));
      } catch (Exception $e) {
        $this->messageManager->addError(__("There's something wrong, please try again!"));
      }
    } else {
      $this->messageManager->addError(__("Invalid Order"));
    }
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    $resultRedirect->setUrl($this->_redirect->getRefererUrl());
    return $resultRedirect;
    }
}

i want to generate the url to redirect to this controller with magentmagento GET parameter order_id, how to do it in block file, so i can get the url from my phtml?

edit: i tried to do it like this:

$url = $block->getUrl('mymodulerouter/order/complete', ['param' => array("order_id"=>$order->getId())]);

echo $url;

but the result only generate the url to the controller without request get parameter, like this:

http://baseurl.com/adminhtml/mymodulerouter/order/complete/key/3t45n892808da9ea52mij56b87vv87f37f9c7y79886209d27caf9df3e7dc7c9c07/

I have a controller for adminhtml area like this:

namespace Namespace\Module\Controller\Adminhtml\Order;

use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\Order;
 
class Complete extends \Magento\Backend\App\Action
{
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
    \Magento\Sales\Api\OrderRepositoryInterface $order
    )
    {
    $this->order = $order;
        parent::__construct($context);
    }

    public function execute()
    {
    $orderId = $this->request->getParam('order_id');
    $order = $this->order->get($orderId);
    if(!empty($order->getId())){
      try {
        $orderState = Order::STATE_COMPLETE;
        $order->setState($orderState)->setStatus(Order::STATE_COMPLETE);
        $this->messageManager->addSuccess(__("Successfully completed the order"));
      } catch (Exception $e) {
        $this->messageManager->addError(__("There's something wrong, please try again!"));
      }
    } else {
      $this->messageManager->addError(__("Invalid Order"));
    }
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    $resultRedirect->setUrl($this->_redirect->getRefererUrl());
    return $resultRedirect;
    }
}

i want to generate the url to redirect to this controller with magent GET parameter order_id, how to do it in block file, so i can get the url from my phtml?

edit: i tried to do it like this:

$url = $block->getUrl('mymodulerouter/order/complete', ['param' => array("order_id"=>$order->getId())]);

echo $url;

but the result only generate the url to the controller without request get parameter, like this:

http://baseurl.com/adminhtml/mymodulerouter/order/complete/key/3t45n892808da9ea52mij56b87vv87f37f9c7y79886209d27caf9df3e7dc7c9c07/

I have a controller for adminhtml area like this:

namespace Namespace\Module\Controller\Adminhtml\Order;

use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\Order;
 
class Complete extends \Magento\Backend\App\Action
{
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
    \Magento\Sales\Api\OrderRepositoryInterface $order
    )
    {
    $this->order = $order;
        parent::__construct($context);
    }

    public function execute()
    {
    $orderId = $this->request->getParam('order_id');
    $order = $this->order->get($orderId);
    if(!empty($order->getId())){
      try {
        $orderState = Order::STATE_COMPLETE;
        $order->setState($orderState)->setStatus(Order::STATE_COMPLETE);
        $this->messageManager->addSuccess(__("Successfully completed the order"));
      } catch (Exception $e) {
        $this->messageManager->addError(__("There's something wrong, please try again!"));
      }
    } else {
      $this->messageManager->addError(__("Invalid Order"));
    }
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    $resultRedirect->setUrl($this->_redirect->getRefererUrl());
    return $resultRedirect;
    }
}

i want to generate the url to redirect to this controller with magento GET parameter order_id, how to do it in block file, so i can get the url from my phtml?

edit: i tried to do it like this:

$url = $block->getUrl('mymodulerouter/order/complete', ['param' => array("order_id"=>$order->getId())]);

echo $url;

but the result only generate the url to the controller without request get parameter, like this:

http://baseurl.com/adminhtml/mymodulerouter/order/complete/key/3t45n892808da9ea52mij56b87vv87f37f9c7y79886209d27caf9df3e7dc7c9c07/

added 416 characters in body
Source Link
nortonuser
  • 772
  • 1
  • 9
  • 26

I have a controller for adminhtml area like this:

namespace Namespace\Module\Controller\Adminhtml\Order;

use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\Order;
 
class Complete extends \Magento\Backend\App\Action
{
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
    \Magento\Sales\Api\OrderRepositoryInterface $order
    )
    {
    $this->order = $order;
        parent::__construct($context);
    }

    public function execute()
    {
    $orderId = $this->request->getParam('order_id');
    $order = $this->order->get($orderId);
    if(!empty($order->getId())){
      try {
        $orderState = Order::STATE_COMPLETE;
        $order->setState($orderState)->setStatus(Order::STATE_COMPLETE);
        $this->messageManager->addSuccess(__("Successfully completed the order"));
      } catch (Exception $e) {
        $this->messageManager->addError(__("There's something wrong, please try again!"));
      }
    } else {
      $this->messageManager->addError(__("Invalid Order"));
    }
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    $resultRedirect->setUrl($this->_redirect->getRefererUrl());
    return $resultRedirect;
    }
}

i want to generate the url to redirect to this controller with magent GET parameter order_id, how to do it in block file, so i can get the url from my phtml?

edit: i tried to do it like this:

$url = $block->getUrl('mymodulerouter/order/complete', ['param' => array("order_id"=>$order->getId())]);

echo $url;

but the result only generate the url to the controller without request get parameter, like this:

http://baseurl.com/adminhtml/mymodulerouter/order/complete/key/3t45n892808da9ea52mij56b87vv87f37f9c7y79886209d27caf9df3e7dc7c9c07/

I have a controller for adminhtml area like this:

namespace Namespace\Module\Controller\Adminhtml\Order;

use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\Order;
 
class Complete extends \Magento\Backend\App\Action
{
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
    \Magento\Sales\Api\OrderRepositoryInterface $order
    )
    {
    $this->order = $order;
        parent::__construct($context);
    }

    public function execute()
    {
    $orderId = $this->request->getParam('order_id');
    $order = $this->order->get($orderId);
    if(!empty($order->getId())){
      try {
        $orderState = Order::STATE_COMPLETE;
        $order->setState($orderState)->setStatus(Order::STATE_COMPLETE);
        $this->messageManager->addSuccess(__("Successfully completed the order"));
      } catch (Exception $e) {
        $this->messageManager->addError(__("There's something wrong, please try again!"));
      }
    } else {
      $this->messageManager->addError(__("Invalid Order"));
    }
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    $resultRedirect->setUrl($this->_redirect->getRefererUrl());
    return $resultRedirect;
    }
}

i want to generate the url to redirect to this controller with magent GET parameter order_id, how to do it in block file, so i can get the url from my phtml?

I have a controller for adminhtml area like this:

namespace Namespace\Module\Controller\Adminhtml\Order;

use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\Order;
 
class Complete extends \Magento\Backend\App\Action
{
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
    \Magento\Sales\Api\OrderRepositoryInterface $order
    )
    {
    $this->order = $order;
        parent::__construct($context);
    }

    public function execute()
    {
    $orderId = $this->request->getParam('order_id');
    $order = $this->order->get($orderId);
    if(!empty($order->getId())){
      try {
        $orderState = Order::STATE_COMPLETE;
        $order->setState($orderState)->setStatus(Order::STATE_COMPLETE);
        $this->messageManager->addSuccess(__("Successfully completed the order"));
      } catch (Exception $e) {
        $this->messageManager->addError(__("There's something wrong, please try again!"));
      }
    } else {
      $this->messageManager->addError(__("Invalid Order"));
    }
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    $resultRedirect->setUrl($this->_redirect->getRefererUrl());
    return $resultRedirect;
    }
}

i want to generate the url to redirect to this controller with magent GET parameter order_id, how to do it in block file, so i can get the url from my phtml?

edit: i tried to do it like this:

$url = $block->getUrl('mymodulerouter/order/complete', ['param' => array("order_id"=>$order->getId())]);

echo $url;

but the result only generate the url to the controller without request get parameter, like this:

http://baseurl.com/adminhtml/mymodulerouter/order/complete/key/3t45n892808da9ea52mij56b87vv87f37f9c7y79886209d27caf9df3e7dc7c9c07/

Source Link
nortonuser
  • 772
  • 1
  • 9
  • 26

Generate Adminhtml Controller url with get parameter in Block

I have a controller for adminhtml area like this:

namespace Namespace\Module\Controller\Adminhtml\Order;

use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\Order;
 
class Complete extends \Magento\Backend\App\Action
{
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
    \Magento\Sales\Api\OrderRepositoryInterface $order
    )
    {
    $this->order = $order;
        parent::__construct($context);
    }

    public function execute()
    {
    $orderId = $this->request->getParam('order_id');
    $order = $this->order->get($orderId);
    if(!empty($order->getId())){
      try {
        $orderState = Order::STATE_COMPLETE;
        $order->setState($orderState)->setStatus(Order::STATE_COMPLETE);
        $this->messageManager->addSuccess(__("Successfully completed the order"));
      } catch (Exception $e) {
        $this->messageManager->addError(__("There's something wrong, please try again!"));
      }
    } else {
      $this->messageManager->addError(__("Invalid Order"));
    }
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    $resultRedirect->setUrl($this->_redirect->getRefererUrl());
    return $resultRedirect;
    }
}

i want to generate the url to redirect to this controller with magent GET parameter order_id, how to do it in block file, so i can get the url from my phtml?