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: class Mage_Sales_Block_Adminhtml_Recurring_Profile_Edit_Form extends Mage_Adminhtml_Block_Abstract
32: {
33: 34: 35: 36: 37:
38: protected $_parentElement = null;
39:
40: 41: 42: 43: 44:
45: protected $_isReadOnly = false;
46:
47: 48: 49: 50: 51:
52: protected $_profile = null;
53:
54: 55: 56: 57:
58: protected $_product = null;
59:
60: 61: 62: 63: 64:
65: public function setParentElement(Varien_Data_Form_Element_Abstract $element)
66: {
67: $this->_parentElement = $element;
68: return $this;
69: }
70:
71: 72: 73: 74: 75:
76: public function setProductEntity(Mage_Catalog_Model_Product $product)
77: {
78: $this->_product = $product;
79: return $this;
80: }
81:
82: 83: 84:
85: protected function _construct()
86: {
87: $this->_profile = Mage::getSingleton('sales/recurring_profile');
88: return parent::_construct();
89: }
90:
91: 92: 93: 94: 95:
96: protected function _toHtml()
97: {
98:
99: $form = $this->_prepareForm();
100: if ($this->_product && $this->_product->getRecurringProfile()) {
101: $form->setValues($this->_product->getRecurringProfile());
102: }
103: return $form->toHtml();
104: }
105:
106: 107: 108: 109: 110:
111: protected function _prepareForm()
112: {
113: $form = new Varien_Data_Form();
114: $form->setFieldsetRenderer($this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset'));
115: $form->setFieldsetElementRenderer($this->getLayout()
116: ->createBlock('adminhtml/widget_form_renderer_fieldset_element'));
117:
118: 119: 120: 121: 122:
123: if ($this->_parentElement) {
124: $form->setHtmlIdPrefix($this->_parentElement->getHtmlId())
125: ->setFieldNameSuffix($this->_parentElement->getName());
126: $form->addField('', 'hidden', array('name' => ''));
127: }
128:
129: $noYes = array(Mage::helper('adminhtml')->__('No'), Mage::helper('adminhtml')->__('Yes'));
130:
131:
132: $schedule = $form->addFieldset('schedule_fieldset', array(
133: 'legend' => Mage::helper('sales')->__('Schedule'),
134: 'disabled' => $this->_isReadOnly
135: ));
136: $schedule->addField('start_date_is_editable', 'select', array(
137: 'name' => 'start_date_is_editable',
138: 'label' => Mage::helper('sales')->__('Customer Can Define Start Date'),
139: 'comment' => Mage::helper('sales')->__('Whether buyer can define the date when billing for the profile begins.'),
140: 'options' => $noYes,
141: 'disabled' => $this->_isReadOnly
142: ));
143: $this->_addField($schedule, 'schedule_description');
144: $this->_addField($schedule, 'suspension_threshold');
145: $this->_addField($schedule, 'bill_failed_later', array('options' => $noYes), 'select');
146:
147:
148: $billing = $form->addFieldset('billing_fieldset', array(
149: 'legend' => Mage::helper('sales')->__('Billing'),
150: 'disabled' => $this->_isReadOnly
151: ));
152: $this->_addField($billing, 'period_unit', array(
153: 'options' => $this->_getPeriodUnitOptions(Mage::helper('adminhtml')->__('-- Please Select --')),
154: ), 'select');
155: $this->_addField($billing, 'period_frequency');
156: $this->_addField($billing, 'period_max_cycles');
157:
158:
159: $trial = $form->addFieldset('trial_fieldset', array(
160: 'legend' => Mage::helper('sales')->__('Trial Period'),
161: 'disabled' => $this->_isReadOnly
162: ));
163: $this->_addField($trial, 'trial_period_unit', array(
164: 'options' => $this->_getPeriodUnitOptions(Mage::helper('adminhtml')->__('-- Not Selected --')),
165: ), 'select');
166: $this->_addField($trial, 'trial_period_frequency');
167: $this->_addField($trial, 'trial_period_max_cycles');
168: $this->_addField($trial, 'trial_billing_amount');
169:
170:
171: $initial = $form->addFieldset('initial_fieldset', array(
172: 'legend' => Mage::helper('sales')->__('Initial Fees'),
173: 'disabled' => $this->_isReadOnly
174: ));
175: $this->_addField($initial, 'init_amount');
176: $this->_addField($initial, 'init_may_fail', array('options' => $noYes), 'select');
177:
178: return $form;
179: }
180:
181: 182: 183: 184: 185: 186: 187: 188: 189: 190:
191: protected function _addField($formOrFieldset, $elementName, $options = array(), $type = 'text')
192: {
193: $options = array_merge($options, array(
194: 'name' => $elementName,
195: 'label' => $this->_profile->getFieldLabel($elementName),
196: 'note' => $this->_profile->getFieldComment($elementName),
197: 'disabled' => $this->_isReadOnly,
198: ));
199: if (in_array($elementName, array('period_unit', 'period_frequency'))) {
200: $options['required'] = true;
201: }
202: return $formOrFieldset->addField($elementName, $type, $options);
203: }
204:
205: 206: 207: 208: 209:
210: protected function _getPeriodUnitOptions($emptyLabel)
211: {
212: return array_merge(array('' => $emptyLabel),
213: $this->_profile->getAllPeriodUnits()
214: );
215: }
216:
217: 218: 219: 220: 221: 222:
223: public function setIsReadonly($isReadonly)
224: {
225: $this->_isReadOnly = $isReadonly;
226: return $this;
227: }
228:
229: 230: 231: 232: 233:
234: public function getIsReadonly()
235: {
236: return $this->_isReadOnly;
237: }
238: }
239: