Hello,
I am creating a plugin in shopware which will list all products based on 1 API. for that API I have created a configuration file in the plugin to store API key, URL etc.
But how can I get these parameters in listing view/ detail view?
the configuration file (at ProductList/Resources/config.xml ): ProductList is name of plugin
ProductImportApi
Api Key
Api key
ProductImportUsername
Username
Username
ProductImportCategoryId
Category Id
Category id
Category wise Products will be shown.
Category wise Products will be shown.
Also ProductList/Subscriber/TemplateRegistration.php
pluginDirectory = $pluginDirectory;
$this->templateManager = $templateManager;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
'Enlight_Controller_Action_PreDispatch' => 'onPreDispatch',
'Enlight_Controller_Action_PostDispatchSecure_Backend_Listing' => 'onPostDispatch',
];
}
public function onPreDispatch() {
$this->templateManager->addTemplateDir($this->pluginDirectory . '/Resources/views');
}
public function onPostDispatch(\Enlight_Controller_ActionEventArgs $args) {
/** @var \Enlight_Controller_Action $controller */
$controller = $args->get('subject');
$view = $controller->View();
$config = $this->container->get('shopware.plugin.cached_config_reader')->getByPluginName($this->getName());
$view->addTemplateDir($this->pluginDirectory . '/Resources/views');
$view->assign('ProductImportApi', $config['ProductImportApi']);
$view->assign('ProductImportUsername', $config['ProductImportUsername']);
$view->assign('ProductImportCategoryId', $config['ProductImportCategoryId']);
}
}
ProductList/Controllers/Backend/ProductList.php
Please find attached snap