0
我已經創建了應用特殊價格的產品集合,但是我不知道如何在應用目錄價格規則時獲取產品集合。Magento:需要在應用的目錄價格規則上獲得產品集合
下面是代碼,從而獲得特殊價格的產品,
public function getSpecialPriceProducts()
{
$categoryID = $this->getCategoryId();
if($categoryID)
{
$category = new Mage_Catalog_Model_Category();
$category->load($categoryID); // this is category id
$collection = $category->getProductCollection();
} else
{
$collection = Mage::getResourceModel('catalog/product_collection');
}
$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->addAttributeToSort('created_at', 'desc');
$collection->addStoreFilter()
->addAttributeToSelect(array('name', 'price', 'short_description','image','small_image','url_key'), 'inner');
$collection->addAttributeToFilter('special_price', array('gt' => 0));
$collection->addAttributeToFilter('special_to_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_from_date', array('or'=> array(
0 => array('date' => true, 'from' => $tomorrowDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left');
return $collection;
}
任何人都可以請指導我如何獲得所在目錄價格規則應用於產品列表?提前致謝。
你好,謝謝你的解決方案。你在哪個文件中放置了這個代碼? – zekia
沒有特定的文件。您可以將它添加到模型/塊文件中,並且可以使用它。 – shyammtp