EmicoEcommerce / Magento2Tweakwise

Magento 2 module for Tweakwise integration
Other
4 stars 16 forks source link

Call to a member function getProductIds() on null #202

Open leonhelmus opened 2 months ago

leonhelmus commented 2 months ago

Issue Brief

What is the purpose of this issue? Explain the background context.

Resolve the error: Call to a member function getProductIds() on null

Which i sometimes see in the error logs.

Environment

Steps to reproduce

  1. \Tweakwise\Magento2Tweakwise\Model\Catalog\Layer\NavigationContext:getResponse returns null which is possible when looking at the function return type.
  2. \Tweakwise\Magento2Tweakwise\Model\Catalog\Product\Collection::getProductIds $response = $this->navigationContext->getResponse(); return $response->getProductIds();
  3. this returns an empty array.

Actual result

  1. $response is null and than it cannot call getProductIds() on null.
  2. you get the following error:
  3. Error: Caught Error (500): Call to a member function getProductIds() on null

Expected result

  1. if $response is null than $response->getProductIds() will not be called.

Possible solution

diff --git a/vendor/tweakwise/magento2-tweakwise/Model/Catalog/Product/Collection.php b/vendor/tweakwise/magento2-tweakwise/Model/Catalog/Product/Collection.php
--- a/vendor/tweakwise/magento2-tweakwise/Model/Catalog/Product/Collection.php
+++ b/vendor/tweakwise/magento2-tweakwise/Model/Catalog/Product/Collection.php  (date 1719832609005)
@@ -148,6 +148,6 @@
     protected function getProductIds()
     {
         $response = $this->navigationContext->getResponse();
-        return $response->getProductIds();
+        return $response->getProductIds() ?? [];
     }
 }