2009-12-29 3 views
1

약간의 딜레마가 있습니다. 다음 코드는 최소 가격을 무시하면서 할당 된 제품을 올바르게 표시합니다. "as as as low"옵션.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와 반복하는 데 관심이 있습니다. 초기 제품 컬렉션을 지우는 가장 좋은 방법은 무엇입니까?

관련 문제