1

I'm trying to get a new products widget to show items based on the new_from and new_to dates, but I can't find where to configure it. Right now, the /all-new-products page shows items that were added recently, but have a new_from and new_to date that doesn't include today's date.

This is what the new_from and new_to dates are for, right? So where do I configure Magento to look at those?

1

short answer: Choose "New products" in the "Display Type" Select

longer answer:

in Mage_Catalog_Block_Product_Widget_New on line 79-90 the collections are built:

protected function _getProductCollection()
{
    switch ($this->getDisplayType()) {
        case self::DISPLAY_TYPE_NEW_PRODUCTS:
            $collection = parent::_getProductCollection();
            break;
        default:
            $collection = $this->_getRecentlyAddedProductsCollection();
            break;
    }
    return $collection;
}

the possible constants are DISPLAY_TYPE_ALL_PRODUCTS and DISPLAY_TYPE_NEW_PRODUCTS. Using the Type DISPLAY_TYPE_ALL_PRODUCTS ends up in getting all Products sorted by created_at.

So choosing the New Products (Type DISPLAY_TYPE_NEW_PRODUCTS) gets another collection that filters all products between news_from_date and news_to_date

class Mage_Catalog_Block_Product_New {
[...]
protected function _getProductCollection()
{
    $todayStartOfDayDate  = Mage::app()->getLocale()->date()
        ->setTime('00:00:00')
        ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

    $todayEndOfDayDate  = Mage::app()->getLocale()->date()
        ->setTime('23:59:59')
        ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

    /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */
    $collection = Mage::getResourceModel('catalog/product_collection');
    $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());


    $collection = $this->_addProductAttributesAndPrices($collection)
        ->addStoreFilter()
        ->addAttributeToFilter('news_from_date', array('or'=> array(
                0 => array('date' => true, 'to' => $todayEndOfDayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
        ->addAttributeToFilter('news_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $todayStartOfDayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
        ->addAttributeToFilter(
            array(
                array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
                array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))
            )
        )
        ->addAttributeToSort('news_from_date', 'desc')
        ->setPageSize($this->getProductsCount())
        ->setCurPage(1)
    ;

    return $collection;
}
[...]
}

hope that helps.

| improve this answer | |
  • I don't have a "Display Type" select, I have a "Type" select and the only option for new products is "Catalog New Products List". this answer appears to be for a different version than mine, perhaps Magento GO? – David Wilkins Dec 1 '14 at 16:01
  • The display type has been added in Magento 1.8 – Fabian Schmengler Jan 4 '16 at 11:19
0

Right, this is what the new products widget does. In later Magento versions there is a "display type" option which can be set to "All Products" (sort by creation date) or "New Products" (classic behavior), but up to CE 1.7 it's always depending on the "new from" and "new to" dates.

What you can check:

  • does /all-new-products really use the "new products" widget?
  • did you refresh all the indexes?
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.