2

I have a payment module used in Magento 2 backend order creation.

In Magento 2 the administrator first chooses the store where the order is to be created. However, when reading configuration I always get configuration from store 1. Also using \Magento\Store\Model\StoreManagerInterface I always get store ID 1.

How can I find out which store the order is being created to?

Thanks.

  • Perhaps you will find the the answer for your question here – Siarhey Uchukhlebau Dec 12 '16 at 11:32
  • Nope, tried and getting store id 0. The website selection is different for backend orders. – Tero Lahtinen Dec 12 '16 at 12:29
2

As you can see in the corresponding controller (Magento\Sales\Controller\Adminhtml\Order\Create) you should use next code to get the requested store id:

$storeId = $this->getRequest()->getParam('store_id');

Or you can get the store_id from the current quote session (just add the Magento\Backend\Model\Session\Quote in di):

/** @var \Magento\Backend\Model\Session\Quote $session */
$session->getStoreId()
  • getParam does not work in an observer, $session->getStoreId() does. – Tero Lahtinen Dec 12 '16 at 14:27
  • @TeroLahtinen If my answer has helped you, please accept it. – Siarhey Uchukhlebau Dec 12 '16 at 17:09

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.