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

Filter product by attribute in list.phtml page
 
meglioth
Sr. Member
 
Total Posts:  98
Joined:  2010-04-09
 

Hi, I created two attributes for a product in Magento.
The two attributes are of type date.

An attribute is called: publish_start
The other attribute is called: publish_end

Now I would like the product categories, only exhibit products within the date range of the above attributes.

example:
Chair -> publish_start: 13/3/26 18:00
Chair -> publish_end: 04/26/13 17:59

It can not be displayed when the page ~\app\design\frontend\default\default\template\catalog\product\list.phtml run because the publication date is greater than the current date.
Mesa -> publish_start: 04/13/26 18:00
Mesa -> publish_end: 26/05/13 17:59

Would something like:

Only products with date display publish_start> = current_date and publish_end <= current_date
Currently I filter these dates within the foreach on page ~\app\design\frontend\default\default\template\catalog\product\list.phtml

But it is very slow.

How can I do this with filters? Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Indies Inc
Sr. Member
 
Avatar
Total Posts:  193
Joined:  2013-09-18
 

Hi,
To get the collection between the two dates range, You can use the following pattern into your code to filter the collection and get the better result.

$productcollection Mage::getModel('catalog/product')->getCollection()
        ->
addAttributeToFilter('start_date',array('gteq' => $newstartdate))
        -> 
addAttributeToFilter('end_date',array('lteq' => $newenddate));

Hope this will help you.

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