Call to a member function getSku() on a non-object in app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php

call tomember function

Today one of our clients reported the following issue in Magento ver. 1.5.1.0, we tried to replicate but unable to replicate the issue. After digging through the code we found that the following line was causing the problem -:

$simple_sku = $simpleOption->getProduct($product)->getSku();</code>

The question was, why was it causing the problem and why can’t we replicate the issue, then one of our tech leads said it could be that the product in customer’s basket might have been deleted or disabled. We went into sales_flat_quote table and found out there are quite few SKUs in that table do not exist in main product table. To prove that this is the case, we went and changed the SKU of our basket directly in sales_flat_quote table and we got the same error, voila!

Call to a member function getSku() on a non-object in 
app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php

This is one of the main reason, we always request our clients to upgrade Magento to latest version because this issue was later fixed in 1.6.1.0. Anyways to rectify this issue we copied the Configurable.php in app/code/local/Mage/Catalog/Model/Product/Type/ and changed it to look as follows -:

//$simple_sku = $simpleOption->getProduct($product)->getSku();
$optionProduct = $simpleOption->getProduct($product);
if ($optionProduct) {
    $simple_sku = $simpleOption->getProduct($product)->getSku();
}

Hope this article helped you in some way. Please leave us your comment and let us know what do you think? Thanks.

2 thoughts on “Call to a member function getSku() on a non-object in app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php

  1. Fatal error: Call to a member function get_sku() on a non-object in /home/hoangng2/dungcusextoy.com/wp-content/themes/kuteshop/woocommerce/content-single-product.php
    How to use error?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.