Get collection with ordered quantities for admin grid
-
30-10-2019 - |
質問
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
?
正しい解決策はありません