PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/dnejedly/eaparts
PHP | 281 lines | 192 code | 35 blank | 54 comment | 8 complexity | d6d1a514ca878a91bb0f8fdfee56b858 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@magentocommerce.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.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Adminhtml
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.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. ));
  181. $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
  182. $fieldset->addField('from_date', 'date', array(
  183. 'name' => 'from_date',
  184. 'label' => Mage::helper('salesrule')->__('From Date'),
  185. 'title' => Mage::helper('salesrule')->__('From Date'),
  186. 'image' => $this->getSkinUrl('images/grid-cal.gif'),
  187. 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
  188. 'format' => $dateFormatIso
  189. ));
  190. $fieldset->addField('to_date', 'date', array(
  191. 'name' => 'to_date',
  192. 'label' => Mage::helper('salesrule')->__('To Date'),
  193. 'title' => Mage::helper('salesrule')->__('To Date'),
  194. 'image' => $this->getSkinUrl('images/grid-cal.gif'),
  195. 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
  196. 'format' => $dateFormatIso
  197. ));
  198. $fieldset->addField('sort_order', 'text', array(
  199. 'name' => 'sort_order',
  200. 'label' => Mage::helper('salesrule')->__('Priority'),
  201. ));
  202. $fieldset->addField('is_rss', 'select', array(
  203. 'label' => Mage::helper('salesrule')->__('Public In RSS Feed'),
  204. 'title' => Mage::helper('salesrule')->__('Public In RSS Feed'),
  205. 'name' => 'is_rss',
  206. 'options' => array(
  207. '1' => Mage::helper('salesrule')->__('Yes'),
  208. '0' => Mage::helper('salesrule')->__('No'),
  209. ),
  210. ));
  211. if(!$model->getId()){
  212. //set the default value for is_rss feed to yes for new promotion
  213. $model->setIsRss(1);
  214. }
  215. $form->setValues($model->getData());
  216. $autoGenerationCheckbox->setValue(1);
  217. if ($model->isReadonly()) {
  218. foreach ($fieldset->getElements() as $element) {
  219. $element->setReadonly(true, true);
  220. }
  221. }
  222. //$form->setUseContainer(true);
  223. $this->setForm($form);
  224. // field dependencies
  225. $this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
  226. ->addFieldMap($couponTypeFiled->getHtmlId(), $couponTypeFiled->getName())
  227. ->addFieldMap($couponCodeFiled->getHtmlId(), $couponCodeFiled->getName())
  228. ->addFieldMap($autoGenerationCheckbox->getHtmlId(), $autoGenerationCheckbox->getName())
  229. ->addFieldMap($usesPerCouponFiled->getHtmlId(), $usesPerCouponFiled->getName())
  230. ->addFieldDependence(
  231. $couponCodeFiled->getName(),
  232. $couponTypeFiled->getName(),
  233. Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
  234. ->addFieldDependence(
  235. $autoGenerationCheckbox->getName(),
  236. $couponTypeFiled->getName(),
  237. Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
  238. ->addFieldDependence(
  239. $usesPerCouponFiled->getName(),
  240. $couponTypeFiled->getName(),
  241. Mage_SalesRule_Model_Rule::COUPON_TYPE_SPECIFIC)
  242. );
  243. Mage::dispatchEvent('adminhtml_promo_quote_edit_tab_main_prepare_form', array('form' => $form));
  244. return parent::_prepareForm();
  245. }
  246. }