在Magento前台的页面显示设置有特殊价格日期的产品的处理办法 :
1) 新建一个Page页,Design的内容为
<reference name="content">
<block type="catalog/product_special " name="product_special " template="catalog/product/list.phtml">
<action method="setColumnCount"><column_count>6</column_count></action>
<action method="setProductsCount"><count>0</count></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" />
<action method="setDefaultGridPerPage"><limit>12</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>12</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>24</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>36</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>48</limit></action>
<action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action>
</block>
<action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>6</count></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
2) 建立文件:app/code/local/Mage/Catalog/Block/Product/Special.php,内容为:
<?php
/*
sjolzy <chen@sjolzy.cn >
*/
class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List{
function get_prod_count(){
Mage::getSingleton('catalog/session')->unsLimitPage();
return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 12;
}
function get_cur_page(){
return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
}
protected function _getProductCollection(){
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
$collection = $this->_addProductAttributesAndPrices($collection)
->addStoreFilter()
->addAttributeToFilter('special_from_date ', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_to_date ', array('or'=> array(
0 => array('date' => true, 'from' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToSort('special_from_date', 'desc')
->setPageSize($this->get_prod_count())
->setCurPage($this->get_cur_page());
$this->setProductCollection($collection);
return $collection;
}
}
?>
3) 访问Page的url,已经看见设置有特殊日期和价格的产品了。
P, 这个Magento 页面自动显示特殊价格的产品和Magento添加新到产品在CMS Page(带分页) 这篇文章类似,可以参考。
(责任编辑:最模板) |