Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To use <code>addAttributeToFilter()</code> with an <code>OR</code> condition you can pass an array of arrays like this:</p> <pre><code>$collection-&gt;addAttributeToFilter( array( array( 'attribute' =&gt; 'name_of_attribute_1', 'null' =&gt; 'this_value_doesnt_matter' ), array( 'attribute' =&gt; 'name_of_attribute_2', 'in' =&gt; array(115, 116) ) ) ); </code></pre> <p>The definition of filtering against <code>NULL</code> keywords may look somewhat confusing at first glance, but it's plain simple, once you get used to it.</p> <p>Magento supports two filter types of type <code>string</code>, namely <code>'null'</code> and <code>'notnull'</code>, for comparisions against <code>NULL</code> keywords. </p> <p>Be aware, that even though you need to pass key=>value pairs (because an associative array is used), the value will be always ignored, when filter type <code>'null'</code> or <code>'notnull'</code> is used.</p> <h2>Example</h2> <pre><code>var_dump( Mage::getModel('catalog/product') -&gt;getCollection() -&gt;addFieldToFilter( array( array( 'attribute' =&gt; 'description', 'null' =&gt; 'this_value_doesnt_matter' ), array( 'attribute' =&gt; 'sku', 'in' =&gt; array(115, 116) ) ) ) -&gt;getSelectSql(true) ); </code></pre> <p>The output of the dump may vary depending on your shop configuration (attribute ids, count of stores, etc.), but the <code>OR</code> logic in the <code>WHERE</code> clause should always remain the same:</p> <pre><code>SELECT `e`.*, IFNULL(_table_description.value, _table_description_default.value) AS `description` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_product_entity_text` AS `_table_description_default` ON (_table_description_default.entity_id = e.entity_id) AND (_table_description_default.attribute_id='57') AND _table_description_default.store_id=0 LEFT JOIN `catalog_product_entity_text` AS `_table_description` ON (_table_description.entity_id = e.entity_id) AND (_table_description.attribute_id='57') AND (_table_description.store_id='1') WHERE ( (IFNULL(_table_description.value, _table_description_default.value) is NULL) OR (e.sku in (115, 116)) ) </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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