Magento Expert Forum - Improve your Magento experience

Results 1 to 5 of 5

How to fetch 5 bestsellers products programmatically?

  1. #1

  2. #2
    Junior Member PeterJ's Avatar
    Join Date
    Jan 2015
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    You can get it by this simple line

    PHP Code:
    $_productCollection Mage::getResourceModel('sales/report_bestsellers_collection')
            ->
    setModel('catalog/product')
        ; 
    Or you may look at this extension

    http://www.magentocommerce.com/magen...extension.html

    Maybe this article can help you too

    http://inchoo.net/magento/bestseller...ts-in-magento/

  3. #3
    New member
    Join Date
    Jul 2015
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you for help peter

  4. #4
    Junior Member knowband.plugins's Avatar
    Join Date
    Jul 2016
    Location
    Noida, India
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    $storeId = (int) Mage::app()->getStore()->getId();

    // Date
    $date = new Zend_Date();
    $toDate = $date->setDay(1)->getDate()->get('Y-MM-DD');
    $fromDate = $date->subMonth(1)->getDate()->get('Y-MM-DD');

    $collection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect(Mage::getSingleton('catalo g/config')->getProductAttributes())
    ->addStoreFilter()
    ->addPriceData()
    ->addTaxPercents()
    ->addUrlRewrite()
    ->setPageSize(5);

    $collection->getSelect()
    ->joinLeft(
    array('aggregation' => $collection->getResource()->getTable('sales/bestsellers_aggregated_monthly')),
    "e.entity_id = aggregation.product_id AND aggregation.store_id={$storeId} AND aggregation.period BETWEEN '{$fromDate}' AND '{$toDate}'",
    array('SUM(aggregation.qty_ordered) AS sold_quantity')
    )
    ->group('e.entity_id')
    ->order(array('sold_quantity DESC', 'e.created_at'));

    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection );
    $collection = $collection->getData();

    $collection will give 5 bestseller products.




    Regards,

    Knowband Plugins | Buy Best Magento Extensions

  5. #5
    Junior Member
    Join Date
    Aug 2016
    Posts
    72
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    <!--?php
    Mega::getResourceModel('reports/product_collection')-->addOrderedQty()->addAttributeToSelect('*')->setPage(1,5)->load();
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •