PageRenderTime 84ms CodeModel.GetById 19ms RepoModel.GetById 2ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Main.php

https://github.com/speedupmate/Magento-CE-Mirror
PHP | 282 lines | 193 code | 35 blank | 54 comment | 8 complexity | 862e61c3e2bd7f27c249ab86f5bd9273 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Adminhtml
  23. * @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Shopping Cart Price Rule General Information Tab
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Main
  34. extends Mage_Adminhtml_Block_Widget_Form
  35. implements Mage_Adminhtml_Block_Widget_Tab_Interface
  36. {
  37. /**
  38. * Prepare content for tab
  39. *
  40. * @return string
  41. */
  42. public function getTabLabel()
  43. {
  44. return Mage::helper('salesrule')->__('Rule Information');
  45. }
  46. /**
  47. * Prepare title for tab
  48. *
  49. * @return string
  50. */
  51. public function getTabTitle()
  52. {
  53. return Mage::helper('salesrule')->__('Rule Information');
  54. }
  55. /**
  56. * Returns status flag about this tab can be showed or not
  57. *
  58. * @return true
  59. */
  60. public function canShowTab()
  61. {
  62. return true;
  63. }
  64. /**
  65. * Returns status flag about this tab hidden or not
  66. *
  67. * @return true
  68. */
  69. public function isHidden()
  70. {
  71. return false;
  72. }
  73. protected function _prepareForm()
  74. {
  75. $model = Mage::registry('current_promo_quote_rule');
  76. $form = new Varien_Data_Form();
  77. $form->setHtmlIdPrefix('rule_');
  78. $fieldset = $form->addFieldset('base_fieldset',
  79. array('legend' => Mage::helper('salesrule')->__('General Information'))
  80. );
  81. if ($model->getId()) {
  82. $fieldset->addField('rule_id', 'hidden', array(
  83. 'name' => 'rule_id',
  84. ));
  85. }
  86. $fieldset->addField('product_ids', 'hidden', array(
  87. 'name' => 'product_ids',
  88. ));
  89. $fieldset->addField('name', 'text', array(
  90. 'name' => 'name',
  91. 'label' => Mage::helper('salesrule')->__('Rule Name'),
  92. 'title' => Mage::helper('salesrule')->__('Rule Name'),
  93. 'required' => true,
  94. ));
  95. $fieldset->addField('description', 'textarea', array(
  96. 'name' => 'description',
  97. 'label' => Mage::helper('salesrule')->__('Description'),
  98. 'title' => Mage::helper('salesrule')->__('Description'),
  99. 'style' => 'height: 100px;',
  100. ));
  101. $fieldset->addField('is_active', 'select', array(
  102. 'label' => Mage::helper('salesrule')->__('Status'),
  103. 'title' => Mage::helper('salesrule')->__('Status'),
  104. 'name' => 'is_active',
  105. 'required' => true,
  106. 'options' => array(
  107. '1' => Mage::helper('salesrule')->__('Active'),
  108. '0' => Mage::helper('salesrule')->__('Inactive'),
  109. ),
  110. ));
  111. if (!$model->getId()) {
  112. $model->setData('is_active', '1');
  113. }
  114. if (Mage::app()->isSingleStoreMode()) {
  115. $websiteId = Mage::app()->getStore(true)->getWebsiteId();
  116. $fieldset->addField('website_ids', 'hidden', array(
  117. 'name' => 'website_ids[]',
  118. 'value' => $websiteId
  119. ));
  120. $model->setWebsiteIds($websiteId);
  121. } else {
  122. $field = $fieldset->addField('website_ids', 'multiselect', array(
  123. 'name' => 'website_ids[]',
  124. 'label' => Mage::helper('salesrule')->__('Websites'),
  125. 'title' => Mage::helper('salesrule')->__('Websites'),
  126. 'required' => true,
  127. 'values' => Mage::getSingleton('adminhtml/system_store')->getWebsiteValuesForForm()
  128. ));
  129. $renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
  130. $field->setRenderer($renderer);
  131. }
  132. $customerGroups = Mage::getResourceModel('customer/group_collection')->load()->toOptionArray();
  133. $found = false;
  134. foreach ($customerGroups as $group) {
  135. if ($group['value']==0) {
  136. $found = true;
  137. }
  138. }
  139. if (!$found) {
  140. array_unshift($customerGroups, array(
  141. 'value' => 0,
  142. 'label' => Mage::helper('salesrule')->__('NOT LOGGED IN'))
  143. );
  144. }
  145. $fieldset->addField('customer_group_ids', 'multiselect', array(
  146. 'name' => 'customer_group_ids[]',
  147. 'label' => Mage::helper('salesrule')->__('Customer Groups'),
  148. 'title' => Mage::helper('salesrule')->__('Customer Groups'),
  149. 'required' => true,
  150. 'values' => Mage::getResourceModel('customer/group_collection')->toOptionArray(),
  151. ));
  152. $couponTypeFiled = $fieldset->addField('coupon_type', 'select', array(
  153. 'name' => 'coupon_type',
  154. 'label' => Mage::helper('salesrule')->__('Coupon'),
  155. 'required' => true,
  156. 'options' => Mage::getModel('salesrule/rule')->getCouponTypes(),
  157. ));
  158. $couponCodeFiled = $fieldset->addField('coupon_code', 'text', array(
  159. 'name' => 'coupon_code',
  160. 'label' => Mage::helper('salesrule')->__('Coupon Code'),
  161. 'required' => true,
  162. ));
  163. $autoGenerationCheckbox = $fieldset->addField('use_auto_generation', 'checkbox', array(
  164. 'name' => 'use_auto_generation',
  165. 'label' => Mage::helper('salesrule')->__('Use Auto Generation'),
  166. 'note' => Mage::helper('salesrule')->__('If you select and save the rule you will be able to generate multiple coupon codes.'),
  167. 'onclick' => 'handleCouponsTabContentActivity()',
  168. 'checked' => (int)$model->getUseAutoGeneration() > 0 ? 'checked' : ''
  169. ));
  170. $autoGenerationCheckbox->setRenderer(
  171. $this->getLayout()->createBlock('adminhtml/promo_quote_edit_tab_main_renderer_checkbox')
  172. );
  173. $usesPerCouponFiled = $fieldset->addField('uses_per_coupon', 'text', array(
  174. 'name' => 'uses_per_coupon',
  175. 'label' => Mage::helper('salesrule')->__('Uses per Coupon'),
  176. ));
  177. $fieldset->addField('uses_per_customer', 'text', array(
  178. 'name' => 'uses_per_customer',
  179. 'label' => Mage::helper('salesrule')->__('Uses per Customer'),
  180. 'note' => Mage::helper('salesrule')->__('Usage limit enforced for logged in customers only'),
  181. ));
  182. $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
  183. $fieldset->addField('from_date', 'date', array(
  184. 'name' => 'from_date',
  185. 'label' => Mage::helper('salesrule')->__('From Date'),
  186. 'title' => Mage::helper('salesrule')->__('From Date'),
  187. 'image' => $this->getSkinUrl('images/grid-cal.gif'),
  188. 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
  189. 'format' => $dateFormatIso
  190. ));
  191. $fieldset->addField('to_date', 'date', array(
  192. 'name' => 'to_date',
  193. 'label' => Mage::helper('salesrule')->__('To Date'),
  194. 'title' => Mage::helper('salesrule')->__('To Date'),
  195. 'image' => $this->getSkinUrl('images/grid-cal.gif'),
  196. 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
  197. 'format' => $dateFormatIso
  198. ));
  199. $fieldset->addField('sort_order', 'text', array(
  200. 'name' => 'sort_order',
  201. 'label' => Mage::helper('salesrule')->__('Priority'),
  202. ));
  203. $fieldset->addField('is_rss', 'select', array(
  204. 'label' => Mage::helper('salesrule')->__('Public In RSS Feed'),
  205. 'title' => Mage::helper('salesrule')->__('Public In RSS Feed'),
  206. 'name' => 'is_rss',
  207. 'options' => array(
  208. '1' => Mage::helper('salesrule')->__('Yes'),
  209. '0' => Mage::helper('salesrule')->__('No'),
  210. ),
  211. ));
  212. if(!$model->getId()){
  213. //set the default value for is_rss feed to yes for new promotion
  214. $model->setIsRss(1);
  215. }
  216. $form->setValues($model->getData());
  217. $autoGenerationCheckbox->setValue(1);
  218. if ($model->isReadonly()) {
  219. foreach ($fieldset->getElements() as $element) {
  220. $element->setReadonly(true, true);
  221. }
  222. }
  223. //$form->setUseContainer(true);
  224. $this->setForm($form);
  225. // field dependencies
  226. $this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
  227. ->addFieldMap($couponTypeFiled->getHtmlId(), $couponTypeFiled->getName())
  228. ->addFieldMap($couponCodeFiled->getHtmlId(), $couponCodeFiled->getName())
  229. ->addFieldMap($autoGenerationCheckbox->getHtmlId(), $autoGenerationCheckbox->getName())
  230. ->addFieldMap($usesPerCouponFiled->getHtmlId(), $usesPerCouponFiled->getName())
  231. ->addFieldDependence(
  232. $couponCodeFiled->getName(),
  233. $couponTypeFiled->getName(),
  234. Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
  235. ->addFieldDependence(
  236. $autoGenerationCheckbox->getName(),
  237. $couponTypeFiled->getName(),
  238. Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
  239. ->addFieldDependence(
  240. $usesPerCouponFiled->getName(),
  241. $couponTypeFiled->getName(),
  242. Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
  243. );
  244. Mage::dispatchEvent('adminhtml_promo_quote_edit_tab_main_prepare_form', array('form' => $form));
  245. return parent::_prepareForm();
  246. }
  247. }