-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Getting PHP Fatal Error on getPrice() #5519
Comments
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. |
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: |
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. |
I'm also running into this. |
Issue has been fixed in current develop branch c966dc1 |
Also running into this issue, using Magento CE 2.1.4 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. |
@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 On a side note, i tried changing the stock settings for a Configurable product. |
Internal ticket to track issue progress: MAGETWO-72251 |
Steps to reproduce
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
The text was updated successfully, but these errors were encountered: