2009-12-29 43 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重複這個過程。清除初始產品收集的最佳方式是什麼?