-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Seems to have happened while I was testing enabling/disabling child products. Saw it just later in the error.log on our testserver and because our customer got the error cached in firefox.
Preconditions
Magento 2.1.7
Steps to reproduce
hard to reproduce. maybe it helps to deactive/delete a child product in the backend product listing without further steps. then have the given configured product in the wishlist or cart.
Expected result
nothing
Actual result
[11-Jul-2017 08:38:42 UTC] PHP Fatal error: Uncaught Error: Call to a member function getPrice() on null in /srv/httpd/test/src/www/vendor/magento/module-configurable-product/Model/Product/Type/Configurable/Price.php:43
Stack trace:
#0 /srv/httpd/test/src/www/vendor/magento/module-catalog/Model/Product.php(554): Magento\ConfigurableProduct\Model\Product\Type\Configurable\Price->getPrice(Object(Magento\Catalog\Model\Product\Interceptor))
#1 /srv/httpd/test/src/www/var/generation/Magento/Catalog/Model/Product/Interceptor.php(89): Magento\Catalog\Model\Product->getPrice()
#2 /srv/httpd/test/src/www/vendor/magento/module-quote/Model/Quote/Address/Total/Subtotal.php(110): Magento\Catalog\Model\Product\Interceptor->getPrice()
#3 /srv/httpd/test/src/www/vendor/magento/module-quote/Model/Quote/Address/Total/Subtotal.php(53): Magento\Quote\Model\Quote\Address\Total\Subtotal->_initItem(Object(Magento\Quote\Model\Quote\Address), Object(Magento\Quote\Model\Quote\Item\Interceptor))
#4 /srv/httpd/test/src/www/vendor/magento/module-quote/Model/Quote/TotalsCollector.p in /srv/httpd/test/src/www/vendor/magento/module-configurable-product/Model/Product/Type/Configurable/Price.php on line 43
- [Screenshot, logs]
Fix
The Fix is already given in Issue #5519
#5519
But you closed the issue before actual all possible causes were fixed. I applied the following patch to prevent a future circumstancial call on null in the getPrice() function:
diff --git a/www/vendor/magento/module-configurable-product/Model/Product/Type/Configurable/Price.php b/www/vendor/magento/module-configurable-product/Model/Product/Type/Configurable/Price.php
index 9c7efd803..db45d8ece 100644
--- a/www/vendor/magento/module-configurable-product/Model/Product/Type/Configurable/Price.php
+++ b/www/vendor/magento/module-configurable-product/Model/Product/Type/Configurable/Price.php
@@ -39,7 +39,9 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price
*/
public function getPrice($product)
{
-
if ($product->getCustomOption('simple_product')) {
-
// REF-MOD START under certain circumstances getPrice is called on null
-
if ($product->getCustomOption('simple_product') && $product->getCustomOption('simple_product')->getProduct()) {
-
// REF-MOD END return $product->getCustomOption('simple_product')->getProduct()->getPrice(); } else { return 0;