magento 每日新品展示
2015-06-26 12:34
323 查看
http://blog.csdn.net/benben0503/article/details/8647020
1、创建Newarrivals.php文件:
[php] view plaincopy
<?php
/**
* This is the part of 'BmProducts' module for Magento,
* which allows easy access to product collection
* with flexible filters
*/
class Bestmagento_BmProducts_Block_Product_Newarrivals 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']) : 48;
}
function get_cur_page()
{
return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
}
/**
* Retrieve loaded category collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
**/
protected function _getProductCollection()
{
$date = $_GET['date'];
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
$collection = $this->_addProductAttributesAndPrices($collection)
->addAttributeToSelect('created_at')
->setOrder('created_at', 'desc')
->setPageSize($this->get_prod_count())
->setCurPage($this->get_cur_page());
if(!empty($date))
{
$this->_data['title'] = $date;
$collection->getSelect()->where('DATE(created_at) = ?',$date);
}
$this->setProductCollection($collection);
return $collection;
}
}
2、后台CMS列表添加Page页,设置Design内容为:
[html] view plaincopy
<reference name="content">
<block type="bmproducts/product_newarrivals" name="product_new" template="catalog/product/list.phtml">
<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>48</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>48</limit></action>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
不带分页可以只设置Content项为:
[html] view plaincopy
{{block type="bmproducts/product_newarrivals" name="newarrivals" title="New Arrivals" template="catalog/product/list.phtml"}}
3、在要显示目录的地方加如下代码:
[php] view plaincopy
<div class="support_left">
<div class="subitem">
<div class="title">New Arrivals</div>
<?php
$collection = Mage::getModel('catalog/product')->getResourceCollection()
->setOrder('created_at', 'desc');
$collection->getSelect()->group('CAST(created_at as date)');
//$collection->getSelect()->group('CAST(created_at as date)')->limit(5);
//echo $collection->getSelect();exit;
$date = array();
foreach($collection as $val)
{
?>
<div class="left_link"><a href="/new_arrivals?date=<?php echo date("Y-m-d",strtotime($val['created_at'])); ?>" rel="nofollow"><?php echo date("Y-m-d",strtotime($val['created_at'])); ?></a></div>
<?php
}
?>
</div>
</div>
1、创建Newarrivals.php文件:
[php] view plaincopy
<?php
/**
* This is the part of 'BmProducts' module for Magento,
* which allows easy access to product collection
* with flexible filters
*/
class Bestmagento_BmProducts_Block_Product_Newarrivals 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']) : 48;
}
function get_cur_page()
{
return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
}
/**
* Retrieve loaded category collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
**/
protected function _getProductCollection()
{
$date = $_GET['date'];
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
$collection = $this->_addProductAttributesAndPrices($collection)
->addAttributeToSelect('created_at')
->setOrder('created_at', 'desc')
->setPageSize($this->get_prod_count())
->setCurPage($this->get_cur_page());
if(!empty($date))
{
$this->_data['title'] = $date;
$collection->getSelect()->where('DATE(created_at) = ?',$date);
}
$this->setProductCollection($collection);
return $collection;
}
}
2、后台CMS列表添加Page页,设置Design内容为:
[html] view plaincopy
<reference name="content">
<block type="bmproducts/product_newarrivals" name="product_new" template="catalog/product/list.phtml">
<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>48</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>48</limit></action>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
不带分页可以只设置Content项为:
[html] view plaincopy
{{block type="bmproducts/product_newarrivals" name="newarrivals" title="New Arrivals" template="catalog/product/list.phtml"}}
3、在要显示目录的地方加如下代码:
[php] view plaincopy
<div class="support_left">
<div class="subitem">
<div class="title">New Arrivals</div>
<?php
$collection = Mage::getModel('catalog/product')->getResourceCollection()
->setOrder('created_at', 'desc');
$collection->getSelect()->group('CAST(created_at as date)');
//$collection->getSelect()->group('CAST(created_at as date)')->limit(5);
//echo $collection->getSelect();exit;
$date = array();
foreach($collection as $val)
{
?>
<div class="left_link"><a href="/new_arrivals?date=<?php echo date("Y-m-d",strtotime($val['created_at'])); ?>" rel="nofollow"><?php echo date("Y-m-d",strtotime($val['created_at'])); ?></a></div>
<?php
}
?>
</div>
</div>
相关文章推荐
- Android monkey 初步
- Nginx下Magento伪静态规则,适用于LNMP一键包
- Android M的App Links实现详解
- Two Sum-n方优化与C++map的使用
- URL 传+号到后台变空格问题解决方案
- android不是内部或外部命令,也不是可运行的程序或批处理文件
- View,Activity,Window三者的关系
- Android中的软件Watchdog
- 2015/06/26
- [SoapUI] 循环遍历某个Test Case下的所有Test Step,将Cookie传递给这些Test Step
- android studio debug
- Spring与Quartz的整合实现定时任务调度
- liunx下面新建一个文件然后上传到FTP
- 辅助方法
- Android调用系统功能获取当前经纬度
- 前端知识体系目录
- 程序员编程生涯中会犯的7个错误
- 回复《我要阻止做java开发的男朋友去创业型公司工作吗?》园友问题
- 写在那个毕业五年的日子(转)
- yii、yaf、ci等php框架性能对比