I have installed new magento 2.1 with mysql 5.6 , php7 on ubunu 15. Everything works except sometimes when I add a prod to cart , checkout, or login, I get the following error:
[Thu Jul 07 07:26:27.251375 2016] [:error] [pid 5731] [client 127.0.0.1:59868] PHP Fatal error: Uncaught Error: Call to a member function getPrice() on null in /var/www/magento2/vendor/magento/module-configurable-product/Model/Product/Type/Configurable/Price.php:43\nStack trace:\n#0 /var/www/magento2/vendor/magento/module-catalog/Model/Product.php(555): Magento\ConfigurableProduct\Model\Product\Type\Configurable\Price->getPrice(Object(Magento\Catalog\Model\Product\Interceptor))\n#1 /var/www/magento2/var/generation/Magento/Catalog/Model/Product/Interceptor.php(89): Magento\Catalog\Model\Product->getPrice()\n#2 /var/www/magento2/vendor/magento/module-quote/Model/Quote/Address/Total/Subtotal.php(110): Magento\Catalog\Model\Product\Interceptor->getPrice()\n#3 /var/www/magento2/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))\n#4 /var/www/magento2/vendor/magento/module-quote/Model/Quote/TotalsCollector.php(265): Magento\Quote\Model\Quote\Address\Total in /var/www/magento2/vendor/magento/module-configurable-product/Model/Product/Type/Configurable/Price.php on line 43, referer:
Please help
I had the same problem. I flushed all Cache from Magento 2 and then reindexed and now it's working.
@hvohra thank you for your report.
Could you please provide more specific cases when the issue reproduces? Maybe additional settings, product type, etc. As it may be very hard or impossible to reproduce on other environment the issue which appears "sometimes" only.
Also happens to me. I'm using Magento 2.1. It occurs during viewing cart when one of the items in the cart is set to "Out of Stock".
Replication step:
Result:
Fatal error: Uncaught Error: Call to a member function getPrice() on null in /Users/user/Sites/classic-spirit/vendor/magento/module-configurable-product/Model/Product/Type/Configurable/Price.php:43 Stack trace: #0 /Users/user/Sites/classic-spirit/vendor/magento/module-catalog/Model/Product.php(555): Magento\ConfigurableProduct\Model\Product\Type\Configurable\Price->getPrice(Object(Magento\Catalog\Model\Product\Interceptor))
Internal ticket: MAGETWO-57719
Any update on this? I am getting this error very frequently..
I had this issue couple of months ago so and I think I was able to resolve (or get around) this issue by downgrading my php from 7 to 5.6.
Hi, any update on when this will be fixed as Paypal is unusable if you have configurable products @maksek @veloraven @isitnikov
馃憤 on this we are having the exact same issue here using magento 2.1 with mysql 5.6 , php 7.0.8
It happens for us under the following circumstances:
We are having the same issue MhorGonzales describes.
Any update so far?
I'm also running into this.
Issue has been fixed in current develop branch https://github.com/magento/magento2/commit/c966dc1
Please check. Reopen if needed
Also running into this issue, using Magento CE 2.1.4
Don't know how to reproduce, but suddenly we started having this problem.
The above commit mentioned by @tkacheva obviously has nothing to do with this. It was included in Magento 2.1.3, but it doesn't help with this particular problem.
We just fixed it as follows (not sure if this is the correct way, but whatever):
diff --git a/Model/Product/Type/Configurable/Price.php b/Model/Product/Type/Configurable/Price.php
index fe4428cf589..3704b47f516 100644
--- a/Model/Product/Type/Configurable/Price.php
+++ b/Model/Product/Type/Configurable/Price.php
@@ -39,7 +39,7 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price
*/
public function getPrice($product)
{
- if ($product->getCustomOption('simple_product')) {
+ if ($product->getCustomOption('simple_product') && $product->getCustomOption('simple_product')->getProduct()) {
return $product->getCustomOption('simple_product')->getProduct()->getPrice();
} else {
return 0;
@maghamed, looks like another good place for defensive programming to be applied :)
I had to patch two additional files. My cart included a outdated configurable product.
diff --git a/app/code/Magento/ConfigurableProduct/Block/Cart/Item/Renderer/Configurable.php b/app/code/Magento/ConfigurableProduct/Block/Cart/Item/Renderer/Configurable.php
index b401e1a..ab8d764 100644
--- a/app/code/Magento/ConfigurableProduct/Block/Cart/Item/Renderer/Configurable.php
+++ b/app/code/Magento/ConfigurableProduct/Block/Cart/Item/Renderer/Configurable.php
@@ -65,7 +65,7 @@ class Configurable extends Renderer implements IdentityInterface
self::CONFIG_THUMBNAIL_SOURCE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
) == ThumbnailSource::OPTION_USE_PARENT_IMAGE ||
- !($this->getChildProduct()->getThumbnail() && $this->getChildProduct()->getThumbnail() != 'no_selection')
+ !($this->getChildProduct() && $this->getChildProduct()->getThumbnail() && $this->getChildProduct()->getThumbnail() != 'no_selection')
) {
$product = $this->getProduct();
} else {
diff --git a/app/code/Magento/ConfigurableProduct/CustomerData/ConfigurableItem.php b/app/code/Magento/ConfigurableProduct/CustomerData/ConfigurableItem.php
index 7614eef..dab847d 100644
--- a/app/code/Magento/ConfigurableProduct/CustomerData/ConfigurableItem.php
+++ b/app/code/Magento/ConfigurableProduct/CustomerData/ConfigurableItem.php
@@ -60,7 +60,7 @@ class ConfigurableItem extends DefaultItem
);
$product = $config == ThumbnailSource::OPTION_USE_PARENT_IMAGE
- || (!$this->getChildProduct()->getThumbnail() || $this->getChildProduct()->getThumbnail() == 'no_selection')
+ || (!$this->getChildProduct() || !$this->getChildProduct()->getThumbnail() || $this->getChildProduct()->getThumbnail() == 'no_selection')
? $this->getProduct()
: $this->getChildProduct();
diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable/Price.php b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable/Price.php
index fe4428c..3704b47 100644
--- a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable/Price.php
+++ b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable/Price.php
@@ -39,7 +39,7 @@ class Price extends \Magento\Catalog\Model\Product\Type\Price
*/
public function getPrice($product)
{
- if ($product->getCustomOption('simple_product')) {
+ if ($product->getCustomOption('simple_product') && $product->getCustomOption('simple_product')->getProduct()) {
return $product->getCustomOption('simple_product')->getProduct()->getPrice();
} else {
return 0;
We has the same issue (on magento 2.1.4), and the previous patch work for us, thank @peterhirn.
The problem seem to occur when the children product of a configurable is considered as deleted in module-quote/Model/ResourceModel/Quote/Item/Collection.php:258
@peterhirn patch fixed my Issue is this going to be pushed on the next release of magento?
@leandrosunrise as this is just an extended hack based on the patch from @hostep I think someone more familiar with the code should check this and create a pull request.
@peterhirn Although this hack prevents the error from showing it does not fix the issue of the simple product not being set within the protected $_product variable within vendor/magento/module-quote/Model/Quote/Item/Option.php.
Strangely the product option 'simple_product' does exist in the database within the table 'quote_item_option' and holds the correct product id towards the simple product in the value column.
While debugging i noticed that it does get the correct option from that table but never sets the product that is associated to it.
On a side note, i tried changing the stock settings for a Configurable product.
Namely by changing "Manage Stock" from Yes to No as this is what we generally use ourselves.
This somehow solved the issue for this specific product (do note we did several other changes on the product which had no effect) and showed the product properly in the cart.
Strangely once i change the settings back to what they were it will no longer give this error so it is not reliant on this setting.
Hence i believe this goes wrong in the indexing process, but as to why / where i am not yet sure.
Perhaps this information somehow helps others find the actual cause.
Internal ticket to track issue progress: MAGETWO-72251
Most helpful comment
I had to patch two additional files. My cart included a outdated configurable product.