【问题标题】:Order products in a category with "New" items listed first in Magento在 Magento 中首先列出“新”项目的类别中订购产品
【发布时间】:2011-04-29 00:53:28
【问题描述】:

在显示 Magento 类别时,是否可以在集合的开头列出任何新产品(具有“new from”和“new to”日期的产品),以便它们显示在该类别的第一页上而不是基于当前排序的默认位置?

是否需要有两个查询?

谢谢!

【问题讨论】:

    标签: magento categories


    【解决方案1】:

    news_from_datenews_to_date对产品进行排序的代码:-

    $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
    
    $productCollection->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')
                     ->addAttributeToSort('news_from_date', 'desc');
    

    您可以在Mage_Catalog_Block_Product_New类查看新产品代码

    (app/code/core/Mage/Catalog/Block/Product/New.php)

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多