2

I added a custom grid in admin panel which shows all the Best seller product collections. (configurable products). The admin grid has the following columns:

entity_id     product_name    sku      ordered_qty

I am getting the Best seller product collection by using Mage::getResourceModel('reports/product_collection'); but while filling the admin grid, I am changing the product collection to related to catalog product collection. as shown below:

protected function _prepareCollection()
{
    $from = /* some date */;
    $to = /* some date */;

    $collection = Mage::getResourceModel('reports/product_collection')
        ->addAttributeToSelect('*')
        ->setStoreId($storeId)
        ->addOrderedQty($from, $to)

    $common_ids = array();

    foreach($collection as $product) {
        $common_ids[] = $product->getId();
    }

    $collection = Mage::getResourceModel('catalog/product_collection')
        ->addFieldToFilter('entity_id', $common_ids)
        ->addAttributeToSelect('*')
        ->addAttributeToSort('created_at', 'desc');
    $this->setCollection($collection);
    parent::_prepareCollection();
    return $this;
}

As you can see in the above code, I am getting the product collection twice because the "reports/product_collection" is not filling the admin grid. So, I did "catalog/product_collection" again to the collection which is filling the admin grid.

But "catalog/product_collection" is not filling the column ordered_qty because the ordered_qty column values are being prepared by "reports/product_collection".

How should I get the values for ordered_qty ?

  • please let me know if you can't understand my explanation. – Mr_Green May 21 '14 at 11:48
2

You are already getting the ordered_qty from the first collection.
You can remember them in an array by id and attach them to the second collection after calling parent::_prepareCollection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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