Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento: Get products collection which have atleast one category
    primarykey
    data
    text
    <p>I want to get products collection that have at-least one category. Actually I want to ignore that products which are not in any category. Can anyone help??? My code is below:</p> <pre><code>protected function _prepareCollection() { $store = $this-&gt;_getStore(); $collection = Mage::getModel('catalog/product')-&gt;getCollection() -&gt;addAttributeToSelect('sku') -&gt;addAttributeToSelect('name') -&gt;addAttributeToSelect('attribute_set_id') -&gt;addAttributeToSelect('type_id') -&gt;joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'); if ($store-&gt;getId()) { //$collection-&gt;setStoreId($store-&gt;getId()); $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID; $collection-&gt;addStoreFilter($store); $collection-&gt;joinAttribute('name', 'catalog_product/name', 'entity_id', null, 'inner', $adminStore); $collection-&gt;joinAttribute('custom_name', 'catalog_product/name', 'entity_id', null, 'inner', $store-&gt;getId()); $collection-&gt;joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner', $store-&gt;getId()); $collection-&gt;joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', $store-&gt;getId()); $collection-&gt;joinAttribute('price', 'catalog_product/price', 'entity_id', null, 'left', $store-&gt;getId()); } else { $collection-&gt;addAttributeToSelect('price'); $collection-&gt;joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner'); $collection-&gt;joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner'); } $this-&gt;setCollection($collection); parent::_prepareCollection(); $this-&gt;getCollection()-&gt;addWebsiteNamesToResult(); return $this; } </code></pre> <p>Thanks, </p>
    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. 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