Skip to content

Instantly share code, notes, and snippets.

@astorm
Forked from anonymous/commerce_bug_error
Created April 21, 2011 15:43
Show Gist options
  • Save astorm/934801 to your computer and use it in GitHub Desktop.
Save astorm/934801 to your computer and use it in GitHub Desktop.
Commerce Bug error
Magento 1.4.1.1
URL: .../catalogsearch/result/?q=test
Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat::getEntityType() in /var/www/html/products/app/code/local/[redacted]/Commercebug/Model/Collectorcollections.php on line 36
@astorm
Copy link
Author

astorm commented Apr 21, 2011

This error in a known issue with Commerce Bug and the "Flat" catalog that will be fixed in a future release. In the meantime, you can manually patch the error yourself to get a working extension

In the following file

Commercebug/Collectorcollections.php

replace the _getModelNameFromModel method with the following.

protected function _getModelNameFromModel($model)
{
    if(method_exists($model, 'getModelName'))
    {
        return $model->getModelName();
    }
    if(is_object($model->getResource()) && method_exists($model->getResource(), 'getEntityType'))
    {
        return $model->getResource()->getEntityType()->getEntityModel();
    }
    if(is_object($model->getResource()))
    {
        return 'Method getEntityType not found on ' . get_class($model->getResource());
    }        
    return 'UNKNOWN';
}

that should take care of your problems.

If any other problems crop up or need help applying the above patch please don't hesitate to reply.

For the curious, this error came about because there's no official interface to Magento collections, and the collections of flat items don't implement either a getModelName method or a getResource method, which makes things explode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment