0

I need to get the quantity of products sold on my report module. Actually I'm only getting the ordered quantity, but I need to get the quantity of all finished orders.

Here is my actual code:

public function _prepareCollection()
{
    $collection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addOrderedQty();

    $this->setCollection($collection);
    parent::_prepareCollection();

    return $this;
}

protected function _prepareColumns()
{
    $this->addColumn('name', array(
        'header' => $this->_getHelper()->__('Name),
        'type' => 'text',
        'index' => 'name'
    ));
    $this->addColumn('ordered_qty', array(
        'header' => $this->_getHelper()->__('Quantity Sold'),
        'type' => 'number',
        'index' => 'ordered_qty'
    ));

    return parent::_prepareColumns();
}

How can I get the desired result? Thanks in advance.

0

This code works fine for me.

public function _prepareCollection()
{
    $collection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect('*')->addOrderedQty();

    $this->setCollection($collection);
    parent::_prepareCollection();

    return $this;
}

protected function _prepareColumns()
{
    $this->addColumn('name', array(
        'header' => 'Name', // Single quote missing
        'type' => 'text',
        'index' => 'name'
    ));
    $this->addColumn('ordered_qty', array(
        'header' => 'Quantity Sold',
        'type' => 'text',
        'index' => 'ordered_qty'
    ));

    return parent::_prepareColumns();
}

I have removed the $this->_getHelper().

  • The problem with this code is that I get the ordered quantity, but I need the quantity of the ordered ones that have been paid(I'm actually trying to get now the invoiced quantity, but for no avail) – Pedro de Albuquerque Jun 6 '18 at 15:17
  • Then you need to modify the code and get collection of invoiced qty from invoice item table. – Sukumar Gorai Jun 6 '18 at 15:54
  • I tried that, but the invoiced quantity that appeared was inconsistent, can you give me a working example? – Pedro de Albuquerque Jun 6 '18 at 17:37

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.