It is sad to say, but in spite of the contemporary well developed and tool-rich marketing system, the main methods to attract customers and increase sales are still quite traditional and involve various promotions, sales, discounts and coupons. Of course, Magento provides a sufficiently rich functionality for analysis and statistics. But, as you know, there are never too many tools. That is why we decided to make another present surprise to our sales managers.
Basically, there is, of course, available a default report on used coupons under the Reports – Sales – Coupons section. But we have decided to push the limits and go further. First of all, we will start with creating a module with a custom grid (check here for more details about creating a module).
We will describe only the main part – that is creating of a grid.
* Prepare grid collection
* @return Mage_Adminhtml_Block_Widget_Grid
protected function _prepareCollection()
$collection = Mage::getModel('sales/order')->getCollection();
$collection->addAttributeToFilter('coupon_code', array('notnull' => TRUE));
$collection->addAttributeToFilter('coupon_code', array('neq' => ''));
$collection->getSelect()->joinLeft( array('salesrule_coupon'=>$collection->getTable('salesrule/coupon')), 'main_table.coupon_code = salesrule_coupon.code', array('salesrule_coupon.rule_id'));
$collection->getSelect()->joinLeft( array('salesrule_rule'=>$collection->getTable('salesrule/rule')), 'salesrule_coupon.rule_id = salesrule_rule.rule_id', array('salesrule_rule.name'));
The main request is to find all orders where соupоn_соde is specified. This will provide us with the number, amount, status of the order and the used coupon itself. However, coupon code looks not informative enough. That is why let’s also add the name of the coupon: simply join the models salesrule/coupon and salesrule/rule and thus we will get the information about the rule used.
Seems to me, now it looks pretty informative and functional.
Actually, we could already stop here, yet there is still a question to be answered: What should we actually do with all these results?
Let’s add the possibility to instantly go to coupon and order pages.
Not to show the entire listing let me give you just an example for the name of the rule. Indicate your renderer in the grid’s block:
'header' => Mage::helper('salesrule')->__('Rule Name'),
'align' => 'left',
'index' => 'name',
'renderer' => $this->getNoRenderer()?'':'belvg_couponusage/adminhtml_couponsusage_grid_renderer_rule',
'filter_index' => 'salesrule_rule.name'
And the renderer itself:
public function render(Varien_Object $row)
$rule_id = $row->getRuleId();
$name = $row->getName();
$rule_url = $this->getUrl('adminhtml/promo_quote/edit', array('id' => $rule_id));
return sprintf('<a href="%s">%s</a>', $rule_url, $name);
Now it looks like to be complete. Let’s see how the module will perform in test runs.
Check out the ready-to-use module on GitHub:
Download CouponUsage from GitHub