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_Catalog_Product_Attribute_Set_Main extends Mage_Adminhtml_Block_Template
35: {
36: 37: 38: 39:
40: protected function _construct()
41: {
42: $this->setTemplate('catalog/product/attribute/set/main.phtml');
43: }
44:
45: 46: 47: 48: 49:
50: protected function _prepareLayout()
51: {
52: $setId = $this->_getSetId();
53:
54: $this->setChild('group_tree',
55: $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main_tree_group')
56: );
57:
58: $this->setChild('edit_set_form',
59: $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main_formset')
60: );
61:
62: $this->setChild('delete_group_button',
63: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
64: 'label' => Mage::helper('catalog')->__('Delete Selected Group'),
65: 'onclick' => 'editSet.submit();',
66: 'class' => 'delete'
67: )));
68:
69: $this->setChild('add_group_button',
70: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
71: 'label' => Mage::helper('catalog')->__('Add New'),
72: 'onclick' => 'editSet.addGroup();',
73: 'class' => 'add'
74: )));
75:
76: $this->setChild('back_button',
77: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
78: 'label' => Mage::helper('catalog')->__('Back'),
79: 'onclick' => 'setLocation(\''.$this->getUrl('*/*/').'\')',
80: 'class' => 'back'
81: )));
82:
83: $this->setChild('reset_button',
84: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
85: 'label' => Mage::helper('catalog')->__('Reset'),
86: 'onclick' => 'window.location.reload()'
87: )));
88:
89: $this->setChild('save_button',
90: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
91: 'label' => Mage::helper('catalog')->__('Save Attribute Set'),
92: 'onclick' => 'editSet.save();',
93: 'class' => 'save'
94: )));
95:
96: $this->setChild('delete_button',
97: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
98: 'label' => Mage::helper('catalog')->__('Delete Attribute Set'),
99: 'onclick' => 'deleteConfirm(\''. $this->jsQuoteEscape(Mage::helper('catalog')->__('All products of this set will be deleted! Are you sure you want to delete this attribute set?')) . '\', \'' . $this->getUrl('*/*/delete', array('id' => $setId)) . '\')',
100: 'class' => 'delete'
101: )));
102:
103: $this->setChild('rename_button',
104: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
105: 'label' => Mage::helper('catalog')->__('New Set Name'),
106: 'onclick' => 'editSet.rename()'
107: )));
108:
109: return parent::_prepareLayout();
110: }
111:
112: 113: 114: 115: 116:
117: public function getGroupTreeHtml()
118: {
119: return $this->getChildHtml('group_tree');
120: }
121:
122: 123: 124: 125: 126:
127: public function getSetFormHtml()
128: {
129: return $this->getChildHtml('edit_set_form');
130: }
131:
132: 133: 134: 135: 136:
137: protected function ()
138: {
139: return Mage::helper('catalog')->__("Edit Attribute Set '%s'", $this->_getAttributeSet()->getAttributeSetName());
140: }
141:
142: 143: 144: 145: 146:
147: public function getMoveUrl()
148: {
149: return $this->getUrl('*/catalog_product_set/save', array('id' => $this->_getSetId()));
150: }
151:
152: 153: 154: 155: 156:
157: public function getGroupUrl()
158: {
159: return $this->getUrl('*/catalog_product_group/save', array('id' => $this->_getSetId()));
160: }
161:
162: 163: 164: 165: 166:
167: public function getGroupTreeJson()
168: {
169: $items = array();
170: $setId = $this->_getSetId();
171:
172:
173: $groups = Mage::getModel('eav/entity_attribute_group')
174: ->getResourceCollection()
175: ->setAttributeSetFilter($setId)
176: ->setSortOrder()
177: ->load();
178:
179: $configurable = Mage::getResourceModel('catalog/product_type_configurable_attribute')
180: ->getUsedAttributes($setId);
181:
182:
183: foreach ($groups as $node) {
184: $item = array();
185: $item['text'] = $node->getAttributeGroupName();
186: $item['id'] = $node->getAttributeGroupId();
187: $item['cls'] = 'folder';
188: $item['allowDrop'] = true;
189: $item['allowDrag'] = true;
190:
191: $nodeChildren = Mage::getResourceModel('catalog/product_attribute_collection')
192: ->setAttributeGroupFilter($node->getId())
193: ->addVisibleFilter()
194: ->checkConfigurableProducts()
195: ->load();
196:
197: if ($nodeChildren->getSize() > 0) {
198: $item['children'] = array();
199: foreach ($nodeChildren->getItems() as $child) {
200:
201: $attr = array(
202: 'text' => $child->getAttributeCode(),
203: 'id' => $child->getAttributeId(),
204: 'cls' => (!$child->getIsUserDefined()) ? 'system-leaf' : 'leaf',
205: 'allowDrop' => false,
206: 'allowDrag' => true,
207: 'leaf' => true,
208: 'is_user_defined' => $child->getIsUserDefined(),
209: 'is_configurable' => (int)in_array($child->getAttributeId(), $configurable),
210: 'entity_id' => $child->getEntityAttributeId()
211: );
212:
213: $item['children'][] = $attr;
214: }
215: }
216:
217: $items[] = $item;
218: }
219:
220: return Mage::helper('core')->jsonEncode($items);
221: }
222:
223: 224: 225: 226: 227:
228: public function getAttributeTreeJson()
229: {
230: $items = array();
231: $setId = $this->_getSetId();
232:
233: $collection = Mage::getResourceModel('catalog/product_attribute_collection')
234: ->setAttributeSetFilter($setId)
235: ->load();
236:
237: $attributesIds = array('0');
238:
239: foreach ($collection->getItems() as $item) {
240: $attributesIds[] = $item->getAttributeId();
241: }
242:
243: $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
244: ->setAttributesExcludeFilter($attributesIds)
245: ->addVisibleFilter()
246: ->load();
247:
248: foreach ($attributes as $child) {
249: $attr = array(
250: 'text' => $child->getAttributeCode(),
251: 'id' => $child->getAttributeId(),
252: 'cls' => 'leaf',
253: 'allowDrop' => false,
254: 'allowDrag' => true,
255: 'leaf' => true,
256: 'is_user_defined' => $child->getIsUserDefined(),
257: 'is_configurable' => false,
258: 'entity_id' => $child->getEntityId()
259: );
260:
261: $items[] = $attr;
262: }
263:
264: if (count($items) == 0) {
265: $items[] = array(
266: 'text' => Mage::helper('catalog')->__('Empty'),
267: 'id' => 'empty',
268: 'cls' => 'folder',
269: 'allowDrop' => false,
270: 'allowDrag' => false,
271: );
272: }
273:
274: return Mage::helper('core')->jsonEncode($items);
275: }
276:
277: 278: 279: 280: 281:
282: public function getBackButtonHtml()
283: {
284: return $this->getChildHtml('back_button');
285: }
286:
287: 288: 289: 290: 291:
292: public function getResetButtonHtml()
293: {
294: return $this->getChildHtml('reset_button');
295: }
296:
297: 298: 299: 300: 301:
302: public function getSaveButtonHtml()
303: {
304: return $this->getChildHtml('save_button');
305: }
306:
307: 308: 309: 310: 311:
312: public function getDeleteButtonHtml()
313: {
314: if ($this->getIsCurrentSetDefault()) {
315: return '';
316: }
317: return $this->getChildHtml('delete_button');
318: }
319:
320: 321: 322: 323: 324:
325: public function getDeleteGroupButton()
326: {
327: return $this->getChildHtml('delete_group_button');
328: }
329:
330: 331: 332: 333: 334:
335: public function getAddGroupButton()
336: {
337: return $this->getChildHtml('add_group_button');
338: }
339:
340: 341: 342: 343: 344:
345: public function getRenameButton()
346: {
347: return $this->getChildHtml('rename_button');
348: }
349:
350: 351: 352: 353: 354:
355: protected function _getAttributeSet()
356: {
357: return Mage::registry('current_attribute_set');
358: }
359:
360: 361: 362: 363: 364:
365: protected function _getSetId()
366: {
367: return $this->_getAttributeSet()->getId();
368: }
369:
370: 371: 372: 373: 374:
375: public function getIsCurrentSetDefault()
376: {
377: $isDefault = $this->getData('is_current_set_default');
378: if (is_null($isDefault)) {
379: $defaultSetId = Mage::getModel('eav/entity_type')
380: ->load(Mage::registry('entityType'))
381: ->getDefaultAttributeSetId();
382: $isDefault = $this->_getSetId() == $defaultSetId;
383: $this->setData('is_current_set_default', $isDefault);
384: }
385: return $isDefault;
386: }
387:
388: 389: 390: 391: 392: 393:
394: protected function _getSetData()
395: {
396: return $this->_getAttributeSet();
397: }
398:
399: 400: 401: 402: 403:
404: protected function _toHtml()
405: {
406: Mage::dispatchEvent('adminhtml_catalog_product_attribute_set_main_html_before', array('block' => $this));
407: return parent::_toHtml();
408: }
409: }
410: