php - Magento 1.7 sorting by ordered quantity - bestseller products issues -
there several cases reported standard solution(s) query not work (similar questions on abunding,with no definitive solution whatsoever).
what 1 retrieve collection of "bestsellers" use query builder:
$storeid = mage::app()->getstore()->getid(); $collection = mage::getresourcemodel('reports/product_collection'); $collection->setvisibility(mage::getsingleton('catalog/product_visibility')->getvisibleincatalogids()); $collection = $collection ->addfieldtofilter('*') ->addorderedqty() ->addstorefilter() ->setstoreid($storeid) ->setorder('ordered_qty', 'desc') ->setpagesize(10) ->setcurpage(1);
now, $collection
result holds bogus values , it's missing important attributes altogether (no name, price, etc.). cannot try this core-code workaround in 1.7.
could please post solution magento 1.7 verified/certified/tested? (or latest magento release).
this may or may not work you, might not efficient way, job me here merged parts of code.
$storeid = mage::app()->getstore()->getid(); $collection = mage::getresourcemodel('reports/product_collection'); $collection->setvisibility(mage::getsingleton('catalog/product_visibility')->getvisibleincatalogids()); $collection = $collection ->addfieldtofilter('*') ->addstorefilter() ->setstoreid($storeid) ->setpagesize(10) ->setcurpage(1); $collection->getselect() ->joinleft( 'sales_flat_order_item order_item', 'e.entity_id = order_item.product_id', 'sum(order_item.qty_ordered) ordered_qty') ->group('e.entity_id') ->order('ordered_qty desc') ;
Comments
Post a Comment