custom/plugins/sw6_payment_integration-64.1.8/src/SveaPayment.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Svea\SveaPayment;
  3. use Shopware\Core\Framework\Plugin;
  4. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  5. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  6. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  8. use Shopware\Core\Framework\Plugin\Util\PluginIdProvider;
  9. use Svea\SveaPayment\Installer\CoreInstaller;
  10. class SveaPayment extends Plugin {
  11.     public function postInstall(InstallContext $installContext): void {
  12.         $pluginId $this->getPluginId($installContext->getContext());
  13.         $pluginVersion $this->getPluginVersion();
  14.         $installer = new CoreInstaller($this->container$installContext->getContext(), $pluginId$pluginVersion);
  15.         $installer->install();
  16.         parent::install($installContext);
  17.     }
  18.     
  19.     public function activate(ActivateContext $activateContext): void {
  20.         $pluginId $this->getPluginId($activateContext->getContext());
  21.         $installer = new CoreInstaller($this->container$activateContext->getContext(), $pluginId);
  22.         $installer->setPaymentMethodsIsActive(true$activateContext->getContext());
  23.         parent::activate($activateContext);
  24.     }
  25.     
  26.     public function uninstall(UninstallContext $uninstallContext): void {
  27.         $pluginId $this->getPluginId($uninstallContext->getContext());
  28.         $installer = new CoreInstaller($this->container$uninstallContext->getContext(), $pluginId);
  29.         $installer->uninstall();
  30.         if (!$uninstallContext->keepUserData()) {
  31.             $installer->removeConfig();
  32.             //$uninstaller->deleteMailSettings();
  33.         }
  34.         parent::uninstall($uninstallContext);
  35.     }
  36.     public function deactivate(DeactivateContext $deactivateContext): void {
  37.         $pluginId $this->getPluginId($deactivateContext->getContext());
  38.         $installer = new CoreInstaller($this->container$deactivateContext->getContext(), $pluginId);
  39.         $installer->setPaymentMethodsIsActive(false$deactivateContext->getContext());
  40.         parent::deactivate($deactivateContext);
  41.     }
  42.     
  43.     public function getPluginId($context) {
  44.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  45.         return $pluginIdProvider->getPluginIdByBaseClass(get_class($this), $context);
  46.     }
  47.     
  48.     public function getPluginVersion() {
  49.         $pluginDirectory dirname($this->getPath());
  50.         $composerJsonPath $pluginDirectory '/composer.json';
  51.         if (!file_exists($composerJsonPath)) {
  52.             throw new \Exception('composer.json not found under: ' $pluginDirectory);
  53.         }
  54.         $composerJson file_get_contents($composerJsonPath);
  55.         $composerData json_decode($composerJsontrue);
  56.         if (isset($composerData['version'])) {
  57.             return $composerData['version'];
  58.         }
  59.         throw new \Exception('Plugin version not found in composer.json');
  60.     }
  61. }