skip to Main Content

I want to display sold products for 10 days after customer ordered that product in magento 1.9.3

2

Answers


  1. It’s not very difficult with the report classes :

    $from = date('Y-m-d', strtotime('-10 days'));
    $to = date('Y-m-d');
    
    $productIds = Mage::getResourceModel('reports/product_ordered_collection')
        ->setDateRange($from, $to)
        ->getColumnValues('entity_id');
    

    You now have an array of all the IDs of products ordered the 10 last days, you are free to load a product collection filtered with this array, like that :

    $products = Mage::getResourceModel('catalog/product_collection')
        ->addAttributeToSelect('*')
        ->addIdFilter($orders);
    
    Login or Signup to reply.
  2. To reply to your comment : the code in my answer above this one will give you a collection of the last 10 days sold products that you can exploit. If you want to filter products that are out of stock, use this piece of code on the collection above :

    Mage::getSingleton('cataloginventory/stock')
        ->addInStockFilterToCollection($products);
    

    You can add a category filter too if you need :

    $products->addCategoryFilter($categoryModel);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search