Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getID() on a non-object

When I visit a page using the magentoshop; I get this errormessage:

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

I headed for that line, it's a part of a function called getTotalConfigurableItemsPrice. It's in a foreach:

And it says:

foreach ($attributes as $attribute) {
    $attributeId = $attribute->getProductAttribute()->getId();

And the attribute stuff is the problem. I tried a var_dump() on $attribute->getProductAttribute() and recieved NULL A var_dump on($attribute) shows i.e.

["_data":protected]=>
  array(5) {
    ["product_super_attribute_id"]=>
    string(4) "3845"
    ["product_id"]=>
    string(8) "10001563"
    ["attribute_id"]=>
    string(3) "135"
    ["position"]=>
    string(1) "0"
    ["product_attribute"]=>
    NULL
  }

What's wrong with the attribute and how can I fix it ? If I say:

$attributeId = 1234;

instead of

$attributeId = $attribute->getProductAttribute()->getId();

The error is gone, but I need true values ..

like image 960
user1697061 Avatar asked Jun 05 '13 14:06

user1697061


1 Answers

I had the same problem and found the solution for it.

Problem description:

The problem affects configurable products that were with attribute set "Default" and configurable attribute "color". A new attribute set was created based on "Default" and the attribute color was removed from that attribute set. Afterwards with some 3rd party extension the attribute sets of some configurable products were changed to the new one. And that was causing the problem.

Solution:

Add the attribute "color" to the attribute set of the problematic product.

Approach:

The configurable attributes for a given product are stored in the table catalog_product_super_attribute. Using the id of the product you can find out which those attributes are.

mysql> select * from catalog_product_super_attribute where product_id=1826;
+----------------------------+------------+--------------+----------+
| product_super_attribute_id | product_id | attribute_id | position |
+----------------------------+------------+--------------+----------+
|                       1826 |       1826 |           92 |        0 |
|                       2683 |       1826 |          209 |        0 |
+----------------------------+------------+--------------+----------+
mysql> select attribute_id,attribute_code from eav_attribute where (attribute_id=92 or attribute_id=208);
+--------------+----------------+
| attribute_id | attribute_code |
+--------------+----------------+
|           92 | color          |
|          208 | color_mutsy    |
+--------------+----------------+

All you have to do is go to your admin to Catalog - Attributes - Manage Attribute Sets and add the attributes to the attribute set of the problematic product and reindex.

like image 54
Nikolay Dimitrov Avatar answered Oct 14 '22 18:10

Nikolay Dimitrov