2017-02-24 17 views
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的商店中的值)。

當然,我已經檢查了數據庫,數值正好如圖所示:DB values

Magento 2.1.4。

任何提示?

在此先感謝。

回答

1

如果您將商店或商店ID傳遞給第三參數,會發生什麼情況?

$message = $this->scopeConfig->getValue(self::CONF_MESSAGE, 
    \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); 
+0

非常感謝你,$ store('store = $ this-> storeManager-> getStore();')是我必須傳遞的參數。 –

+0

不客氣,但我一直假設,如果你不通過第三個參數,它必須默認獲得當前的商店。 –

+0

我假設使用'SCOPE_STORE'是一種說「範圍是商店,所以使用當前商店」。我很確定我沒有去檢查'getValue()'函數代碼,那是一個很大的錯誤......再次感謝 –