1

我有点进退两难。以下代码在忽略最低定价的情况下正确显示分配的产品。“低至”选项。

<?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()): ?>

我错过了什么?谢谢

4

1 回答 1

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 的同一文件中重复此过程。清除初始产品集合的最佳方法是什么。

于 2009-12-30T20:55:04.010 回答