12

I have added one filter in Method _getProductCollection() of the class Mage_Catalog_Block_Product_List as follows.

protected function _getProductCollection()
{
     ...
    $this->_productCollection = $layer->getProductCollection();
    $this->_productCollection->getSelect()->joinInner(
        array('cpe' => 'catalog_product_entity'),
        'e.entity_id = cpe.entity_id'
    ) 
    ->where("cpe.type_id = 'simple'"); 
    ...
}

The above code is working fine as of Magento Version 1.7. But whenever I write the following code, it gives

Column not found: 1054 Unknown column 'e.type_id' in 'where clause'

error.

The code (which is not working).

protected function _getProductCollection()
{
     ...
    $this->_productCollection = $layer->getProductCollection();
    $this->_productCollection
        ->addAttributeToSelect('type_id')
        ->addAttributeToFilter('type_id','simple');
    ...
}

Now the Questions.

  1. Will there be any performance impact if I use the first working code?
  2. is there any other way to get around to having a proper product filter?

UPDATE:

Whenever I apply the following code and use rwd theme, I am not getting any error. But whenever I use the default theme, I get the below error,

Code

protected function _getProductCollection()
{
     ...
    $this->_productCollection = $layer->getProductCollection();
    $this->_productCollection
         ->addAttributeToSelect('type_id')
         ->addAttributeToFilter('type_id','simple');
    ...
}

Error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'e.type_id' in 'where clause', query was: SELECT FLOOR((ROUND((e.min_price) * 1, 2)) / 10) + 1 AS range, COUNT(*) AS count FROM catalog_product_index_price AS e INNER JOIN catalog_category_product_index AS cat_index ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id = '3' WHERE (e.type_id IN('simple')) AND ( e.website_id = '1' ) AND ( e.customer_group_id = 0) AND (e.min_price IS NOT NULL) GROUP BY FLOOR((ROUND((e.min_price) * 1, 2)) / 10) + 1 ORDER BY FLOOR((ROUND((e.min_price) * 1, 2)) / 10) + 1 ASC

3
  • which magento version u have use?? *& have applied magento patches
    – Amit Bera
    Commented Dec 24, 2015 at 8:19
  • 1
    wtf? now has sense... i was trying over a EE 1.14 on RWD, that is just unacceptable, how can a view theme change an entire query even worst how can change the main table... this couldn't be anything but a bug. Well done @Magento Learner! Commented Dec 29, 2015 at 6:33
  • Exactly, the view theme creates problem. thanks. The code should be independent of a theme Commented Dec 29, 2015 at 6:36

1 Answer 1

0

I think that:

$collection->addAttributeToFilter('type_id', array('eq' => 'simple');

Should works, you don't need to add type_id to select since is a catalog_product_entity column and it's retrieved by default. I always suggest logging the final query in order to get the best idea of what is happening:

Mage.:log($collection->getSelectSql(true));

BTW: The first code block has no sense at all since you are joining the main table (catalog_product_entity) to itself.

10
  • " in Magento 1.7 they did an optimization on the select sql that is used for the price filtering options. They remove the FROM sql part (which is product entity - which contains type_id attribute) and make the price_index related table the main one - the one that is used in the FROM part of the query. So basically the table from which the data is selected is not the product entity table anymore (you lose all products base attributes) the main table becomes the product index. This is an core update that the Magento team added starting 1.7 versions." Refer the following Commented Dec 24, 2015 at 8:54
  • sohu.io/questions/886200/… Commented Dec 24, 2015 at 8:54
  • 1
    wooow my fault folk, for some reason, i was thinking in backend block getCollection method, so in this scenario your first code it's ok I'm not sure if it is the best solution but seems to be ok. Sorry Commented Dec 24, 2015 at 9:02
  • @MagentoLearner are you sure about that post? i've just re-checked on a EE1.14 i have installed and still using catalog_product_entity as main table, except when you set to use flat catalog (absolutely recommended) but in both cases you have type_id present in the select. Can you log the query as i've wrote in the original Answer? Commented Dec 24, 2015 at 9:17
  • 1
    mmmm interesting... i Also check the query in a search case and is using catalog_product_entity as main table, maybe the "magento team" have decided to rollback that changes. I can't found any 1.7 installed to check it but the idea of change the main table of an entity sounds like a very bad architectural decision... Well note that you just ruined my weekend, now i need to find and install a CE1.7 and look this crap with my own eyes... my wife will not be happy with this :) Commented Dec 24, 2015 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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