Search code examples
phpmagento

Magento upsell_products raises error "must be an instance of Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection"


Putting this line to view.phtml ...

<?php echo $this->getChildHtml('upsell_products') ?>

... raises this error:

Recoverable Error: Argument 1 passed to Mage_Catalog_Block_Product_Abstract::_addProductAttributesAndPrices() must be an instance of Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection, instance of Mage_Catalog_Model_Resource_Product_Link_Product_Collection given, called in D:\active\***\src\app\code\core\Mage\Catalog\Block\Product\List\Upsell.php on line 65 and defined  in D:\active\***\src\app\code\local\Mage\Catalog\Block\Product\Abstract.php on line 355

#0 D:\active\***\src\app\code\local\Mage\Catalog\Block\Product\Abstract.php(355): mageCoreErrorHandler(4096, 'Argument 1 pass...', 'D:\active\***...', 355, Array)
#1 D:\active\***\src\app\code\core\Mage\Catalog\Block\Product\List\Upsell.php(65): Mage_Catalog_Block_Product_Abstract->_addProductAttributesAndPrices(Object(Mage_Catalog_Model_Resource_Product_Link_Product_Collection))
#2 D:\active\***\src\app\code\core\Mage\Catalog\Block\Product\List\Upsell.php(94): Mage_Catalog_Block_Product_List_Upsell->_prepareData()
#3 D:\active\***\src\app\code\core\Mage\Core\Block\Abstract.php(862): Mage_Catalog_Block_Product_List_Upsell->_beforeToHtml()
#4 D:\active\***\src\app\code\core\Mage\Core\Block\Abstract.php(582): Mage_Core_Block_Abstract->toHtml()
#5 D:\active\***\src\app\code\core\Mage\Core\Block\Abstract.php(526): Mage_Core_Block_Abstract->_getChildHtml('upsell_products', true)
#6 D:\active\***\src\app\design\frontend\default\***\template\catalog\product\view.phtml(163): Mage_Core_Block_Abstract->getChildHtml('upsell_products')

I found only one forum topic and it says that there is magento 1.6 core with not compatible modules.

Can you help me to solve this problem, please?


Solution

  • I had the same issue that came from the extension "Market Ready Germany 2.1.3". It came from an incompatible core overwrite that broke the product view pages.

    How to fix it for Magento from 1.5.+

    1. Copy current core file

    from

    \app\code\core\Mage\Catalog\Block\Product\Abstract.php
    

    to

    \app\code\local\Mage\Catalog\Block\Product\Abstract.php
    

    Backup the existing file in local (rename it).

    2. Compare both files

    Open the old local file and search for this method:

    public function getPriceHtml
    

    There should be two sections with commentary around them:

    //begin: symmetrics code
    ...
    //end: symmetrics code
    
    • Copy the first symmetrics section to the methods beginning, and copy the second section to the return value.
    • Delete the content of var/cache/* and open a product view page and it will not log any more errors.

    That should fix it.