I'm trying to override the prepareProductCollection to show a list of products which will have all in stock products and one month old out of stock products.

So far I was able to filter out the products as I want to but the pagination is not working correctly.

protected function _getProductCollection()
    if (is_null($this->_productCollection)) {
        // filter product colletion
        foreach ($this->_productCollection as $key => $product ) {

            $date_created       = $product->getCreatedAt();                
            $datetime           = new DateTime($date_created);
            $month_created      = $datetime->format('Y-m-d');

            $current_date       = date("Y-m-d");
            $current_time       = new DateTime($current_date);
            $onemonthbuffer     = $current_time->modify('-3 month')->format('Y-m-d');

            if ( !$product->isSaleable() ){
                 if ( ($month_created < $onemonthbuffer) ) {

    return $this->_productCollection;

1 Answer 1


You can fetch using this code.

$date = Mage::getModel('core/date')->date('Y-m-d h:m:s');
$startDate =  Mage::getModel('core/date')->date('Y-m-d 0:0:0', strtotime($date." -30 days"));

$products = Mage::getModel('catalog/product')
                ->addAttributeToFilter('is_in_stock', array('eq' => 0))
                ->addFieldToFilter('created_at', array('from' => $startDate, 'to' => $date));
  • Nah, this returns me an empty object. I dont want to show only out of stock products btw. I need the whole list (with and without out of stock products), just that the out of stock products should be 1 month old Nov 16, 2018 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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