我想获得产品的订购数量。我可以获得sku,名称,价格等。但我无法获得订购数量。 这就是我到目前为止:
public function render(Varien_Object $row)
{
$sku = Mage::getModel("catalog/product")->load($row->getId())->getSku();
$price = Mage::getModel("catalog/product")->load($row->getId())->getPrice();
$quantity = Mage::getModel("catalog/product")->load($row->getId())->getQtyOrdered();
}
请帮忙!
答案 0 :(得分:0)
以下是你如何做到这一点:
$orderedQty = 0;
$report = Mage::getResourceModel('reports/product_sold_collection')
->addOrderedQty() //you can also filter by date range, like ->addOrderedQty($from, $to) with proper SQL dates
->addIdFilter($row->getId())
->getFirstItem();
if ($report) {
$orderedQty = $report->getOrderedQty();
}
此外,您可能希望深入了解Mage_Reports_Model_Resource_Product_Sold_Collection
和Mage_Reports_Model_Resource_Product_Collection
课程,在这些课程中您会找到一些有趣的自解释方法,例如:
public function setDateRange($from, $to)
public function setStoreIds($storeIds)
public function addOrdersCount($from = '', $to = '')