I want to display products in a particular category whose quantity is 1 or more. Please help me in getting done.
Thank you.
Create a file in this location (replace XXX/YYY with your theme location);
app/design/frontend/XXX/YYY/template/catalog/product/instock.phtml
In this file put this;
<?php
$instockIds = Mage::getModel('cataloginventory/stock_item')
->getCollection()
->addQtyFilter('>=', 1);
foreach($instockIds as $stock) {
$idarray[] = $stock->getProductId();
}
// Get all products
// $_productCollection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
// Load just 1 category, set the ID here
$categoryId = 12;
$_productCollection = Mage::getModel('catalog/category')->load($categoryId)
->getProductCollection()
->addIdFilter($idarray)
->addAttributeToSelect('*');
//Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($_productCollection);
$layout = Mage::getSingleton('core/layout');
$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();
$pager = $layout->createBlock('page/html_pager');
$block = $layout->createBlock('catalog/product_list');
$toolbar->setCollection($_productCollection);
$toolbar->setChild('product_list_toolbar_pager', $pager);
$toolbar->setPageSize(10);
$toolbar->setCurPage(1);
$toolbar->setCollection($_productCollection);
$block->setChild('toolbar', $toolbar);
$block->setCollection($_productCollection);
$block->setTemplate('catalog/product/list.phtml');
echo $block->renderView();
Now create a cms page, set the design of your page to match your category default - 2 column left etc.
In the content of the page, put this;
{{block type="catalog/product_list" template="catalog/product/instock.phtml"}}
This will load all products that either have stock, or are set to not manage stock.