Note that there are some explanatory texts on larger screens.

plurals
  1. POFilter Product collection by multiple price ranges
    primarykey
    data
    text
    <p>I want to filter product collection by some attributes including diy_kit_price attribute (new attribute already added) as shown below.</p> <p>Price Ranges:</p> <ol> <li>0 - 5000</li> <li>10000 - 15000</li> </ol> <p>I tried several ways but no luck.</p> <p>Working Code: when i am filtering by one price range:</p> <pre><code>$products = Mage::getModel('catalog/product')-&gt;getCollection() -&gt;addAttributeToSelect('*') -&gt;addAttributeToFilter('type_id', 'configurable') -&gt;joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') -&gt;addAttributeToFilter('category_id', array( array('finset' =&gt; '37') )) -&gt;addAttributeToSort('name', 'asc') -&gt;addAttributeToFilter('diy_kit_price', array('gt' =&gt; 0)) -&gt;addAttributeToFilter('diy_kit_price', array('lt' =&gt; 5000)); </code></pre> <p>Not Working Code: when i am filtering by one price range:</p> <pre><code>$products = Mage::getModel('catalog/product')-&gt;getCollection() -&gt;addAttributeToSelect('*') -&gt;addAttributeToFilter('type_id', 'configurable') -&gt;joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') -&gt;addAttributeToFilter('category_id', array( array('finset' =&gt; '37') )) -&gt;addAttributeToSort('name', 'asc') -&gt;addAttributeToFilter('diy_kit_price', array('gt' =&gt; 0)) -&gt;addAttributeToFilter('diy_kit_price', array('lt' =&gt; 5000)) -&gt;addAttributeToFilter('diy_kit_price', array('gt' =&gt; 10000)) -&gt;addAttributeToFilter('diy_kit_price', array('lt' =&gt; 15000)); </code></pre> <p>Is there any other way to filter. Can we filter using plain SQL with multiple price ranges.</p> <p>Thanks in advance.</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.
 

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