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_Edit_Tab_Attributes extends Mage_Adminhtml_Block_Catalog_Form
35: {
36: 37: 38:
39: protected function _prepareLayout()
40: {
41: parent::_prepareLayout();
42: if (Mage::helper('catalog')->isModuleEnabled('Mage_Cms')
43: && Mage::getSingleton('cms/wysiwyg_config')->isEnabled()
44: ) {
45: $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
46: }
47: }
48:
49: 50: 51: 52: 53:
54: protected function _prepareForm()
55: {
56: $group = $this->getGroup();
57: if ($group) {
58: $form = new Varien_Data_Form();
59:
60:
61: $form->setDataObject(Mage::registry('product'));
62:
63: $fieldset = $form->addFieldset('group_fields' . $group->getId(), array(
64: 'legend' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
65: 'class' => 'fieldset-wide'
66: ));
67:
68: $attributes = $this->getGroupAttributes();
69:
70: $this->_setFieldset($attributes, $fieldset, array('gallery'));
71:
72: $urlKey = $form->getElement('url_key');
73: if ($urlKey) {
74: $urlKey->setRenderer(
75: $this->getLayout()->createBlock('adminhtml/catalog_form_renderer_attribute_urlkey')
76: );
77: }
78:
79: $tierPrice = $form->getElement('tier_price');
80: if ($tierPrice) {
81: $tierPrice->setRenderer(
82: $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_price_tier')
83: );
84: }
85:
86: $groupPrice = $form->getElement('group_price');
87: if ($groupPrice) {
88: $groupPrice->setRenderer(
89: $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_price_group')
90: );
91: }
92:
93: $recurringProfile = $form->getElement('recurring_profile');
94: if ($recurringProfile) {
95: $recurringProfile->setRenderer(
96: $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_price_recurring')
97: );
98: }
99:
100:
101: if (!$form->getElement('media_gallery')
102: && Mage::getSingleton('admin/session')->isAllowed('catalog/attributes/attributes')
103: ) {
104: $headerBar = $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_attributes_create');
105:
106: $headerBar->getConfig()
107: ->setTabId('group_' . $group->getId())
108: ->setGroupId($group->getId())
109: ->setStoreId($form->getDataObject()->getStoreId())
110: ->setAttributeSetId($form->getDataObject()->getAttributeSetId())
111: ->setTypeId($form->getDataObject()->getTypeId())
112: ->setProductId($form->getDataObject()->getId());
113:
114: $fieldset->setHeaderBar($headerBar->toHtml());
115: }
116:
117: if ($form->getElement('meta_description')) {
118: $form->getElement('meta_description')->setOnkeyup('checkMaxLength(this, 255);');
119: }
120:
121: $values = Mage::registry('product')->getData();
122:
123:
124: if (!Mage::registry('product')->getId()) {
125: foreach ($attributes as $attribute) {
126: if (!isset($values[$attribute->getAttributeCode()])) {
127: $values[$attribute->getAttributeCode()] = $attribute->getDefaultValue();
128: }
129: }
130: }
131:
132: if (Mage::registry('product')->hasLockedAttributes()) {
133: foreach (Mage::registry('product')->getLockedAttributes() as $attribute) {
134: $element = $form->getElement($attribute);
135: if ($element) {
136: $element->setReadonly(true, true);
137: }
138: }
139: }
140: $form->addValues($values);
141: $form->setFieldNameSuffix('product');
142:
143: Mage::dispatchEvent('adminhtml_catalog_product_edit_prepare_form', array('form' => $form));
144:
145: $this->setForm($form);
146: }
147: }
148:
149: 150: 151: 152: 153:
154: protected function _getAdditionalElementTypes()
155: {
156: $result = array(
157: 'price' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_price'),
158: 'weight' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_weight'),
159: 'gallery' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_gallery'),
160: 'image' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_image'),
161: 'boolean' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_boolean'),
162: 'textarea' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_helper_form_wysiwyg')
163: );
164:
165: $response = new Varien_Object();
166: $response->setTypes(array());
167: Mage::dispatchEvent('adminhtml_catalog_product_edit_element_types', array('response' => $response));
168:
169: foreach ($response->getTypes() as $typeName => $typeClass) {
170: $result[$typeName] = $typeClass;
171: }
172:
173: return $result;
174: }
175: }
176: