zoukankan      html  css  js  c++  java
  • magento 每日新品展示

    http://blog.csdn.net/benben0503/article/details/8647020

    1、创建Newarrivals.php文件:

    [php] view plaincopy
     
    1. <?php  
    2. /** 
    3.  * This is the part of 'BmProducts' module for Magento, 
    4.  * which allows easy access to product collection 
    5.  * with flexible filters 
    6.  */  
    7.   
    8. class Bestmagento_BmProducts_Block_Product_Newarrivals extends Mage_Catalog_Block_Product_List  
    9. {  
    10.     function get_prod_count()  
    11.     {  
    12.         //unset any saved limits  
    13.         Mage::getSingleton('catalog/session')->unsLimitPage();  
    14.         return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 48;  
    15.     }  
    16.   
    17.     function get_cur_page()  
    18.     {  
    19.         return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;  
    20.     }  
    21.   
    22.     /** 
    23.     * Retrieve loaded category collection 
    24.     * 
    25.     * @return Mage_Eav_Model_Entity_Collection_Abstract 
    26.     **/  
    27.     protected function _getProductCollection()  
    28.     {  
    29.         $date = $_GET['date'];  
    30.   
    31.         $collection = Mage::getResourceModel('catalog/product_collection');  
    32.         $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());  
    33.   
    34.         $collection = $this->_addProductAttributesAndPrices($collection)  
    35.             ->addAttributeToSelect('created_at')  
    36.             ->setOrder('created_at', 'desc')  
    37.             ->setPageSize($this->get_prod_count())  
    38.             ->setCurPage($this->get_cur_page());  
    39.               
    40.         if(!empty($date))  
    41.         {  
    42.             $this->_data['title'] = $date;  
    43.             $collection->getSelect()->where('DATE(created_at) = ?',$date);  
    44.         }  
    45.   
    46.         $this->setProductCollection($collection);  
    47.   
    48.         return $collection;  
    49.     }  
    50. }  


    2、后台CMS列表添加Page页,设置Design内容为:

    [html] view plaincopy
     
    1. <reference name="content">  
    2.    <block type="bmproducts/product_newarrivals" name="product_new" template="catalog/product/list.phtml">  
    3.       <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">  
    4.          <block type="page/html_pager" name="product_list_toolbar_pager" />  
    5.          <action method="setDefaultGridPerPage"><limit>48</limit></action>  
    6.          <action method="addPagerLimit"><mode>grid</mode><limit>48</limit></action>  
    7.       </block>  
    8.       <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>  
    9.    </block>  
    10. </reference>  


    不带分页可以只设置Content项为:

    [html] view plaincopy
     
    1. {{block type="bmproducts/product_newarrivals" name="newarrivals" title="New Arrivals" template="catalog/product/list.phtml"}}  


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

    [php] view plaincopy
     
      1. <div class="support_left">  
      2.                         <div class="subitem">  
      3.                             <div class="title">New Arrivals</div>  
      4.                     <?php  
      5.                         $collection = Mage::getModel('catalog/product')->getResourceCollection()  
      6.                                     ->setOrder('created_at', 'desc');  
      7.                         $collection->getSelect()->group('CAST(created_at as date)');  
      8.                         //$collection->getSelect()->group('CAST(created_at as date)')->limit(5);  
      9.                         //echo $collection->getSelect();exit;  
      10.                         $date = array();  
      11.                         foreach($collection as $val)  
      12.                         {  
      13.                     ?>  
      14.                             <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>  
      15.                     <?php  
      16.                         }  
      17.                     ?>  
      18.                         </div>  
      19.                     </div>  
    Flag Counter
  • 相关阅读:
    iOS 苹果开发证书失效的解决方案(Failed to locate or generate matching signing assets)
    iOS NSArray数组过滤
    App Store2016年最新审核规则
    iOS 根据字符串数目,自定义Label等控件的高度
    iOS 证书Bug The identity used to sign the executable is no longer valid 解决方案
    Entity FrameWork 增删查改的本质
    EF容器---代理类对象
    Entity FrameWork 延迟加载本质(二)
    Entity FrameWork 延迟加载的本质(一)
    Entity FrameWork 增删查改
  • 原文地址:https://www.cnblogs.com/sunsoftware/p/4602009.html
Copyright © 2011-2022 走看看