1

I want to show all attributes of a product in compare page. I added this code in catalog/product/compare/list.phtml but I get this error:

<h2><?php echo (
        (
            $_item->getProduct()->getResource()->getAttribute('admin_rating')->getFrontend()->getValue($_item->getProduct() )
            && $_item->getProduct() ->getResource()->getAttribute('admin_rating')->getFrontend()->getValue($_item->getProduct() ) != "Nein"
        )
        ? $_item->getProduct() ->getResource()->getAttribute('admin_rating')->getFrontend()->getValue($_item->getProduct() )
        : ''
    ); ?></h2>

ERROR: Fatal error: Call to a member function getResource() on a non-object in ...\app\design\frontend\base\default\template\catalog\product\compare\list.phtml on line 78

What's wrong?

0

The error is telling you that the result for $_item->getProduct() is not an object, thus you can't call any methods. Make sure when you call $_item that has a product.

If you want to show all the attributes of the product you can instead try to get the product id and load it like this:

$product = Mage::getModel('catalog/product')->load('PRODUCT_ID_HERE');
$product->getData(); //this will return all the attributes

You will need to load the product again just to make sure you are loading all the attributes, but also you can work with the already loaded product if it already has all the attributes you need.

  • I added your code but no attributes shows in compare page. – Elham Gdz Jul 27 '15 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.