From 2b241dbfba9f2b0a995809d0e5af4d6d3b6ab1dd Mon Sep 17 00:00:00 2001 From: Aad Mathijssen Date: Wed, 3 Nov 2021 17:07:54 +0100 Subject: [PATCH] Avoid API Exceptions for empty product template ids When retrieving the the related/upsell relations of a product for which the corresponding crosssell/upsell template id is empty, an `\Emico\Tweakwise\Exception\ApiException` is triggered with the following message: Featured products without template ID was requested. This exception is caught later on and is written as an error to the `system.log`. However, imho this scenario is not an actual error. Also, this might give rise to lots of error messages, which pollutes the `system.log` (and services that process errors from these logs like Sentry and Elasticsearch). This PR fixes these issues by adding an extra check to the Related and Upsell plugins before trying to perform a request to Tweakwise. --- Block/Catalog/Product/ProductList/Related/Plugin.php | 3 +++ Block/Catalog/Product/ProductList/Upsell/Plugin.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Block/Catalog/Product/ProductList/Related/Plugin.php b/Block/Catalog/Product/ProductList/Related/Plugin.php index 9ae1c61d..7f9f6ebf 100644 --- a/Block/Catalog/Product/ProductList/Related/Plugin.php +++ b/Block/Catalog/Product/ProductList/Related/Plugin.php @@ -34,6 +34,9 @@ public function aroundGetItems(Related $subject, Closure $proceed) if (!$this->config->isRecommendationsEnabled(Config::RECOMMENDATION_TYPE_CROSSSELL)) { return $proceed(); } + if (!$this->templateFinder->forProduct($subject->getProduct(), $this->getType())) { + return $proceed(); + } try { return $this->getCollection(); diff --git a/Block/Catalog/Product/ProductList/Upsell/Plugin.php b/Block/Catalog/Product/ProductList/Upsell/Plugin.php index b57fb708..de603808 100644 --- a/Block/Catalog/Product/ProductList/Upsell/Plugin.php +++ b/Block/Catalog/Product/ProductList/Upsell/Plugin.php @@ -35,6 +35,9 @@ public function aroundGetItemCollection(Upsell $subject, Closure $proceed) if (!$this->config->isRecommendationsEnabled(Config::RECOMMENDATION_TYPE_UPSELL)) { return $proceed(); } + if (!$this->templateFinder->forProduct($subject->getProduct(), $this->getType())) { + return $proceed(); + } try { return $this->getCollection();