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_Main
35: extends Mage_Adminhtml_Block_Widget_Form
36: implements Mage_Adminhtml_Block_Widget_Tab_Interface
37: {
38: 39: 40: 41: 42:
43: public function getTabLabel()
44: {
45: return Mage::helper('salesrule')->__('Rule Information');
46: }
47:
48: 49: 50: 51: 52:
53: public function getTabTitle()
54: {
55: return Mage::helper('salesrule')->__('Rule Information');
56: }
57:
58: 59: 60: 61: 62:
63: public function canShowTab()
64: {
65: return true;
66: }
67:
68: 69: 70: 71: 72:
73: public function isHidden()
74: {
75: return false;
76: }
77:
78: protected function _prepareForm()
79: {
80: $model = Mage::registry('current_promo_quote_rule');
81:
82: $form = new Varien_Data_Form();
83: $form->setHtmlIdPrefix('rule_');
84:
85: $fieldset = $form->addFieldset('base_fieldset',
86: array('legend' => Mage::helper('salesrule')->__('General Information'))
87: );
88:
89: if ($model->getId()) {
90: $fieldset->addField('rule_id', 'hidden', array(
91: 'name' => 'rule_id',
92: ));
93: }
94:
95: $fieldset->addField('product_ids', 'hidden', array(
96: 'name' => 'product_ids',
97: ));
98:
99: $fieldset->addField('name', 'text', array(
100: 'name' => 'name',
101: 'label' => Mage::helper('salesrule')->__('Rule Name'),
102: 'title' => Mage::helper('salesrule')->__('Rule Name'),
103: 'required' => true,
104: ));
105:
106: $fieldset->addField('description', 'textarea', array(
107: 'name' => 'description',
108: 'label' => Mage::helper('salesrule')->__('Description'),
109: 'title' => Mage::helper('salesrule')->__('Description'),
110: 'style' => 'height: 100px;',
111: ));
112:
113: $fieldset->addField('is_active', 'select', array(
114: 'label' => Mage::helper('salesrule')->__('Status'),
115: 'title' => Mage::helper('salesrule')->__('Status'),
116: 'name' => 'is_active',
117: 'required' => true,
118: 'options' => array(
119: '1' => Mage::helper('salesrule')->__('Active'),
120: '0' => Mage::helper('salesrule')->__('Inactive'),
121: ),
122: ));
123:
124: if (!$model->getId()) {
125: $model->setData('is_active', '1');
126: }
127:
128: if (Mage::app()->isSingleStoreMode()) {
129: $websiteId = Mage::app()->getStore(true)->getWebsiteId();
130: $fieldset->addField('website_ids', 'hidden', array(
131: 'name' => 'website_ids[]',
132: 'value' => $websiteId
133: ));
134: $model->setWebsiteIds($websiteId);
135: } else {
136: $field = $fieldset->addField('website_ids', 'multiselect', array(
137: 'name' => 'website_ids[]',
138: 'label' => Mage::helper('salesrule')->__('Websites'),
139: 'title' => Mage::helper('salesrule')->__('Websites'),
140: 'required' => true,
141: 'values' => Mage::getSingleton('adminhtml/system_store')->getWebsiteValuesForForm()
142: ));
143: $renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
144: $field->setRenderer($renderer);
145: }
146:
147: $customerGroups = Mage::getResourceModel('customer/group_collection')->load()->toOptionArray();
148: $found = false;
149:
150: foreach ($customerGroups as $group) {
151: if ($group['value']==0) {
152: $found = true;
153: }
154: }
155: if (!$found) {
156: array_unshift($customerGroups, array(
157: 'value' => 0,
158: 'label' => Mage::helper('salesrule')->__('NOT LOGGED IN'))
159: );
160: }
161:
162: $fieldset->addField('customer_group_ids', 'multiselect', array(
163: 'name' => 'customer_group_ids[]',
164: 'label' => Mage::helper('salesrule')->__('Customer Groups'),
165: 'title' => Mage::helper('salesrule')->__('Customer Groups'),
166: 'required' => true,
167: 'values' => Mage::getResourceModel('customer/group_collection')->toOptionArray(),
168: ));
169:
170: $couponTypeFiled = $fieldset->addField('coupon_type', 'select', array(
171: 'name' => 'coupon_type',
172: 'label' => Mage::helper('salesrule')->__('Coupon'),
173: 'required' => true,
174: 'options' => Mage::getModel('salesrule/rule')->getCouponTypes(),
175: ));
176:
177: $couponCodeFiled = $fieldset->addField('coupon_code', 'text', array(
178: 'name' => 'coupon_code',
179: 'label' => Mage::helper('salesrule')->__('Coupon Code'),
180: 'required' => true,
181: ));
182:
183: $autoGenerationCheckbox = $fieldset->addField('use_auto_generation', 'checkbox', array(
184: 'name' => 'use_auto_generation',
185: 'label' => Mage::helper('salesrule')->__('Use Auto Generation'),
186: 'note' => Mage::helper('salesrule')->__('If you select and save the rule you will be able to generate multiple coupon codes.'),
187: 'onclick' => 'handleCouponsTabContentActivity()',
188: 'checked' => (int)$model->getUseAutoGeneration() > 0 ? 'checked' : ''
189: ));
190:
191: $autoGenerationCheckbox->setRenderer(
192: $this->getLayout()->createBlock('adminhtml/promo_quote_edit_tab_main_renderer_checkbox')
193: );
194:
195: $usesPerCouponFiled = $fieldset->addField('uses_per_coupon', 'text', array(
196: 'name' => 'uses_per_coupon',
197: 'label' => Mage::helper('salesrule')->__('Uses per Coupon'),
198: ));
199:
200: $fieldset->addField('uses_per_customer', 'text', array(
201: 'name' => 'uses_per_customer',
202: 'label' => Mage::helper('salesrule')->__('Uses per Customer'),
203: ));
204:
205: $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
206: $fieldset->addField('from_date', 'date', array(
207: 'name' => 'from_date',
208: 'label' => Mage::helper('salesrule')->__('From Date'),
209: 'title' => Mage::helper('salesrule')->__('From Date'),
210: 'image' => $this->getSkinUrl('images/grid-cal.gif'),
211: 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
212: 'format' => $dateFormatIso
213: ));
214: $fieldset->addField('to_date', 'date', array(
215: 'name' => 'to_date',
216: 'label' => Mage::helper('salesrule')->__('To Date'),
217: 'title' => Mage::helper('salesrule')->__('To Date'),
218: 'image' => $this->getSkinUrl('images/grid-cal.gif'),
219: 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
220: 'format' => $dateFormatIso
221: ));
222:
223: $fieldset->addField('sort_order', 'text', array(
224: 'name' => 'sort_order',
225: 'label' => Mage::helper('salesrule')->__('Priority'),
226: ));
227:
228: $fieldset->addField('is_rss', 'select', array(
229: 'label' => Mage::helper('salesrule')->__('Public In RSS Feed'),
230: 'title' => Mage::helper('salesrule')->__('Public In RSS Feed'),
231: 'name' => 'is_rss',
232: 'options' => array(
233: '1' => Mage::helper('salesrule')->__('Yes'),
234: '0' => Mage::helper('salesrule')->__('No'),
235: ),
236: ));
237:
238: if(!$model->getId()){
239:
240: $model->setIsRss(1);
241: }
242:
243: $form->setValues($model->getData());
244:
245: $autoGenerationCheckbox->setValue(1);
246:
247: if ($model->isReadonly()) {
248: foreach ($fieldset->getElements() as $element) {
249: $element->setReadonly(true, true);
250: }
251: }
252:
253:
254:
255: $this->setForm($form);
256:
257:
258: $this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
259: ->addFieldMap($couponTypeFiled->getHtmlId(), $couponTypeFiled->getName())
260: ->addFieldMap($couponCodeFiled->getHtmlId(), $couponCodeFiled->getName())
261: ->addFieldMap($autoGenerationCheckbox->getHtmlId(), $autoGenerationCheckbox->getName())
262: ->addFieldMap($usesPerCouponFiled->getHtmlId(), $usesPerCouponFiled->getName())
263: ->addFieldDependence(
264: $couponCodeFiled->getName(),
265: $couponTypeFiled->getName(),
266: Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
267: ->addFieldDependence(
268: $autoGenerationCheckbox->getName(),
269: $couponTypeFiled->getName(),
270: Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
271: ->addFieldDependence(
272: $usesPerCouponFiled->getName(),
273: $couponTypeFiled->getName(),
274: Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
275: );
276:
277: Mage::dispatchEvent('adminhtml_promo_quote_edit_tab_main_prepare_form', array('form' => $form));
278:
279: return parent::_prepareForm();
280: }
281: }
282: