diff --git a/src/Core/Events/Events.php b/src/Core/Events/Events.php index 80c4a573..89e4f740 100644 --- a/src/Core/Events/Events.php +++ b/src/Core/Events/Events.php @@ -10,13 +10,12 @@ namespace OxidSolutionCatalysts\PayPal\Core\Events; use OxidEsales\DoctrineMigrationWrapper\MigrationsBuilder; -use OxidEsales\Eshop\Core\Field; use OxidEsales\Eshop\Application\Model\Payment as EshopModelPayment; +use OxidEsales\Eshop\Core\Registry; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface; use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; -use OxidSolutionCatalysts\PayPal\Core\PayPalDefinitions; use OxidSolutionCatalysts\PayPal\Service\Logger; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; @@ -53,20 +52,6 @@ public static function onActivate(): void */ public static function onDeactivate(): void { - $activePayments = []; - foreach (PayPalDefinitions::getPayPalDefinitions() as $paymentId => $paymentDefinitions) { - $paymentMethod = oxNew(EshopModelPayment::class); - if ( - $paymentMethod->load($paymentId) && - (bool)$paymentMethod->oxpayments__oxactive->value - ) { - $activePayments[] = $paymentId; - $paymentMethod->oxpayments__oxactive = new Field(false); - $paymentMethod->save(); - } - } - $service = self::getModuleSettingsService(); - $service->saveActivePayments($activePayments); } /** @@ -95,8 +80,10 @@ private static function executeModuleMigrations(): void private static function addStaticContents(): void { $service = self::getStaticContentService(); - $service->ensureStaticContents(); - $service->ensurePayPalPaymentMethods(); + if ($service) { + $service->ensureStaticContents(); + $service->ensurePayPalPaymentMethods(); + } } /** @@ -105,14 +92,12 @@ private static function addStaticContents(): void private static function addRequireSession(): void { $service = self::getModuleSettingsService(); - $service->addRequireSession(); + if ($service) { + $service->addRequireSession(); + } } - /** - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - */ - private static function getStaticContentService(): StaticContent + private static function getStaticContentService(): ?StaticContent { /* Normally I would fetch the StaticContents service like this: @@ -125,24 +110,25 @@ private static function getStaticContentService(): StaticContent That's why I build the containers by hand as an exception.: */ - /** @var ContainerInterface $container */ - $container = ContainerFactory::getInstance() - ->getContainer(); - /** @var QueryBuilderFactoryInterface $queryBuilderFactory */ - $queryBuilderFactory = $container->get(QueryBuilderFactoryInterface::class); - $moduleSettings = self::getModuleSettingsService(); - - return new StaticContent( - $queryBuilderFactory, - $moduleSettings - ); + try { + /** @var ContainerInterface $container */ + $container = ContainerFactory::getInstance() + ->getContainer(); + /** @var QueryBuilderFactoryInterface $queryBuilderFactory */ + $queryBuilderFactory = $container->get(QueryBuilderFactoryInterface::class); + $moduleSettings = self::getModuleSettingsService(); + + return new StaticContent( + $queryBuilderFactory, + $moduleSettings + ); + } catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) { + Registry::getUtilsView()->addErrorToDisplay('OSC_PAYPAL_INSTALLPROCESS_FAILED'); + return null; + } } - /** - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface - */ - private static function getModuleSettingsService(): ModuleSettings + private static function getModuleSettingsService(): ?ModuleSettings { /* Normally I would fetch the StaticContents service like this: @@ -155,22 +141,29 @@ private static function getModuleSettingsService(): ModuleSettings That's why I build the containers by hand as an exception.: */ - /** @var ContainerInterface $container */ - $container = ContainerFactory::getInstance() - ->getContainer(); - /** @var ModuleSettingBridgeInterface $moduleSettingsBridge */ - $moduleSettingsBridge = $container->get(ModuleSettingBridgeInterface::class); - /** @var ContextInterface $context */ - $context = $container->get(ContextInterface::class); - /** @var ModuleConfigurationDaoBridgeInterface $moduleConfigurationDaoBridgeInterface */ - $moduleConfigurationDaoBridgeInterface = $container->get(ModuleConfigurationDaoBridgeInterface::class); - /** @var Logger $logger */ - $logger = $container->get(Logger::class); - return new ModuleSettings( - $moduleSettingsBridge, - $context, - $moduleConfigurationDaoBridgeInterface, - $logger - ); + try { + /** @var ContainerInterface $container */ + $container = ContainerFactory::getInstance() + ->getContainer(); + /** @var ModuleSettingBridgeInterface $moduleSettingsBridge */ + $moduleSettingsBridge = $container->get(ModuleSettingBridgeInterface::class); + /** @var ContextInterface $context */ + $context = $container->get(ContextInterface::class); + /** @var ModuleConfigurationDaoBridgeInterface $moduleConfigurationDaoBridgeInterface */ + $moduleConfigurationDaoBridgeInterface = $container->get(ModuleConfigurationDaoBridgeInterface::class); + /** @var Logger $logger */ + $logger = $container->get(Logger::class); + + return new ModuleSettings( + $moduleSettingsBridge, + $context, + $moduleConfigurationDaoBridgeInterface, + $logger + ); + } catch (NotFoundExceptionInterface | ContainerExceptionInterface $exception) { + Registry::getUtilsView()->addErrorToDisplay('OSC_PAYPAL_INSTALLPROCESS_FAILED'); + Registry::getLogger()->error($exception->getMessage(), [$exception]); + return null; + } } } diff --git a/views/de/admin_translations.php b/views/de/admin_translations.php index cf737757..c6eba995 100644 --- a/views/de/admin_translations.php +++ b/views/de/admin_translations.php @@ -273,4 +273,6 @@ 'HELP_OSC_PAYPAL_VAULTING_ACTIVATE_VAULTING' => 'Wiederholungskäufe leicht gemacht: Mit PayPal können Sie die bevorzugten Zahlarten Ihrer Kund:innen sicher speichern und so eine schnelle und einfache Kaufabwicklung ermöglichen. Mit ihren gespeicherten Zahlungsdaten können Kund:innen mit nur wenigen Klicks Wiederholungskäufe tätigen. Dies kann für Sie eine höhere Checkout-Conversion bedeuten.', - ]; + + 'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Because the module was not installed correctly via Composer, errors occurred during the (de)activation of the module. Please reinstall the module via composer and repeat the process.' +]; diff --git a/views/en/admin_translations.php b/views/en/admin_translations.php index f76ca0de..45c8f066 100644 --- a/views/en/admin_translations.php +++ b/views/en/admin_translations.php @@ -274,4 +274,6 @@ 'HELP_OSC_PAYPAL_VAULTING_ACTIVATE_VAULTING' => 'Repeat purchases made easy: With PayPal you can securely store your customers preferred payment methods, making it quick and easy Enable purchase processing. With their saved payment details, customers can make repeat purchases with just a few clicks. This can be for you mean higher checkout conversion.', - ]; + + 'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Because the module was not installed correctly via Composer, errors occurred during the (de)activation of the module. Please reinstall the module via composer and repeat the process.' +];