0

how can i get sales report based on customer group

Bacially i want to add extra filter customer group to amdin > report > sales > order

How i can do it pls help , if possible via module observer will be helpful

4
  • could not figure out how to start do , which observer to call for that
    – mcoder
    Commented Feb 15, 2015 at 8:05
  • I think you want to start here: \Mage_Sales_Block_Adminhtml_Report_Filter_Form_Order. In the backend are a lot of events "missing", so I don't think you can avoid rewrites Commented Feb 15, 2015 at 8:11
  • can i do it via any observer ??
    – mcoder
    Commented Feb 15, 2015 at 8:18
  • I don'T think so, but I simple don't know. Search for an event. If you find one, use it. If you don't, rewrite, add your own and then use this Commented Feb 15, 2015 at 10:08

2 Answers 2

2

Adding the form filter field can be done easily via observer like this: In your module config.xml

<config>
    <adminhtml>
        <events>

            <adminhtml_block_html_before>
                <observers>
                    <yourmodule_append_custom_sales_report_filters>
                        <type>singleton</type>
                        <class>yourmodule/observer</class>
                        <method>appendCustomSalesReportFilters</method>
                    </yourmodule_append_custom_sales_report_filters>
                </observers>
            </adminhtml_block_html_before>

        </events>
    </adminhtml>
</config>

In your Observer:

public function appendCustomSalesReportFilters($_observer)
{
    $_block = $_observer->getBlock();
    if (!isset($_block)) {
        return $this;
    }
    //Mage_Sales_Block_Adminhtml_Report_Filter_Form_Order
    Mage::log($_block->getType());
    if ($_block->getType() == 'sales/adminhtml_report_filter_form_order') {
        $_form = $_block->getForm();
        $fieldset = $_form->getElement('base_fieldset');
        $fieldset->addField('some_field', 'text', array(
            'name' => 'some_field',
            'label' => Mage::helper('cms')->__('Some Field'),
            'title' => Mage::helper('cms')->__('Some Field'),
        )
        );
    }
}

This will add your custom field to the filter form of the Sales Report. Sales Report Filters Block

Further, try to do the same to add the grid column. Afterwards, check if filter works by default, as I think the grid collection collects the grid columns and applies the filters from the form by default. If not, you'll have to rewrite some collection.

0

About GridControl

Just change customer_id to group_id. Then you have the group_id.

But I think you can't add the customer group name. The problem is, that you need to first join from sales_flat_order_grid to sales_flat_order and then to customer_group. The second join can't be made at the moment. At least I didn't find fast a way. You are welcome to read in https://github.com/magento-hackathon/GridControl/blob/master/src/app/code/community/FireGento/GridControl/Model/Observer.php maybe you find a way.

If not feel free to send a PR to join tables without fields :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.