PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php

https://bitbucket.org/kdms/sh-magento
PHP | 409 lines | 223 code | 46 blank | 140 comment | 6 complexity | 6e1b0f0345ca02a1a65748e1e7dde712 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento Enterprise Edition
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Magento Enterprise Edition License
  8. * that is bundled with this package in the file LICENSE_EE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.magentocommerce.com/license/enterprise-edition
  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://www.magentocommerce.com/license/enterprise-edition
  25. */
  26. /**
  27. * Adminhtml Catalog Attribute Set Main Block
  28. *
  29. * @category Mage
  30. * @package Mage_Adminhtml
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main extends Mage_Adminhtml_Block_Template
  34. {
  35. /**
  36. * Initialize template
  37. *
  38. */
  39. protected function _construct()
  40. {
  41. $this->setTemplate('catalog/product/attribute/set/main.phtml');
  42. }
  43. /**
  44. * Prepare Global Layout
  45. *
  46. * @return Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main
  47. */
  48. protected function _prepareLayout()
  49. {
  50. $setId = $this->_getSetId();
  51. $this->setChild('group_tree',
  52. $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main_tree_group')
  53. );
  54. $this->setChild('edit_set_form',
  55. $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main_formset')
  56. );
  57. $this->setChild('delete_group_button',
  58. $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
  59. 'label' => Mage::helper('catalog')->__('Delete Selected Group'),
  60. 'onclick' => 'editSet.submit();',
  61. 'class' => 'delete'
  62. )));
  63. $this->setChild('add_group_button',
  64. $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
  65. 'label' => Mage::helper('catalog')->__('Add New'),
  66. 'onclick' => 'editSet.addGroup();',
  67. 'class' => 'add'
  68. )));
  69. $this->setChild('back_button',
  70. $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
  71. 'label' => Mage::helper('catalog')->__('Back'),
  72. 'onclick' => 'setLocation(\''.$this->getUrl('*/*/').'\')',
  73. 'class' => 'back'
  74. )));
  75. $this->setChild('reset_button',
  76. $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
  77. 'label' => Mage::helper('catalog')->__('Reset'),
  78. 'onclick' => 'window.location.reload()'
  79. )));
  80. $this->setChild('save_button',
  81. $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
  82. 'label' => Mage::helper('catalog')->__('Save Attribute Set'),
  83. 'onclick' => 'editSet.save();',
  84. 'class' => 'save'
  85. )));
  86. $this->setChild('delete_button',
  87. $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
  88. 'label' => Mage::helper('catalog')->__('Delete Attribute Set'),
  89. '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)) . '\')',
  90. 'class' => 'delete'
  91. )));
  92. $this->setChild('rename_button',
  93. $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
  94. 'label' => Mage::helper('catalog')->__('New Set Name'),
  95. 'onclick' => 'editSet.rename()'
  96. )));
  97. return parent::_prepareLayout();
  98. }
  99. /**
  100. * Retrieve Attribute Set Group Tree HTML
  101. *
  102. * @return string
  103. */
  104. public function getGroupTreeHtml()
  105. {
  106. return $this->getChildHtml('group_tree');
  107. }
  108. /**
  109. * Retrieve Attribute Set Edit Form HTML
  110. *
  111. * @return string
  112. */
  113. public function getSetFormHtml()
  114. {
  115. return $this->getChildHtml('edit_set_form');
  116. }
  117. /**
  118. * Retrieve Block Header Text
  119. *
  120. * @return string
  121. */
  122. protected function _getHeader()
  123. {
  124. return Mage::helper('catalog')->__("Edit Attribute Set '%s'", $this->_getAttributeSet()->getAttributeSetName());
  125. }
  126. /**
  127. * Retrieve Attribute Set Save URL
  128. *
  129. * @return string
  130. */
  131. public function getMoveUrl()
  132. {
  133. return $this->getUrl('*/catalog_product_set/save', array('id' => $this->_getSetId()));
  134. }
  135. /**
  136. * Retrieve Attribute Set Group Save URL
  137. *
  138. * @return string
  139. */
  140. public function getGroupUrl()
  141. {
  142. return $this->getUrl('*/catalog_product_group/save', array('id' => $this->_getSetId()));
  143. }
  144. /**
  145. * Retrieve Attribute Set Group Tree as JSON format
  146. *
  147. * @return string
  148. */
  149. public function getGroupTreeJson()
  150. {
  151. $items = array();
  152. $setId = $this->_getSetId();
  153. /* @var $groups Mage_Eav_Model_Mysql4_Entity_Attribute_Group_Collection */
  154. $groups = Mage::getModel('eav/entity_attribute_group')
  155. ->getResourceCollection()
  156. ->setAttributeSetFilter($setId)
  157. ->setSortOrder()
  158. ->load();
  159. $configurable = Mage::getResourceModel('catalog/product_type_configurable_attribute')
  160. ->getUsedAttributes($setId);
  161. /* @var $node Mage_Eav_Model_Entity_Attribute_Group */
  162. foreach ($groups as $node) {
  163. $item = array();
  164. $item['text'] = $node->getAttributeGroupName();
  165. $item['id'] = $node->getAttributeGroupId();
  166. $item['cls'] = 'folder';
  167. $item['allowDrop'] = true;
  168. $item['allowDrag'] = true;
  169. $nodeChildren = Mage::getResourceModel('catalog/product_attribute_collection')
  170. ->setAttributeGroupFilter($node->getId())
  171. ->addVisibleFilter()
  172. ->checkConfigurableProducts()
  173. ->load();
  174. if ($nodeChildren->getSize() > 0) {
  175. $item['children'] = array();
  176. foreach ($nodeChildren->getItems() as $child) {
  177. /* @var $child Mage_Eav_Model_Entity_Attribute */
  178. $attr = array(
  179. 'text' => $child->getAttributeCode(),
  180. 'id' => $child->getAttributeId(),
  181. 'cls' => (!$child->getIsUserDefined()) ? 'system-leaf' : 'leaf',
  182. 'allowDrop' => false,
  183. 'allowDrag' => true,
  184. 'leaf' => true,
  185. 'is_user_defined' => $child->getIsUserDefined(),
  186. 'is_configurable' => (int)in_array($child->getAttributeId(), $configurable),
  187. 'entity_id' => $child->getEntityAttributeId()
  188. );
  189. $item['children'][] = $attr;
  190. }
  191. }
  192. $items[] = $item;
  193. }
  194. return Mage::helper('core')->jsonEncode($items);
  195. }
  196. /**
  197. * Retrieve Unused in Attribute Set Attribute Tree as JSON
  198. *
  199. * @return string
  200. */
  201. public function getAttributeTreeJson()
  202. {
  203. $items = array();
  204. $setId = $this->_getSetId();
  205. $collection = Mage::getResourceModel('catalog/product_attribute_collection')
  206. ->setAttributeSetFilter($setId)
  207. ->load();
  208. $attributesIds = array('0');
  209. /* @var $item Mage_Eav_Model_Entity_Attribute */
  210. foreach ($collection->getItems() as $item) {
  211. $attributesIds[] = $item->getAttributeId();
  212. }
  213. $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
  214. ->setAttributesExcludeFilter($attributesIds)
  215. ->addVisibleFilter()
  216. ->load();
  217. foreach ($attributes as $child) {
  218. $attr = array(
  219. 'text' => $child->getAttributeCode(),
  220. 'id' => $child->getAttributeId(),
  221. 'cls' => 'leaf',
  222. 'allowDrop' => false,
  223. 'allowDrag' => true,
  224. 'leaf' => true,
  225. 'is_user_defined' => $child->getIsUserDefined(),
  226. 'is_configurable' => false,
  227. 'entity_id' => $child->getEntityId()
  228. );
  229. $items[] = $attr;
  230. }
  231. if (count($items) == 0) {
  232. $items[] = array(
  233. 'text' => Mage::helper('catalog')->__('Empty'),
  234. 'id' => 'empty',
  235. 'cls' => 'folder',
  236. 'allowDrop' => false,
  237. 'allowDrag' => false,
  238. );
  239. }
  240. return Mage::helper('core')->jsonEncode($items);
  241. }
  242. /**
  243. * Retrieve Back Button HTML
  244. *
  245. * @return string
  246. */
  247. public function getBackButtonHtml()
  248. {
  249. return $this->getChildHtml('back_button');
  250. }
  251. /**
  252. * Retrieve Reset Button HTML
  253. *
  254. * @return string
  255. */
  256. public function getResetButtonHtml()
  257. {
  258. return $this->getChildHtml('reset_button');
  259. }
  260. /**
  261. * Retrieve Save Button HTML
  262. *
  263. * @return string
  264. */
  265. public function getSaveButtonHtml()
  266. {
  267. return $this->getChildHtml('save_button');
  268. }
  269. /**
  270. * Retrieve Delete Button HTML
  271. *
  272. * @return string
  273. */
  274. public function getDeleteButtonHtml()
  275. {
  276. if ($this->getIsCurrentSetDefault()) {
  277. return '';
  278. }
  279. return $this->getChildHtml('delete_button');
  280. }
  281. /**
  282. * Retrieve Delete Group Button HTML
  283. *
  284. * @return string
  285. */
  286. public function getDeleteGroupButton()
  287. {
  288. return $this->getChildHtml('delete_group_button');
  289. }
  290. /**
  291. * Retrieve Add New Group Button HTML
  292. *
  293. * @return string
  294. */
  295. public function getAddGroupButton()
  296. {
  297. return $this->getChildHtml('add_group_button');
  298. }
  299. /**
  300. * Retrieve Rename Button HTML
  301. *
  302. * @return string
  303. */
  304. public function getRenameButton()
  305. {
  306. return $this->getChildHtml('rename_button');
  307. }
  308. /**
  309. * Retrieve current Attribute Set object
  310. *
  311. * @return Mage_Eav_Model_Entity_Attribute_Set
  312. */
  313. protected function _getAttributeSet()
  314. {
  315. return Mage::registry('current_attribute_set');
  316. }
  317. /**
  318. * Retrieve current attribute set Id
  319. *
  320. * @return int
  321. */
  322. protected function _getSetId()
  323. {
  324. return $this->_getAttributeSet()->getId();
  325. }
  326. /**
  327. * Check Current Attribute Set is a default
  328. *
  329. * @return bool
  330. */
  331. public function getIsCurrentSetDefault()
  332. {
  333. $isDefault = $this->getData('is_current_set_default');
  334. if (is_null($isDefault)) {
  335. $defaultSetId = Mage::getModel('eav/entity_type')
  336. ->load(Mage::registry('entityType'))
  337. ->getDefaultAttributeSetId();
  338. $isDefault = $this->_getSetId() == $defaultSetId;
  339. $this->setData('is_current_set_default', $isDefault);
  340. }
  341. return $isDefault;
  342. }
  343. /**
  344. * Retrieve current Attribute Set object
  345. *
  346. * @deprecated use _getAttributeSet
  347. * @return Mage_Eav_Model_Entity_Attribute_Set
  348. */
  349. protected function _getSetData()
  350. {
  351. return $this->_getAttributeSet();
  352. }
  353. /**
  354. * Prepare HTML
  355. *
  356. * @return string
  357. */
  358. protected function _toHtml()
  359. {
  360. Mage::dispatchEvent('adminhtml_catalog_product_attribute_set_main_html_before', array('block' => $this));
  361. return parent::_toHtml();
  362. }
  363. }