在magento报表渲染器自定义中获取订购数量

时间:2017-08-28 03:57:19

标签: magento renderer

我想获得产品的订购数量。我可以获得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();
}

请帮忙!

1 个答案:

答案 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_CollectionMage_Reports_Model_Resource_Product_Collection课程,在这些课程中您会找到一些有趣的自解释方法,例如:

public function setDateRange($from, $to)
public function setStoreIds($storeIds)
public function addOrdersCount($from = '', $to = '')