0
我正在嘗試獲取一些Magento2自定義core_config_data值,正如其他主題中所述,但我有一些與商店ID相關的錯誤值。我會盡量解釋,讓我們先從一些相關的代碼:Magento2:每個商店的錯誤配置數據值
public function __construct(
\Psr\Log\LoggerInterface $logger,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig) {..}
{
$store = $this->storeManager->getStore();
$this->logger->debug($store->getId() . ": " . $store->getCode());
$message = $this->scopeConfig->getValue(self::CONF_MESSAGE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
$link = $this->scopeConfig->getValue(self::CONF_LINK,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
這裏發生的是,商店ID和存儲代碼是正確。 在我看到
main.DEBUG: 3: tedesco
我$message
得到的值和$link
的日誌不正確:他們是另一家商店的值(正確的店鋪ID應該是3從調試日誌顯示,但該值是ID爲1的商店中的值)。
Magento 2.1.4。
任何提示?
在此先感謝。
非常感謝你,$ store('store = $ this-> storeManager-> getStore();')是我必須傳遞的參數。 –
不客氣,但我一直假設,如果你不通過第三個參數,它必須默認獲得當前的商店。 –
我假設使用'SCOPE_STORE'是一種說「範圍是商店,所以使用當前商店」。我很確定我沒有去檢查'getValue()'函數代碼,那是一個很大的錯誤......再次感謝 –