views:

319

answers:

1

I'm having a little dilemma. The following code correctly displays the assigned products while ignoring the minimal pricing. The "as low as" option.

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

Minor adjustment of last line, correctly shows the "as low as" price, but ends up adding un-assigned products within said category.

if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>

What am I missing? Thanks

+1  A: 

Here's the solution that worked for anyone interested.

<?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');
?>

I am interested repeating this procedure within same file with another category id. What's the best way clearing the initial product collection.

monocat