Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've solved this problem by implementing addCategoriesFilter in product collection model, here is the patch. Modified code to be copied to the <code>local</code> pool to allow updates to a newer version.</p> <pre><code>@@ -103,6 +103,7 @@ * Allowed filters * store_id int; * category_id int; + * category_ids array; * category_is_anchor int; * visibility array|int; * website_ids array|int; @@ -567,6 +568,21 @@ } /** + * Specify categories filter for product collection + * + * @param array $categories + * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection + */ + public function addCategoriesFilter(array $categories) + { + $this-&gt;_productLimitationFilters['category_ids'] = $categories; + + ($this-&gt;getStoreId() == 0)? $this-&gt;_applyZeroStoreProductLimitations() : $this-&gt;_applyProductLimitations(); + + return $this; + } + + /** * Join minimal price attribute to result * * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection @@ -1592,7 +1608,7 @@ $this-&gt;_productLimitationJoinPrice(); $filters = $this-&gt;_productLimitationFilters; - if (!isset($filters['category_id']) &amp;&amp; !isset($filters['visibility'])) { + if (!isset($filters['category_id']) &amp;&amp; !isset($filters['category_ids']) &amp;&amp; !isset($filters['visibility'])) { return $this; } @@ -1604,11 +1620,16 @@ $conditions[] = $this-&gt;getConnection() -&gt;quoteInto('cat_index.visibility IN(?)', $filters['visibility']); } - $conditions[] = $this-&gt;getConnection() - -&gt;quoteInto('cat_index.category_id=?', $filters['category_id']); - if (isset($filters['category_is_anchor'])) { + + if (!isset($filters['category_ids'])) { $conditions[] = $this-&gt;getConnection() - -&gt;quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']); + -&gt;quoteInto('cat_index.category_id=?', $filters['category_id']); + if (isset($filters['category_is_anchor'])) { + $conditions[] = $this-&gt;getConnection() + -&gt;quoteInto('cat_index.is_parent=?', $filters['category_is_anchor']); + } + } else { + $conditions[] = $this-&gt;getConnection()-&gt;quoteInto('cat_index.category_id IN(' . implode(',', $filters['category_ids']) . ')', ""); } $joinCond = join(' AND ', $conditions); </code></pre> <p>Usage:</p> <pre class="lang-php prettyprint-override"><code>$category = $layer-&gt;getCurrentCategory(); $categories = $category-&gt;getAllChildren(true); $collection = Mage::getResourceModel('catalog/product_collection'); $collection-&gt;addCategoriesFilter($categories); </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