magento 每日新品展示

本文介绍了一个Magento扩展模块'BmProducts'的实现细节,该模块能够方便地展示新品,并支持按日期筛选。文中提供了Newarrivals.php文件的具体代码,以及如何在后台配置页面以使用这个模块。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、创建Newarrivals.php文件:

<?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内容为:

<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项为:

{{block type="bmproducts/product_newarrivals" name="newarrivals" title="New Arrivals" template="catalog/product/list.phtml"}}

3、在要显示目录的地方加如下代码:

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值