From 6e2b2f1529aeceae22ad3eee19fe7f3e80017b35 Mon Sep 17 00:00:00 2001 From: Sam James Date: Thu, 24 Apr 2025 12:26:42 +0100 Subject: [PATCH 1/3] fix: log exceptions during source distance calculation --- .../SearchRequest/Area/GetDistanceToSources.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php b/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php index 263e4c33bb05..981f207d7e7e 100644 --- a/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php +++ b/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php @@ -14,6 +14,7 @@ use Magento\InventoryInStorePickupApi\Model\SearchRequest\Area\Pipeline; use Magento\InventorySourceSelectionApi\Api\Data\AddressInterface; use Magento\InventorySourceSelectionApi\Api\Data\AddressInterfaceFactory; +use Psr\Log\LoggerInterface; /** * Provide associated list of Source codes and distance to them in KM. @@ -47,22 +48,30 @@ class GetDistanceToSources */ private $searchTermPipeline; + /** + * @var LoggerInterface + */ + private $logger; + /** * @param GetLatsLngsFromAddressInterface $getLatsLngsFromAddress * @param GetOrderedDistanceToSources $getOrderedDistanceToSources * @param AddressInterfaceFactory $addressInterfaceFactory * @param Pipeline $searchTermPipeline + * @param Logger $logger */ public function __construct( GetLatsLngsFromAddressInterface $getLatsLngsFromAddress, GetOrderedDistanceToSources $getOrderedDistanceToSources, AddressInterfaceFactory $addressInterfaceFactory, - Pipeline $searchTermPipeline + Pipeline $searchTermPipeline, + LoggerInterface $logger ) { $this->getLatsLngsFromAddress = $getLatsLngsFromAddress; $this->getOrderedDistanceToSources = $getOrderedDistanceToSources; $this->addressInterfaceFactory = $addressInterfaceFactory; $this->searchTermPipeline = $searchTermPipeline; + $this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class); } /** @@ -108,6 +117,7 @@ private function getDistanceToSources(AreaInterface $area): array try { $latsLngs = $this->getLatsLngsFromAddress->execute($sourceSelectionAddress); } catch (LocalizedException $exception) { + $this->logger->error($exception->getMessage()); return []; } From 3b3d83b508e75f634555570ccf3b175628c0738b Mon Sep 17 00:00:00 2001 From: engcom-Hotel Date: Wed, 3 Sep 2025 17:06:45 +0530 Subject: [PATCH 2/3] Fix the review comment and static test failure --- .../Model/SearchRequest/Area/GetDistanceToSources.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php b/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php index 47d3f7edc432..e1a22617b69f 100644 --- a/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php +++ b/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php @@ -15,6 +15,7 @@ use Magento\InventorySourceSelectionApi\Api\Data\AddressInterface; use Magento\InventorySourceSelectionApi\Api\Data\AddressInterfaceFactory; use Psr\Log\LoggerInterface; +use Magento\Framework\App\ObjectManager; /** * Provide associated list of Source codes and distance to them in KM. @@ -58,14 +59,14 @@ class GetDistanceToSources * @param GetOrderedDistanceToSources $getOrderedDistanceToSources * @param AddressInterfaceFactory $addressInterfaceFactory * @param Pipeline $searchTermPipeline - * @param Logger $logger + * @param LoggerInterface $logger */ public function __construct( GetLatsLngsFromAddressInterface $getLatsLngsFromAddress, GetOrderedDistanceToSources $getOrderedDistanceToSources, AddressInterfaceFactory $addressInterfaceFactory, Pipeline $searchTermPipeline, - LoggerInterface $logger + LoggerInterface $logger = null ) { $this->getLatsLngsFromAddress = $getLatsLngsFromAddress; $this->getOrderedDistanceToSources = $getOrderedDistanceToSources; From c5bbfab5a792d76c53f635a5d9816709b67a1083 Mon Sep 17 00:00:00 2001 From: engcom-Hotel Date: Wed, 3 Sep 2025 20:59:54 +0530 Subject: [PATCH 3/3] Fix static test failure --- .../Model/SearchRequest/Area/GetDistanceToSources.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php b/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php index e1a22617b69f..daa375a11877 100644 --- a/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php +++ b/InventoryInStorePickup/Model/SearchRequest/Area/GetDistanceToSources.php @@ -66,7 +66,7 @@ public function __construct( GetOrderedDistanceToSources $getOrderedDistanceToSources, AddressInterfaceFactory $addressInterfaceFactory, Pipeline $searchTermPipeline, - LoggerInterface $logger = null + ?LoggerInterface $logger = null ) { $this->getLatsLngsFromAddress = $getLatsLngsFromAddress; $this->getOrderedDistanceToSources = $getOrderedDistanceToSources;