1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Coupons_Grid extends Mage_Adminhtml_Block_Widget_Grid
35: {
36: 37: 38:
39: public function __construct()
40: {
41: parent::__construct();
42: $this->setId('couponCodesGrid');
43: $this->setUseAjax(true);
44: }
45:
46: 47: 48: 49: 50:
51: protected function _prepareCollection()
52: {
53: $priceRule = Mage::registry('current_promo_quote_rule');
54:
55: 56: 57:
58: $collection = Mage::getResourceModel('salesrule/coupon_collection')
59: ->addRuleToFilter($priceRule)
60: ->addGeneratedCouponsFilter();
61:
62: $this->setCollection($collection);
63:
64: return parent::_prepareCollection();
65: }
66:
67: 68: 69: 70: 71:
72: protected function _prepareColumns()
73: {
74: $this->addColumn('code', array(
75: 'header' => Mage::helper('salesrule')->__('Coupon Code'),
76: 'index' => 'code'
77: ));
78:
79: $this->addColumn('created_at', array(
80: 'header' => Mage::helper('salesrule')->__('Created On'),
81: 'index' => 'created_at',
82: 'type' => 'datetime',
83: 'align' => 'center',
84: 'width' => '160'
85: ));
86:
87: $this->addColumn('used', array(
88: 'header' => Mage::helper('salesrule')->__('Used'),
89: 'index' => 'times_used',
90: 'width' => '100',
91: 'type' => 'options',
92: 'options' => array(
93: Mage::helper('adminhtml')->__('No'),
94: Mage::helper('adminhtml')->__('Yes')
95: ),
96: 'renderer' => 'adminhtml/promo_quote_edit_tab_coupons_grid_column_renderer_used',
97: 'filter_condition_callback' => array(
98: Mage::getResourceModel('salesrule/coupon_collection'), 'addIsUsedFilterCallback'
99: )
100: ));
101:
102: $this->addColumn('times_used', array(
103: 'header' => Mage::helper('salesrule')->__('Times Used'),
104: 'index' => 'times_used',
105: 'width' => '50',
106: 'type' => 'number',
107: ));
108:
109: $this->addExportType('*/*/exportCouponsCsv', Mage::helper('customer')->__('CSV'));
110: $this->addExportType('*/*/exportCouponsXml', Mage::helper('customer')->__('Excel XML'));
111: return parent::_prepareColumns();
112: }
113:
114: 115: 116: 117: 118:
119: protected function _prepareMassaction()
120: {
121: $this->setMassactionIdField('coupon_id');
122: $this->getMassactionBlock()->setFormFieldName('ids');
123: $this->getMassactionBlock()->setUseAjax(true);
124: $this->getMassactionBlock()->setHideFormElement(true);
125:
126: $this->getMassactionBlock()->addItem('delete', array(
127: 'label'=> Mage::helper('adminhtml')->__('Delete'),
128: 'url' => $this->getUrl('*/*/couponsMassDelete', array('_current' => true)),
129: 'confirm' => Mage::helper('salesrule')->__('Are you sure you want to delete the selected coupon(s)?'),
130: 'complete' => 'refreshCouponCodesGrid'
131: ));
132:
133: return $this;
134: }
135:
136: 137: 138: 139: 140:
141: public function getGridUrl()
142: {
143: return $this->getUrl('*/*/couponsGrid', array('_current'=> true));
144: }
145: }
146: