I currently retrieve if a plugin is installed like this:
$adyenPlugin = $this->pluginRepository->search(
(new Criteria())->addFilter(new EqualsFilter('name', self::ADYEN_PAYMENT_PLUGIN_NAME)),
Context::createDefaultContext(),
)->first();
if (!$adyenPlugin || null === $adyenPlugin->get('installedAt')) {
return new TableCollection(...$tables);
}
What would be the default way in Shopware to check if a plugin is installed? I would assume Shopware has a helper function or something?
You can inject the Shopware\Core\Framework\Plugin\KernelPluginLoader\KernelPluginLoader
.
Then you can check if a plugin is active
like this:
$pluginData = $this->pluginLoader->getPluginInstance('Adyen\Shopware\AdyenPaymentShopware6');
if (!$pluginData || !$pluginData->isActive()) {
return;
}
// Your logic
Is there a reason you want to check if a plugin is installed
instead of active
? An installed plugin won't execute any code / logic in Shopware.