2009-12-29 42 views
1

我有一点困难。以下代码正确显示分配的产品,同时忽略最低价格。 “低至”选项。Magento帮助 - >有困难过滤新产品

<?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()): ?> 

我错过了什么?谢谢

回答

2

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

<?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重复这个过程。清除初始产品收集的最佳方式是什么?