3
votes

I'm trying to add new columns in Magento's "Products Ordered" report. I have added custom options to each product and I'm wondering how I can make these custom options show in the reports view.

So far I've read that one can add columns in the app/code/core/Mage/Adminhtml/Block/Report/Product/Ordered/Grid.php like so:

$this->addColumn('sku', array(
        'header'    =>Mage::helper('reports')->__('Product Sku'),
        'sortable'  =>false,
        'index'     =>'sku'
));

But how would I go about adding custom options I've created for my products? I'm using Magento Community Version 1.6.2.

Thanx in advance!

3

3 Answers

2
votes

Actually you have to add the code :

$this->addColumn('sku', array(
        'header'    =>Mage::helper('reports')->__('Product Sku'),
        'index'     =>'sku'
));

in the method _prepareColumns of the file app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.php (not Ordered)

0
votes

The class you would have to extend is Mage_Reports_Model_Resource_Product_Ordered_Collection, more specifically the parent classes method Mage_Reports_Model_Resource_Product_Collection::addOrderedQty().

Adding the product_options attribute will give you access to any options set on the ordered items.
There is one issue though:

// on the select instance:
->group('order_items.product_id')

This will merge any records by product id. So if the same product was ordered twice, you will only see the options of one of them.
What this boils down to is you should probably build a separate report built on this one, where you also group by the product_options.

Once you have the the product collection with the product options, simply call
$product->processBuyRequest(unserialize($product->getData('product_options'))). After that all options are available using $product->getCustomOptions() to retrieve the array or getCustomOption($code) to retrieve a single one.

0
votes

Don't edit the core, use observers:

    public function appendCustomColumn(Varien_Event_Observer $observer)

        if ($block->getType() == 'adminhtml/report_product_sold_grid') {
            $block->addColumnAfter('Product Name', array(
                'header'    => 'Sku',
                'type'      => 'text',
                'index'     => 'sku',
            ), 'sku');
        }
}