3

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.

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

1 Answer 1

4

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()
3
  • getParam does not work in an observer, $session->getStoreId() does. Dec 12, 2016 at 14:27
  • @TeroLahtinen If my answer has helped you, please accept it. Dec 12, 2016 at 17:09
  • I have to face this issue still using this class Magento\Store\Model\StoreManagerInterface::store => store->getStore()->getStoreId(); It return 1, when I refresh the page then it return correct selected store id in order create page screen
    – HaFiz Umer
    May 27, 2021 at 11:58

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.