Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
magento 2商店管理器始终返回默认商店id_Magento_Magento 2.0 - Fatal编程技术网

magento 2商店管理器始终返回默认商店id

magento 2商店管理器始终返回默认商店id,magento,magento-2.0,Magento,Magento 2.0,我正在实现一个模块,该模块必须为所有存储存储不同的数据,所以我需要获取当前的存储id,并将id设置为具有新记录的db。我正试着用这种方法获取商店id $storeId=$this->\u storeManager->getStore()->getId() 但当我将作用域更改为另一个存储(其id为“2”)时,$storeId仍然具有值“1”(默认存储)。我看到url中的最后一个参数已更改 store/2/ 但是在代码中返回了默认的存储id。知道是什么导致了这个问题吗?问题在于您假设在更改配置范围时

我正在实现一个模块,该模块必须为所有存储存储不同的数据,所以我需要获取当前的存储id,并将id设置为具有新记录的db。我正试着用这种方法获取商店id

$storeId=$this->\u storeManager->getStore()->getId()

但当我将作用域更改为另一个存储(其id为“2”)时,$storeId仍然具有值“1”(默认存储)。我看到url中的最后一个参数已更改
store/2/

但是在代码中返回了默认的存储id。知道是什么导致了这个问题吗?

问题在于您假设在更改配置范围时也会更改后端范围,事实并非如此。有关问题的解决方案,请参阅github中的以下问题:


tl;dr:从请求参数获取存储id:
$this->\u request->getParam('store',0)

问题在于您假设在更改配置范围时,您也会更改后端范围,事实并非如此。有关问题的解决方案,请参阅github中的以下问题:

tl;dr:从请求参数获取存储id:
$this->\u请求->获取参数('store',0)