0

I'm trying to get all sold products for a specific store view using the following code.

$_productCollection = Mage::getResourceModel('reports/product_collection')
        ->addOrderedQty($fromDate, $toDate, true)
        ->setStore(4)
        ->addStoreFilter(4)
        ->setOrder('ordered_qty', 'desc');
echo '<pre>';
echo ($_productCollection->count());

This only returns 2 products, but If I look in the backend at orders for that given date range there are a total of 4 products.

What am I doing wrong?

UPDATE :

I found that if I create an order from the backend using a configurable product then it's not visible using my code, is it possible to get that data?

2
  • Try to use reindex of products. May 10, 2017 at 13:41
  • @VadymKalin : yeah still not working May 11, 2017 at 7:07

1 Answer 1

0

At last I've done in following way

$orders = Mage::getResourceModel('sales/order_collection')
            ->addAttributeToFilter('created_at', array('from'=>$fromDate, 'to'=>$toDate))
            ->addFieldToSelect('*')
            ->setOrder('created_at', 'desc')
            ->addFieldToFilter('store_id',$storeId);
foreach ($orders as $_order):
  $orderitems = $_order->getAllVisibleItems();
  foreach ($orderitems as $orderitem):
    $_product = $orderitem->getProduct();
  endforeach;
endforeach;

And it's returning proper data.

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.