php 按大多数查看的产品集合排序并按新日期过滤

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 按大多数查看的产品集合排序并按新日期过滤相关的知识,希望对你有一定的参考价值。

To

<?php
  if($this->showsoon_products)
      $showproductssoon = $this->showsoon_products;
  else
      $showproductssoon = 10;
      
  $storeId = Mage::app()->getStore()->getId();
  $todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); 
  $productssoon = Mage::getResourceModel('reports/product_collection')
      ->addAttributeToSelect('*')     
      ->setStoreId($storeId)
      ->addStoreFilter($storeId)
      ->addAttributeToFilter('news_to_date', array('or'=> array(
              0 => array('date' => true, 'from' => $todayDate),
              1 => array('is' => new Zend_Db_Expr('null')))
      ), 'left')
      ->setPageSize($showproductssoon);
  $productssoon->getSelect()->joinInner('report_event AS _table_views',' _table_views.object_id = e.entity_id','COUNT(_table_views.event_id) AS views')->group('e.entity_id')->order('views DESC');
  
  Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($productssoon);
  Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($productssoon);
  
?>    

From/To

<?php
  if($this->showsoon_products)
      $showproductssoon = $this->showsoon_products;
  else
      $showproductssoon = 10;
      
  $storeId = Mage::app()->getStore()->getId();
  $todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); 
  $productssoon = Mage::getResourceModel('reports/product_collection')
      ->addAttributeToSelect('*')     
      ->setStoreId($storeId)
      ->addStoreFilter($storeId)
      ->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')
      ->setPageSize($showproductssoon);
  $productssoon->getSelect()->joinInner('report_event AS _table_views',' _table_views.object_id = e.entity_id','COUNT(_table_views.event_id) AS views')->group('e.entity_id')->order('views DESC');
  
  Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($productssoon);
  Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($productssoon);
  
?>    

以上是关于php 按大多数查看的产品集合排序并按新日期过滤的主要内容,如果未能解决你的问题,请参考以下文章

从各种来源中选择项目,并按日期排序

如何按日期过滤并按代码进行表单查询?

SQLAlchemy:如何按两个字段分组并按日期过滤

SQL 按日期排序并按用户获取结果

核心数据按年份分组并按日期排序

具有特定条件计数的 Mongodb 聚合并按输出投影的日期范围过滤不能按预期工作