1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
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://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Category tabs
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Catalog_Category_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
35: {
36: /**
37: * Default Attribute Tab Block
38: *
39: * @var string
40: */
41: protected $_attributeTabBlock = 'adminhtml/catalog_category_tab_attributes';
42:
43: /**
44: * Initialize Tabs
45: *
46: */
47: public function __construct()
48: {
49: parent::__construct();
50: $this->setId('category_info_tabs');
51: $this->setDestElementId('category_tab_content');
52: $this->setTitle(Mage::helper('catalog')->__('Category Data'));
53: $this->setTemplate('widget/tabshoriz.phtml');
54: }
55:
56: /**
57: * Retrieve cattegory object
58: *
59: * @return Mage_Catalog_Model_Category
60: */
61: public function getCategory()
62: {
63: return Mage::registry('current_category');
64: }
65:
66: /**
67: * Return Adminhtml Catalog Helper
68: *
69: * @return Mage_Adminhtml_Helper_Catalog
70: */
71: public function getCatalogHelper()
72: {
73: return Mage::helper('adminhtml/catalog');
74: }
75:
76: /**
77: * Getting attribute block name for tabs
78: *
79: * @return string
80: */
81: public function getAttributeTabBlock()
82: {
83: if ($block = $this->getCatalogHelper()->getCategoryAttributeTabBlock()) {
84: return $block;
85: }
86: return $this->_attributeTabBlock;
87: }
88:
89: /**
90: * Prepare Layout Content
91: *
92: * @return Mage_Adminhtml_Block_Catalog_Category_Tabs
93: */
94: protected function _prepareLayout()
95: {
96: $categoryAttributes = $this->getCategory()->getAttributes();
97: if (!$this->getCategory()->getId()) {
98: foreach ($categoryAttributes as $attribute) {
99: $default = $attribute->getDefaultValue();
100: if ($default != '') {
101: $this->getCategory()->setData($attribute->getAttributeCode(), $default);
102: }
103: }
104: }
105:
106: $attributeSetId = $this->getCategory()->getDefaultAttributeSetId();
107: /** @var $groupCollection Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection */
108: $groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection')
109: ->setAttributeSetFilter($attributeSetId)
110: ->setSortOrder()
111: ->load();
112: $defaultGroupId = 0;
113: foreach ($groupCollection as $group) {
114: /* @var $group Mage_Eav_Model_Entity_Attribute_Group */
115: if ($defaultGroupId == 0 or $group->getIsDefault()) {
116: $defaultGroupId = $group->getId();
117: }
118: }
119:
120: foreach ($groupCollection as $group) {
121: /* @var $group Mage_Eav_Model_Entity_Attribute_Group */
122: $attributes = array();
123: foreach ($categoryAttributes as $attribute) {
124: /* @var $attribute Mage_Eav_Model_Entity_Attribute */
125: if ($attribute->isInGroup($attributeSetId, $group->getId())) {
126: $attributes[] = $attribute;
127: }
128: }
129:
130: // do not add grops without attributes
131: if (!$attributes) {
132: continue;
133: }
134:
135: $active = $defaultGroupId == $group->getId();
136: $block = $this->getLayout()->createBlock($this->getAttributeTabBlock(), '')
137: ->setGroup($group)
138: ->setAttributes($attributes)
139: ->setAddHiddenFields($active)
140: ->toHtml();
141: $this->addTab('group_' . $group->getId(), array(
142: 'label' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
143: 'content' => $block,
144: 'active' => $active
145: ));
146: }
147:
148: $this->addTab('products', array(
149: 'label' => Mage::helper('catalog')->__('Category Products'),
150: 'content' => $this->getLayout()->createBlock(
151: 'adminhtml/catalog_category_tab_product',
152: 'category.product.grid'
153: )->toHtml(),
154: ));
155:
156: // dispatch event add custom tabs
157: Mage::dispatchEvent('adminhtml_catalog_category_tabs', array(
158: 'tabs' => $this
159: ));
160:
161: /*$this->addTab('features', array(
162: 'label' => Mage::helper('catalog')->__('Feature Products'),
163: 'content' => 'Feature Products'
164: )); */
165: return parent::_prepareLayout();
166: }
167: }
168: