diff --git a/myparcelnl.php b/myparcelnl.php index 1e145259..5e32e2bc 100644 --- a/myparcelnl.php +++ b/myparcelnl.php @@ -7,6 +7,7 @@ use MyParcelNL\Pdk\Facade\Installer; use MyParcelNL\Pdk\Facade\Logger; use MyParcelNL\Pdk\Facade\Pdk; +use MyParcelNL\PrestaShop\Facade\MyParcelModule; use MyParcelNL\PrestaShop\Hooks\HasPdkCheckoutDeliveryOptionsHooks; use MyParcelNL\PrestaShop\Hooks\HasPdkCheckoutHooks; use MyParcelNL\PrestaShop\Hooks\HasPdkOrderGridHooks; @@ -66,7 +67,7 @@ public function __construct() $this->withErrorHandling( [$this, 'setup'], sprintf('Failed to instantiate %s', $this->displayName), - function (Throwable $e) { + function () { $this->hasPdk = false; if ($this->active) { @@ -76,6 +77,16 @@ function (Throwable $e) { ); } + /** + * @param bool $force_all + * + * @return bool + */ + public function enable($force_all = false): bool + { + return parent::enable($force_all) && $this->withErrorHandling([MyParcelModule::class, 'registerHooks']); + } + /** * Redirects the "configure" button in the module list to the settings page. * @@ -211,13 +222,17 @@ private function withErrorHandling( Logger::error("An error occurred: {$e->getMessage()}", ['exception' => $e->getTraceAsString()]); } - $this->_errors[] = sprintf( - '
%s: %s

Stack trace:
%s', + $formattedMessage = sprintf( + "%s: %s\n\nStack trace:\n%s", $message ?? 'Error', $e->getMessage(), - str_replace("\n", '
', $e->getTraceAsString()) + $e->getTraceAsString() ); + PrestaShopLogger::addLog($formattedMessage, PrestaShopLogger::LOG_SEVERITY_LEVEL_ERROR); + + $this->_errors[] = str_replace("\n", '
', $formattedMessage); + if ($failureCallback) { $failureCallback($e); }