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_System_Store_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
35: {
36:
37: 38: 39: 40:
41: public function __construct()
42: {
43: parent::__construct();
44: $this->setId('coreStoreForm');
45: }
46:
47: 48: 49: 50: 51:
52: protected function _prepareForm()
53: {
54: if (Mage::registry('store_type') == 'website') {
55: $websiteModel = Mage::registry('store_data');
56: $showWebsiteFieldset = true;
57: $showGroupFieldset = $showStoreFieldset = false;
58: } elseif (Mage::registry('store_type') == 'group') {
59: $groupModel = Mage::registry('store_data');
60: $showGroupFieldset = true;
61: $showWebsiteFieldset = $showStoreFieldset = false;
62: } elseif (Mage::registry('store_type') == 'store') {
63: $storeModel = Mage::registry('store_data');
64: $showWebsiteFieldset = $showGroupFieldset = false;
65: $showStoreFieldset = true;
66: }
67:
68:
69:
70:
71:
72: $form = new Varien_Data_Form(array(
73: 'id' => 'edit_form',
74: 'action' => $this->getData('action'),
75: 'method' => 'post'
76: ));
77:
78: if ($showWebsiteFieldset) {
79: if ($postData = Mage::registry('store_post_data')) {
80: $websiteModel->setData($postData['website']);
81: }
82: $fieldset = $form->addFieldset('website_fieldset', array(
83: 'legend' => Mage::helper('core')->__('Website Information')
84: ));
85:
86:
87: $fieldset->addField('website_name', 'text', array(
88: 'name' => 'website[name]',
89: 'label' => Mage::helper('core')->__('Name'),
90: 'value' => $websiteModel->getName(),
91: 'required' => true,
92: 'disabled' => $websiteModel->isReadOnly(),
93: ));
94:
95: $fieldset->addField('website_code', 'text', array(
96: 'name' => 'website[code]',
97: 'label' => Mage::helper('core')->__('Code'),
98: 'value' => $websiteModel->getCode(),
99: 'required' => true,
100: 'disabled' => $websiteModel->isReadOnly(),
101: ));
102:
103: $fieldset->addField('website_sort_order', 'text', array(
104: 'name' => 'website[sort_order]',
105: 'label' => Mage::helper('core')->__('Sort Order'),
106: 'value' => $websiteModel->getSortOrder(),
107: 'required' => false,
108: 'disabled' => $websiteModel->isReadOnly(),
109: ));
110:
111: if (Mage::registry('store_action') == 'edit') {
112: $groups = Mage::getModel('core/store_group')->getCollection()
113: ->addWebsiteFilter($websiteModel->getId())
114: ->setWithoutStoreViewFilter()
115: ->toOptionArray();
116:
117: $fieldset->addField('website_default_group_id', 'select', array(
118: 'name' => 'website[default_group_id]',
119: 'label' => Mage::helper('core')->__('Default Store'),
120: 'value' => $websiteModel->getDefaultGroupId(),
121: 'values' => $groups,
122: 'required' => false,
123: 'disabled' => $websiteModel->isReadOnly(),
124: ));
125: }
126:
127: if (!$websiteModel->getIsDefault() && $websiteModel->getStoresCount()) {
128: $fieldset->addField('is_default', 'checkbox', array(
129: 'name' => 'website[is_default]',
130: 'label' => Mage::helper('core')->__('Set as Default'),
131: 'value' => 1,
132: 'disabled' => $websiteModel->isReadOnly(),
133: ));
134: }
135: else {
136: $fieldset->addField('is_default', 'hidden', array(
137: 'name' => 'website[is_default]',
138: 'value' => $websiteModel->getIsDefault()
139: ));
140: }
141:
142: $fieldset->addField('website_website_id', 'hidden', array(
143: 'name' => 'website[website_id]',
144: 'value' => $websiteModel->getId()
145: ));
146: }
147:
148: if ($showGroupFieldset) {
149: if ($postData = Mage::registry('store_post_data')) {
150: $groupModel->setData($postData['group']);
151: }
152: $fieldset = $form->addFieldset('group_fieldset', array(
153: 'legend' => Mage::helper('core')->__('Store Information')
154: ));
155:
156: if (Mage::registry('store_action') == 'edit'
157: || (Mage::registry('store_action') == 'add' && Mage::registry('store_type') == 'group')) {
158: $websites = Mage::getModel('core/website')->getCollection()->toOptionArray();
159: $fieldset->addField('group_website_id', 'select', array(
160: 'name' => 'group[website_id]',
161: 'label' => Mage::helper('core')->__('Website'),
162: 'value' => $groupModel->getWebsiteId(),
163: 'values' => $websites,
164: 'required' => true,
165: 'disabled' => $groupModel->isReadOnly(),
166: ));
167:
168: if ($groupModel->getId() && $groupModel->getWebsite()->getDefaultGroupId() == $groupModel->getId()) {
169: if ($groupModel->getWebsite()->getIsDefault() || $groupModel->getWebsite()->getGroupsCount() == 1) {
170: $form->getElement('group_website_id')->setDisabled(true);
171:
172: $fieldset->addField('group_hidden_website_id', 'hidden', array(
173: 'name' => 'group[website_id]',
174: 'no_span' => true,
175: 'value' => $groupModel->getWebsiteId()
176: ));
177: }
178: else {
179: $fieldset->addField('group_original_website_id', 'hidden', array(
180: 'name' => 'group[original_website_id]',
181: 'no_span' => true,
182: 'value' => $groupModel->getWebsiteId()
183: ));
184: }
185: }
186: }
187:
188: $fieldset->addField('group_name', 'text', array(
189: 'name' => 'group[name]',
190: 'label' => Mage::helper('core')->__('Name'),
191: 'value' => $groupModel->getName(),
192: 'required' => true,
193: 'disabled' => $groupModel->isReadOnly(),
194: ));
195:
196: $categories = Mage::getModel('adminhtml/system_config_source_category')->toOptionArray();
197:
198: $fieldset->addField('group_root_category_id', 'select', array(
199: 'name' => 'group[root_category_id]',
200: 'label' => Mage::helper('core')->__('Root Category'),
201: 'value' => $groupModel->getRootCategoryId(),
202: 'values' => $categories,
203: 'required' => true,
204: 'disabled' => $groupModel->isReadOnly(),
205: ));
206:
207: if (Mage::registry('store_action') == 'edit') {
208: $stores = Mage::getModel('core/store')->getCollection()
209: ->addGroupFilter($groupModel->getId())->toOptionArray();
210:
211: $fieldset->addField('group_default_store_id', 'select', array(
212: 'name' => 'group[default_store_id]',
213: 'label' => Mage::helper('core')->__('Default Store View'),
214: 'value' => $groupModel->getDefaultStoreId(),
215: 'values' => $stores,
216: 'required' => false,
217: 'disabled' => $groupModel->isReadOnly(),
218: ));
219: }
220:
221: $fieldset->addField('group_group_id', 'hidden', array(
222: 'name' => 'group[group_id]',
223: 'no_span' => true,
224: 'value' => $groupModel->getId()
225: ));
226: }
227:
228: if ($showStoreFieldset) {
229: if ($postData = Mage::registry('store_post_data')) {
230: $storeModel->setData($postData['store']);
231: }
232: $fieldset = $form->addFieldset('store_fieldset', array(
233: 'legend' => Mage::helper('core')->__('Store View Information')
234: ));
235:
236: if (Mage::registry('store_action') == 'edit'
237: || Mage::registry('store_action') == 'add' && Mage::registry('store_type') == 'store') {
238: $websites = Mage::getModel('core/website')->getCollection();
239: $allgroups = Mage::getModel('core/store_group')->getCollection();
240: $groups = array();
241: foreach ($websites as $website) {
242: $values = array();
243: foreach ($allgroups as $group) {
244: if ($group->getWebsiteId() == $website->getId()) {
245: $values[] = array('label'=>$group->getName(),'value'=>$group->getId());
246: }
247: }
248: $groups[] = array('label'=>$website->getName(),'value'=>$values);
249: }
250: $fieldset->addField('store_group_id', 'select', array(
251: 'name' => 'store[group_id]',
252: 'label' => Mage::helper('core')->__('Store'),
253: 'value' => $storeModel->getGroupId(),
254: 'values' => $groups,
255: 'required' => true,
256: 'disabled' => $storeModel->isReadOnly(),
257: ));
258: if ($storeModel->getId() && $storeModel->getGroup()->getDefaultStoreId() == $storeModel->getId()) {
259: if ($storeModel->getGroup() && $storeModel->getGroup()->getStoresCount() > 1) {
260: $form->getElement('store_group_id')->setDisabled(true);
261:
262: $fieldset->addField('store_hidden_group_id', 'hidden', array(
263: 'name' => 'store[group_id]',
264: 'no_span' => true,
265: 'value' => $storeModel->getGroupId()
266: ));
267: }
268: else {
269: $fieldset->addField('store_original_group_id', 'hidden', array(
270: 'name' => 'store[original_group_id]',
271: 'no_span' => true,
272: 'value' => $storeModel->getGroupId()
273: ));
274: }
275: }
276: }
277:
278: $fieldset->addField('store_name', 'text', array(
279: 'name' => 'store[name]',
280: 'label' => Mage::helper('core')->__('Name'),
281: 'value' => $storeModel->getName(),
282: 'required' => true,
283: 'disabled' => $storeModel->isReadOnly(),
284: ));
285: $fieldset->addField('store_code', 'text', array(
286: 'name' => 'store[code]',
287: 'label' => Mage::helper('core')->__('Code'),
288: 'value' => $storeModel->getCode(),
289: 'required' => true,
290: 'disabled' => $storeModel->isReadOnly(),
291: ));
292:
293: $fieldset->addField('store_is_active', 'select', array(
294: 'name' => 'store[is_active]',
295: 'label' => Mage::helper('core')->__('Status'),
296: 'value' => $storeModel->getIsActive(),
297: 'options' => array(
298: 0 => Mage::helper('adminhtml')->__('Disabled'),
299: 1 => Mage::helper('adminhtml')->__('Enabled')),
300: 'required' => true,
301: 'disabled' => $storeModel->isReadOnly(),
302: ));
303:
304: $fieldset->addField('store_sort_order', 'text', array(
305: 'name' => 'store[sort_order]',
306: 'label' => Mage::helper('core')->__('Sort Order'),
307: 'value' => $storeModel->getSortOrder(),
308: 'required' => false,
309: 'disabled' => $storeModel->isReadOnly(),
310: ));
311:
312: $fieldset->addField('store_is_default', 'hidden', array(
313: 'name' => 'store[is_default]',
314: 'no_span' => true,
315: 'value' => $storeModel->getIsDefault(),
316: ));
317:
318: $fieldset->addField('store_store_id', 'hidden', array(
319: 'name' => 'store[store_id]',
320: 'no_span' => true,
321: 'value' => $storeModel->getId(),
322: 'disabled' => $storeModel->isReadOnly(),
323: ));
324: }
325:
326: $form->addField('store_type', 'hidden', array(
327: 'name' => 'store_type',
328: 'no_span' => true,
329: 'value' => Mage::registry('store_type')
330: ));
331:
332: $form->addField('store_action', 'hidden', array(
333: 'name' => 'store_action',
334: 'no_span' => true,
335: 'value' => Mage::registry('store_action')
336: ));
337:
338: $form->setAction($this->getUrl('*/*/save'));
339: $form->setUseContainer(true);
340: $this->setForm($form);
341:
342: Mage::dispatchEvent('adminhtml_store_edit_form_prepare_form', array('block' => $this));
343:
344: return parent::_prepareForm();
345: }
346: }
347: