[英]Separate plugin configuration in Shopware subshops
我有Shopware 5插件,它在商店的模板中添加了一些js代碼。 有main shop_id = 1
和subshop shop_id = 3
,當我配置插件時,每個商店的backend > configuration > plugin_manager > plugin > configuration
都有單獨的backend > configuration > plugin_manager > plugin > configuration
。
當我在db表s_core_config_values
檢查它時,我看到為每個shop_id
添加了兩個不同的配置。
在主要的pugin文件中,我有一個訂戶方法,在該方法中,我正在獲取插件配置,然后注冊一些事件,例如
public static function getSubscribedEvents()
{
return [
'Enlight_Controller_Action_PostDispatchSecure_Frontend' => 'doSthMethod',
];
}
但是問題在於,總是有主插件配置(即使我在子商店中, shop_id = 1
配置。在主插件文件中)
class Shopware_Plugins_Backend_Pluginname_Bootstrap extends Shopware_Components_Plugin_Bootstrap
有$config = $this->Config();
哪個總是返回主車間配置,那么有什么方法可以得到實際的子車間配置?
編輯:
我已經從第一個答案中嘗試了解決方案,但是無論如何,無論我從哪個子商店提出請求,在以下情況下我都會得到我的主要商店的退貨:
$this->container->get('models')->getRepository(\Shopware\Models\Shop\Shop::class)->getActiveDefault();
隨着主要商店的退貨,我從以下位置獲取默認商店配置:
$this->container->get('shopware.plugin.cached_config_reader')->getByPluginName('PluginName', $shop);
當我打電話時:
$this->container->get('models')->getRepository(\Shopware\Models\Shop\Shop::class)->getActiveShops();
然后,我獲得了所有我的商店(包括子商店)的列表,但是我無法區分請求來自哪個子商店。
您應該使用shopware.plugin.cached_config_reader
服務來讀取插件配置。 您可以在文檔中找到一個很好的例子:
public function onPostDispatch(Enlight_Event_EventArgs $arguments)
{
$shop = false;
if ($this->container->initialized('shop')) {
$shop = $this->container->get('shop');
}
if (!$shop) {
$shop = $this->container->get('models')->getRepository(\Shopware\Models\Shop\Shop::class)->getActiveDefault();
}
$config = $this->container->get('shopware.plugin.cached_config_reader')->getByPluginName('PluginName', $shop);
[...]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.