Magento 제품 컬렉션은 특별 가격 종료일을 기반으로 만든 날짜의 Desc 순서를 기반으로합니다.
-
13-12-2019 - |
문제
제품 수집을 가져 오려면 생성 된 날짜의 Desc 순서로 정렬되어 특별 가격 종료일이 현재 날짜보다 낮 으면 필터링합니다. 이 코드를 사용하여 정렬 할 수 있습니다.
if ($this->getCurrentOrder()) {
if(($this->getCurrentOrder())=='position'){
$this->_collection->setOrder('entity_id','desc');
} else {
$this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
}
}
.
그러나 나는 특별 가격 종료일 <오늘의 날짜로 더 많은 것을 필터링 할 수 없습니다. 누구도 도움이 될 수 있습니까?나는 정말로 그것을 고맙게 생각할 것이다.
감사합니다.
해결책
$now = Mage::getSingleton('core/date')->gmtDate();
$this->_collection->addAttributeToFilter('special_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $now),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
.
위의 코드는 특별 가격에 대한 종료일이 없거나 종료일이 미래에있는 경우의 제품만을 허용해야합니다.
[편집]
special_from_date
에 필터를 추가하려면 위의 코드를
$this->_collection->addAttributeToFilter('special_from_date', array('or'=> array(
0 => array('date' => true, 'to' => $now),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
. 제휴하지 않습니다 magento.stackexchange