我已按照本指南操作,现在已经有新产品显示了一段时间,但左侧的过滤器从未显示: http://www.dnawebagency.com/displaying-new-products-in-magento-with-pagination/
此代码如下/app/code/local/Mage/Catalog/Block/Product/New.php
<?php
class Mage_Catalog_Block_Product_New extends Mage_Catalog_Block_Product_List
{
function get_prod_count()
{
//unset any saved limits
Mage::getSingleton('catalog/session')->unsLimitPage();
return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 12;
}// get_prod_count
function get_cur_page()
{
return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
}// get_cur_page
/**
* Retrieve loaded category collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
**/
protected function _getProductCollection()
{
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
//$collection = Mage::getResourceModel('catalog/product_collection');
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
$collection = $this->_addProductAttributesAndPrices($collection)
->addStoreFilter()
->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('news_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToSort('news_from_date', 'desc')
->setPageSize($this->get_prod_count())
->setCurPage($this->get_cur_page());
$this->setProductCollection($collection);
return $collection;
}// _getProductCollection
}// Mage_Catalog_Block_Product_New
?>
现在,我在页面模板
上使用以下XML获取了页面上的过滤器<!-- add layered navigation to left column -->
<reference name="left">
<block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml" />
</reference>
现在显示左侧的过滤器,但它显示所有类别计数,当点击任何过滤器时,它不会缩小搜索当前新库存。
我一直在挠头,在网上搜索,试着让它发挥作用。
有人有什么想法吗?
页面上的完整xml如下
<action method="addFilter">
</action>
<reference name="content">
<block type="catalog/product_new" name="product_list" after="product_filter" template="catalog/product/list.phtml">
<action method="setCategoryId"><category_id>3</category_id></action>
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="addColumnCountLayoutDepend"><layout>empty</layout>
<count>6</count>
</action>
<action method="addColumnCountLayoutDepend">
<layout>one_column</layout>
<count>5</count>
</action>
<action method="addColumnCountLayoutDepend">
<layout>two_columns_left</layout>
<count>3</count>
</action>
<action method="addColumnCountLayoutDepend">
<layout>two_columns_right</layout>
<count>4</count>
</action>
<action method="addColumnCountLayoutDepend">
<layout>three_columns</layout>
<count>3</count>
</action>
<action method="setToolbarBlockName">
<name>product_list_toolbar</name>
</action>
</block>
</reference>
<!-- add layered navigation to left column -->
<reference name="left">
<block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml" />
</reference>
答案 0 :(得分:1)
请指定图层的类别ID
<reference name="left">
<!-- Layered Navigation Block -->
<block type="catalog/layer_view" name="catalog.leftnav" template="catalog/layer/view.phtml" >
<action method="setCategoryId"><category_id>3</category_id></action>
</block>
</reference>
更多详情请查看....
答案 1 :(得分:1)
通过内容值为
的静态块调用主页上的块{{block type =“catalog / product_list”name =“product_listing”template =“catalog / product / new.phtml”}}
或者你可以直接在cms home上调用这个块,粘贴这个
{{block type =“catalog / product_list”name =“product_listing”template =“catalog / product / new.phtml”}}
在您的cms主页内容中。
在文件夹frontend / theme_folder / default / template / catalog / product中创建一个文件new.phtml。
将以下代码粘贴在其中:
<?php
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->setVisibility(array(2,3,4))
->setOrder('created_at', 'desc')
->setPage(1, 4);
?>
<?php $_iterator = 0; ?>
<ul class="products-grid">
<?php foreach($_productCollection as $_product) : ?>
<li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
<?php // Product Image ?>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
<div class="product-shop">
<div class="f-fix">
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></h2>
<?php echo $this->getPriceHtml($_product, true) ?>
<?php if($_product->isSaleable()): ?>
<p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
多数民众赞成你可以在主页上看到最新的4产品。你可以通过增加 - &gt; setPage(1,4)来增加产品数量;在主页上显示您所需的产品数量。