00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main extends Mage_Adminhtml_Block_Template
00034 {
00035 protected function _construct()
00036 {
00037 $this->setTemplate('catalog/product/attribute/set/main.phtml');
00038 }
00039
00040 protected function _prepareLayout()
00041 {
00042 $setId = $this->_getSetId();
00043
00044 $this->setChild('group_tree',
00045 $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main_tree_group')
00046 );
00047
00048 $this->setChild('edit_set_form',
00049 $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main_formset')
00050 );
00051
00052 $this->setChild('delete_group_button',
00053 $this->getLayout()->createBlock('adminhtml/widget_button')
00054 ->setData(array(
00055 'label' => Mage::helper('catalog')->__('Delete Selected Group'),
00056 'onclick' => 'editSet.submit();',
00057 'class' => 'delete'
00058 )));
00059
00060 $this->setChild('add_group_button',
00061 $this->getLayout()->createBlock('adminhtml/widget_button')
00062 ->setData(array(
00063 'label' => Mage::helper('catalog')->__('Add New'),
00064 'onclick' => 'editSet.addGroup();',
00065 'class' => 'add'
00066 )));
00067
00068 $this->setChild('back_button',
00069 $this->getLayout()->createBlock('adminhtml/widget_button')
00070 ->setData(array(
00071 'label' => Mage::helper('catalog')->__('Back'),
00072 'onclick' => 'setLocation(\''.$this->getUrl('*/*/').'\')',
00073 'class' => 'back'
00074 )));
00075
00076 $this->setChild('reset_button',
00077 $this->getLayout()->createBlock('adminhtml/widget_button')
00078 ->setData(array(
00079 'label' => Mage::helper('catalog')->__('Reset'),
00080 'onclick' => 'window.location.reload()'
00081 )));
00082
00083 $this->setChild('save_button',
00084 $this->getLayout()->createBlock('adminhtml/widget_button')
00085 ->setData(array(
00086 'label' => Mage::helper('catalog')->__('Save Attribute Set'),
00087 'onclick' => 'editSet.save();',
00088 'class' => 'save'
00089 )));
00090
00091 $this->setChild('delete_button',
00092 $this->getLayout()->createBlock('adminhtml/widget_button')
00093 ->setData(array(
00094 'label' => Mage::helper('catalog')->__('Delete Attribute Set'),
00095 '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)) . '\')',
00096 'class' => 'delete'
00097 )));
00098
00099 $this->setChild('rename_button',
00100 $this->getLayout()->createBlock('adminhtml/widget_button')
00101 ->setData(array(
00102 'label' => Mage::helper('catalog')->__('New Set Name'),
00103 'onclick' => 'editSet.rename()'
00104 ))
00105 );
00106 return parent::_prepareLayout();
00107 }
00108
00109 public function getGroupTreeHtml()
00110 {
00111 return $this->getChildHtml('group_tree');
00112 }
00113
00114 public function getSetFormHtml()
00115 {
00116 return $this->getChildHtml('edit_set_form');
00117 }
00118
00119 protected function _getHeader()
00120 {
00121 return Mage::helper('catalog')->__("Edit Attribute Set '%s'", $this->_getSetData()->getAttributeSetName());
00122 }
00123
00124 public function getMoveUrl()
00125 {
00126 return $this->getUrl('*/catalog_product_set/save', array('id' => $this->_getSetId()));
00127 }
00128
00129 public function getGroupUrl()
00130 {
00131 return $this->getUrl('*/catalog_product_group/save', array('id' => $this->_getSetId()));
00132 }
00133
00134 public function getGroupTreeJson()
00135 {
00136 $setId = $this->_getSetId();
00137
00138 $groups = Mage::getModel('eav/entity_attribute_group')
00139 ->getResourceCollection()
00140 ->setAttributeSetFilter($setId)
00141 ->load();
00142
00143 $items = array();
00144 foreach( $groups as $node ) {
00145 $item = array();
00146 $item['text']= $node->getAttributeGroupName();
00147 $item['id'] = $node->getAttributeGroupId();
00148 $item['cls'] = 'folder';
00149 $item['allowDrop'] = true;
00150 $item['allowDrag'] = true;
00151
00152 $nodeChildren = Mage::getModel('eav/entity_attribute')
00153 ->getResourceCollection()
00154 ->setAttributeGroupFilter($node->getAttributeGroupId())
00155 ->addVisibleFilter()
00156
00157
00158
00159
00160 ->checkConfigurableProducts()
00161 ->load();
00162
00163 if ( $nodeChildren->getSize() > 0 ) {
00164 $item['children'] = array();
00165 foreach( $nodeChildren->getItems() as $child ) {
00166 $tmpArr = array();
00167 $tmpArr['text'] = $child->getAttributeCode();
00168 $tmpArr['id'] = $child->getAttributeId();
00169 $tmpArr['cls'] = ( $child->getIsUserDefined() == 0 ) ? 'system-leaf' : 'leaf';
00170 $tmpArr['allowDrop'] = false;
00171 $tmpArr['allowDrag'] = true;
00172 $tmpArr['leaf'] = true;
00173 $tmpArr['is_user_defined'] = $child->getIsUserDefined();
00174 // TODO: issue #5126. Template already has reuqired changes
00175 $tmpArr['is_used_in_configurable'] = false; // (bool)$child->getIsUsedInConfigurable(); // TODO: issue #5126
00176 $tmpArr['entity_id'] = $child->getEntityAttributeId();
00177
00178 $item['children'][] = $tmpArr;
00179 }
00180 }
00181
00182 $items[] = $item;
00183 }
00184
00185 return Zend_Json::encode($items);
00186 }
00187
00188 public function getAttributeTreeJson()
00189 {
00190 $setId = $this->_getSetId();
00191
00192 $attributesIdsObj = Mage::getModel('eav/entity_attribute')
00193 ->getResourceCollection()
00194 ->setAttributeSetFilter($setId)
00195 ->load();
00196 $attributesIds = array('0');
00197 foreach( $attributesIdsObj->getItems() as $item ) {
00198 $attributesIds[] = $item->getAttributeId();
00199 }
00200 $attributes = Mage::getModel('eav/entity_attribute')
00201 ->getResourceCollection()
00202 ->setEntityTypeFilter(Mage::registry('entityType'))
00203 ->setAttributesExcludeFilter($attributesIds)
00204 ->addVisibleFilter()
00205 ->load();
00206
00207 $items = array();
00208 foreach( $attributes as $node ) {
00209 $item = array();
00210 $item['text']= $node->getAttributeCode();
00211 $item['id'] = $node->getAttributeId();
00212 $item['cls'] = 'leaf';
00213 $item['allowDrop'] = false;
00214 $item['allowDrag'] = true;
00215 $item['leaf'] = true;
00216 $item['is_user_defined'] = $node->getIsUserDefined();
00217 $item['is_used_in_configurable'] = false;
00218
00219 $items[] = $item;
00220 }
00221
00222 if( count($items) == 0 ) {
00223 $items[] = array(
00224 'text' => Mage::helper('catalog')->__('Empty'),
00225 'id' => 'empty',
00226 'cls' => 'folder',
00227 'allowDrop' => false,
00228 'allowDrag' => false,
00229 );
00230 }
00231
00232 return Zend_Json::encode($items);
00233 }
00234
00235 public function getBackButtonHtml()
00236 {
00237 return $this->getChildHtml('back_button');
00238 }
00239
00240 public function getResetButtonHtml()
00241 {
00242 return $this->getChildHtml('reset_button');
00243 }
00244
00245 public function getSaveButtonHtml()
00246 {
00247 return $this->getChildHtml('save_button');
00248 }
00249
00250 public function getDeleteButtonHtml()
00251 {
00252 if ($this->getIsCurrentSetDefault()) {
00253 return '';
00254 }
00255 return $this->getChildHtml('delete_button');
00256 }
00257
00258 public function getDeleteGroupButton()
00259 {
00260 return $this->getChildHtml('delete_group_button');
00261 }
00262
00263 public function getAddGroupButton()
00264 {
00265 return $this->getChildHtml('add_group_button');
00266 }
00267
00268 public function getRenameButton()
00269 {
00270 return $this->getChildHtml('rename_button');
00271 }
00272
00273 protected function _getSetId()
00274 {
00275 return Mage::registry('current_attribute_set')->getId();
00276 }
00277
00278 public function getIsCurrentSetDefault()
00279 {
00280 $isDefault = $this->getData('is_current_set_default');
00281 if (is_null($isDefault)) {
00282 $defaultSetId = Mage::getModel('eav/entity_type')
00283 ->load(Mage::registry('entityType'))
00284 ->getDefaultAttributeSetId();
00285 $isDefault = $this->_getSetId() == $defaultSetId;
00286 $this->setData('is_current_set_default', $isDefault);
00287 }
00288 return $isDefault;
00289 }
00290
00291 protected function _getSetData()
00292 {
00293 return Mage::getModel('eav/entity_attribute_set')->load( $this->_getSetId() );
00294 }
00295 }