創造日のDESC順序の特別価格終了日に基づくMagento製品コレクションFetch
-
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