Magento: addAttributeToFilter but ignore for products that don't have this attribute? -
I'm trying to add some filters to my store, but they have a bad effect.
Suppose I have product type A and B. Now I have to show only A where Color = Blue / Red
$ collection = mage :: getResourceModel ('catalog / product_collection') - & gt; SetStoreID ($ this-> GetStoreId ()) - & gt; Updater Filter ($ this) - & gt; AddAttributeToFilter (array (array ('attribute' = & gt; 'color', 'in' = & gt; array (4, 6)),));
This trick does, but now that no value has been assigned to color in product type B (because this feature is not assigned to it), so to show any There is no product.
I found this code on the forum, but it does not work:
array ('attribute' => 'color', 'is' = > New zend_Db_Expr ('zero'))
Neither:
array ('attribute' => 'color', 'Null' = & gt; true);
It actually shows the products that have the assigned assignment but no value has been declared ...
I also tried to add:
array ('attribute' = & gt; 'value', 'gteq' = & gt; 0),
< / Pre>because i feel Note that these statements were associated with 'or' (as per the documentation) but even it only adds product types to which the assignment is assigned ...
Note That these values come from a drop down list, it is not certain if this is the case.
Maybe it is too long e, but it works for me:
$ collection = mage :: getResourceModel ('catalog / product_collection') - & gt; SetStoreID ($ this-> GetStoreId ()) - & gt; AddCategoryFilter ($ This) - & gt; AddAttributeToFilter (array (array ('attribute' = & gt; 'color', 'null' => true), array ('attribute' = & gt; 'color', 'in' => array (4 , 6)),), '', 'left');
Comments
Post a Comment