我有一个需要列出50多种产品的块。在我的list_parts.phtml
中,它只显示列表中的所有链接。我不需要任何分页或选项来更改列出的产品数量,我只想列出所有产品。
我看过这里,但似乎无法找到解决方案。我尝试过添加像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 :(得分: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(); ?>