Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make nested Where clause in Magento collection using addAttributeToFilter or similar functions
    primarykey
    data
    text
    <p>I have to filter the product collection with multiple nested OR's and AND's criteria. I tried to do this using pure SQL statement and I guess I can do it, but as I am finishing work for today I thought that maybe someone here would know a better solution and I will wake up tomorrow and have the answer :P.</p> <p>My problem is that addAttributeToFilter() method provided by Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection class makes it possible to only nest the where clause two times - so I can have </p> <pre><code>(cond1 OR cond2 OR cond3) AND (cond4 OR cond5) AND cond6 </code></pre> <p>but not </p> <pre><code>cond1 AND (cond2 OR(cond3 AND cond4)) </code></pre> <p>(or I don't know a way to do it).</p> <p>As I said I started playing with pure SQL statement to get products ids, so then I can just addAttributeToFilter with 'in' condition. But Magento db is such a mess! I mean it's fine until you have to trace every relation through googol tables :P.</p> <p>I thought that Zend collection objects may have some functions that I need but I am not too familiar with Zend (my bad).</p> <p>So, will anyone save me from writing 300-lines SQL query? I always wanted to do it, but I think I can postpone it a little :).</p> <p>Cheers, Maćko</p> <p>EDIT: I have to get information about products and in this combined condition there will be some custom options from third party module like: targeted age etc. I think I will have to do it on PHP side, but I don't like it too much - for now there are 37 products that can be filtered initially, but what if there would be like 1000 products matching these initial criteria?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload