Magento – Creating order in Magento 2 backend, how to find out the store

magento2multistorepayment-gatewaystore-id

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.

Best Answer

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()
Related Topic