Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Home Page, show all products between two dates
 
cibernoid
Sr. Member
 
Avatar
Total Posts:  208
Joined:  2008-02-12
 

Hello, I am using this class to filter all product with the custom attribute “new”:

<?php
class MyCompany_New_Block_News extends Mage_Catalog_Block_Product_Abstract
{
    
public function __construct()
    
{
        parent
::__construct();

        
$storeId    Mage::app()->getStore()->getId();
            
$product    Mage::getModel('catalog/product');
                
$category    Mage::getModel('catalog/category'); //'stuff' category
        /* @var $product Mage_Catalog_Model_Product */
        
$todayDate  $product->getResource()->formatDate(time());
        
$products   $product->setStoreId($storeId)->getCollection()
            
#->addAttributeToFilter('new', array('yes'=>true))
                /*->addCategoryFilter($category)*/
            
->addAttributeToSelect(array('name''price''small_image'), 'inner')
            ->
addAttributeToSelect(array('special_price''special_from_date''special_to_date'), 'left');
        
$products->getSelect()->order('rand()'); 
       /* @var $products Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */
       
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
     
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

      
$products->setOrder('hot_deals')->setPageSize(5)->setCurPage(1);

        
$this->setProductCollection($products);
    
}
}

Now I’m trying to show all product between two dates (news_from_date and news_to_date) using $todayDate to perform the check.

I’ve come up with the following filter, but it doesn’t work:

->addAttributeToFilter('news_from_date', array('date'=>true'to'=> $todayDate))
            ->
addAttributeToFilter(array(array('attribute'=>'news_to_date''date'=>true'from'=>$todayDate), array('attribute'=>'news_to_date''is' => new Zend_Db_Expr('null'))),'','left')
            ->
addAttributeToSort('news_from_date','desc')

Any clue, please? Thanks in advance

 
Magento Community Magento Community
Magento Community
Magento Community
 
jlenz
Jr. Member
 
Total Posts:  8
Joined:  2010-05-12
 

Did you ever find a solution to this?  I’m also looking for this type of filter.

 
Magento Community Magento Community
Magento Community
Magento Community
 
satish
Enthusiast
 
Total Posts:  812
Joined:  2008-03-24
34,mantri Sadan,Shivaji Nagar,Nagpur,MS,India 4400
 

addAttributeToFilter(’news_from_date’, array(’date’=>true, ‘to’=> $todayDate))
->addAttributeToFilter(array(array(’attribute’=>’news_to_date’, ‘date’=>true, ‘from’=>$todayDate), array(’attribute’=>’news_to_date’, ‘is’ => new Zend_Db_Expr(’null’))),’’,’left’)
->addAttributeToSort(’news_from_date’,’desc’)

In Your code You have ‘to’=> $todayDate and ‘from’=>$todayDate so it will just check if you have uploaded any product today.

Satish

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top