Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leonhelmus opened this issue Jul 1, 2024 · 0 comments
Open

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

leonhelmus opened this issue Jul 1, 2024 · 0 comments

Comments

@leonhelmus
Copy link

leonhelmus commented Jul 1, 2024

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

  • PHP Version: (8.1)
  • Magento Version: 2.4.6-p6
  • Tweakwise Version: 6.0.1
  • Tweakwise Export Version: 7.0.1
  • Magento Deploy Mode: production
  • Third party modules:
    Trace does not have any third party modules visible.

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() ?? [];
     }
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant