-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Update Configurable.php - add check for null in getProductForThumbnail() #10483
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
Conversation
Check to make sure that $this->getChildProduct() isn't null here before trying to call any class methods on it.
@@ -66,7 +66,7 @@ public function getProductForThumbnail() | |||
if ($this->_scopeConfig->getValue( | |||
self::CONFIG_THUMBNAIL_SOURCE, | |||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | |||
) == ThumbnailSource::OPTION_USE_PARENT_IMAGE || | |||
) == ThumbnailSource::OPTION_USE_PARENT_IMAGE || (empty($this->getChildProduct()) || | |||
!($this->getChildProduct()->getThumbnail() && $this->getChildProduct()->getThumbnail() != 'no_selection') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest rewriting it in more readable form
!($this->getChildProduct() && $this->getChildProduct()->getThumbnail() && $this->getChildProduct()->getThumbnail() != 'no_selection')
When $this->getChildProduct()
can be null by the way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orlangur We ran into this in production this morning, had a 500 error on /checkout/cart/ for a user and traced it back to this code. It was being called from the view/frontend/templates/cart/item/default.phtml template in the checkout module.
Thanks for the quick change 👍 Please provide answer to the
question to assure such change is really necessary. |
@orlangur We ran into this in production this morning, had a 500 error on /checkout/cart/ for a user and traced it back to this code. It was being called from the view/frontend/templates/cart/item/default.phtml template in the checkout module. |
@pbaylies do you have a stack trace maybe? As from Currently according to PHPDocs |
@orlangur We have a partial stack trace from the logs: Call to a member function getThumbnail() on null in /var/app/current/htdocs/vendor/magento/module-configurable-product/Block/Cart/Item/Renderer/Configurable.php:68 Stack trace: |
Do you see an approximate way it can happen in vanilla Magento 2 CE? No customization could cause such behavior? Maybe you have access to database to observe quote item and execution flow in |
@orlangur We are running EE with a lot of modules and customizations, so we can't really rule that out as a possibility. That said, there is a null value getting returned here, and it is causing a 500 error on the cart page, so, seems that is some cause for concern in this code. |
Long story short, with the help of @maghamed I noticed that A better fix would be to find out when
|
@orlangur Thanks for tracking that down! |
Hi @pbaylies,
No luck with such approach or didn't try it? Please share your findings if any, if you're not going to try due to lack of time/motivation this is absolutely ok too. |
@orlangur With this fix, at least I know it catches all the cases where getChildProduct() might be null in this function. Figuring out when getProduct() might be null as well would be a bigger job for another ticket. |
Aha, ok, let's leave as is (although we are fixing symptom and not a root of the problem here). |
@orlangur Thank you! |
…ductForThumbnail() #10483
Hey! |
Check to make sure that $this->getChildProduct() isn't null here before trying to call any class methods on it.