【问题标题】:Magento Help -> Having difficulty FILTERING new productsMagento 帮助 -> 过滤新产品有困难
【发布时间】:2009-12-29 05:02:41
【问题描述】:

我有点进退两难。以下代码在忽略最低定价的情况下正确显示分配的产品。 “低至”选项。

<?php 

$cat_id = 123; // category id
$category = Mage::getModel('catalog/category')->load($cat_id);

$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);        

$_products = $category->
getProductCollection()->
addCategoryFilter($category)->
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')->            
addAttributeToSelect('*');

if (($this->getProductCollection()) && $_products->getSize()): ?>

最后一行的小幅调整,正确显示“最低”价格,但最终在所述类别中添加了未分配的产品。

if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>

我错过了什么?谢谢

【问题讨论】:

    标签: php magento e-commerce categories product


    【解决方案1】:

    这是对任何感兴趣的人都有效的解决方案。

    <?php 
    
    if (($_products = $this->getProductCollection()) && $_products->getSize()):
    
    $cat_id = 123; // category id
    $category = Mage::getModel('catalog/category')->load($cat_id);
    
    $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);         
    
    $_products = $this
    ->getProductCollection()
    ->addCategoryFilter($category)
    ->addAttributeToSelect('*')
    ->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');
    ?>
    

    我有兴趣在具有另一个类别 ID 的同一文件中重复此过程。清除初始产品集合的最佳方法是什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 1970-01-01
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多