From 75e6e59a203a76e2aa154d66d178d17d45d4ef0a Mon Sep 17 00:00:00 2001 From: Arturas Date: Mon, 13 Dec 2021 10:06:10 +0200 Subject: [PATCH 1/2] Escape error when parcel email not send, log error in logger --- CHANGELOG.md | 1 + config/service.yml | 1 + .../Handler/ParcelTrackingEmailHandler.php | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e49ac0d7..030ceef3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,5 +99,6 @@ - Bugfix when parcel terminal unconditionally changed to first selection while searching. - Upgrade added to avoid error when client upgrades modules and does not delete cache. - Bugfix when parcel tracking validation was called from prestashop core. Fall back to universal legacy function +- Logic to execute code further if error occurs on tracking email send. diff --git a/config/service.yml b/config/service.yml index 837b3baf..badb368e 100644 --- a/config/service.yml +++ b/config/service.yml @@ -260,6 +260,7 @@ services: arguments: - '@invertus.dpdbaltics.factory.parcel_tracking_url_factory' - '@dpdbaltics' + - '@invertus.dpdbaltics.logger.logger' invertus.dpdbaltics.service.carrier.prestashop_carrier_regeneration_handler: class: 'Invertus\dpdBaltics\Service\Carrier\PrestashopCarrierRegenerationHandler' diff --git a/src/Service/Email/Handler/ParcelTrackingEmailHandler.php b/src/Service/Email/Handler/ParcelTrackingEmailHandler.php index 3faaecff..a1f2ec19 100644 --- a/src/Service/Email/Handler/ParcelTrackingEmailHandler.php +++ b/src/Service/Email/Handler/ParcelTrackingEmailHandler.php @@ -5,6 +5,7 @@ use Invertus\dpdBaltics\Exception\ParcelEmailException; use Invertus\dpdBaltics\Factory\ContextFactory; use Invertus\dpdBaltics\Factory\ParcelTrackingUrlFactory; +use Invertus\dpdBaltics\Logger\Logger; use Mail; use Module; use Validate; @@ -16,17 +17,25 @@ class ParcelTrackingEmailHandler */ private $trackingUrlFactory; + /** * @var Module */ private $module; + /** + * @var Logger + */ + private $logger; + public function __construct( ParcelTrackingUrlFactory $trackingUrlFactory, - Module $module + Module $module, + Logger $logger ) { $this->trackingUrlFactory = $trackingUrlFactory; $this->module = $module; + $this->logger = $logger; } /** @@ -36,17 +45,17 @@ public function __construct( public function handle($idOrder, $parcelNumbers) { if (!$idOrder) { - throw new ParcelEmailException('Could not retrieve order'); + $this->logger->log(Logger::ERROR, 'Could not retrieve order'); } $order = $this->getOrder($idOrder); if (empty($parcelNumbers)) { - throw new ParcelEmailException('Could not retrieve parcel number, failed to format email'); + $this->logger->log(Logger::ERROR, 'Could not retrieve parcel number, failed to format email ID Order: '. $idOrder); } $cart = $this->getCartByOrderId($idOrder); if (!Validate::isLoadedObject($cart)) { - throw new ParcelEmailException('Could not retrieve order cart information'); + $this->logger->log(Logger::ERROR, 'Could not retrieve order cart information ID Order: '. $idOrder); } ContextFactory::getSmarty()->assign([ From fa331564cf51b62b6ed9a2aec83712a56e88bb63 Mon Sep 17 00:00:00 2001 From: Arturas Date: Mon, 13 Dec 2021 11:03:29 +0200 Subject: [PATCH 2/2] stop execution if no needed info for treacking link --- src/Service/Email/Handler/ParcelTrackingEmailHandler.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Service/Email/Handler/ParcelTrackingEmailHandler.php b/src/Service/Email/Handler/ParcelTrackingEmailHandler.php index a1f2ec19..aefd3acf 100644 --- a/src/Service/Email/Handler/ParcelTrackingEmailHandler.php +++ b/src/Service/Email/Handler/ParcelTrackingEmailHandler.php @@ -46,12 +46,15 @@ public function handle($idOrder, $parcelNumbers) { if (!$idOrder) { $this->logger->log(Logger::ERROR, 'Could not retrieve order'); + return false; } $order = $this->getOrder($idOrder); if (empty($parcelNumbers)) { $this->logger->log(Logger::ERROR, 'Could not retrieve parcel number, failed to format email ID Order: '. $idOrder); + return false; } + $cart = $this->getCartByOrderId($idOrder); if (!Validate::isLoadedObject($cart)) {