Callum
Callum

Reputation: 1165

Magento list EVERY product in category

I have a block that needs to list 50+ products. In my list_parts.phtml it just displays all of the links in a list. I don't need any pagination or option to change how many products are listed, I just want list all of them.

I've looked on here but can't seem to find a solution. I've tried adding values like limit=500 but it's not working. Here's my block code:

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_parts" category_id="94" template="catalog/product/list_parts.phtml"}}

Update: Here is my custom block code

<?php

    class Products_Block_ListParts extends Mage_Catalog_Block_Product_Abstract
    {
        public function getProducts()
        {
            $_category = Mage::registry('current_category'); $currentCategoryId = $_category->getId();

            $products = Mage::getResourceModel('catalog/product_collection')
                ->addAttributeToSelect('*')
                ->addMinimalPrice()
                ->addStoreFilter()
                ->addCategoryFilter($_category);

            Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
            Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
            $this->setProductCollection($products);
        }
    }

  $_productCollection=$this->getLoadedProductCollection();
  $_helper = $this->helper('catalog/output');
    $store = Mage::app()->getStore();
  $code  = $store->getCode();
    $_coreHelper = $this->helper('core');
?>


<ol class="products-list" id="products-list">
    <?php foreach ($_productCollection as $_product): ?>
        <li><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></li>
    <?php endforeach; ?>
</ol>

Upvotes: 1

Views: 47

Answers (1)

Suman Singh
Suman Singh

Reputation: 1377

Create a new custom block (may be into new module or any existing module) as below:

<?php
class Package_Modulename_Block_Customplist extends Mage_Catalog_Block_Product_Abstract
{
    public function getProducts()
    {
        $currentCategoryId = 94; // Your category ID
        $_category = Mage::getModel('catalog/category')->load($currentCategoryId);

        $products = Mage::getResourceModel('catalog/product_collection')
            ->addAttributeToSelect('*')
            ->addMinimalPrice()
            ->addStoreFilter()
            ->addCategoryFilter($_category);

        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
        $this->setProductCollection($products);
    }
}
?>

In you theme create a phtml file:

<?php 
$this->getProducts();
$_productCollection=$this->getProductCollection();
foreach ($_productCollection as $_product){
// Your code here
}
?>

Than You can use it like:

{{block type="Your block class alias" name="block name" template="Your phtml file path"}}

OR

<?php echo $this->getLayout()->createBlock('Your block class alias')->setTemplate('Your phtml file path')->tohtml(); ?>

Upvotes: 1

Related Questions