2016-07-11 193 views
1

我有一個區塊需要列出50多個產品。在我的list_parts.phtml中,它只顯示列表中的所有鏈接。我不需要任何分頁或選項來更改列出的產品數量,我只想列出所有產品。Magento列出每個產品類別

我在這裏看過,但似乎無法找到解決方案。我試過添加像limit=500這樣的值,但它不起作用。下面是我的塊代碼:

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

更新:這裏是我的自定義分組碼

<?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> 

回答

0

創建一個新的自定義塊(可能是爲新的模塊或任何現有的模塊),如下:

<?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); 
    } 
} 
?> 

在您的主題創建一個PHTML文件:

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

比你可以使用它像:

{{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(); ?> 
+0

你好謝謝。我打算爲幾個類別做這個,如何將類別ID解析爲自定義塊 – Callum

+0

$ _category = Mage :: registry('current_category'); $ currentCategoryId = $ _category-> getId(); –

+0

很酷謝謝,即時通訊新的magento開發,wheres最好的地方,把這個? – Callum