PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/dnejedly/eaparts
PHP | 261 lines | 187 code | 29 blank | 45 comment | 12 complexity | f108d613493e62a2c97cca7c2d67ea28 MD5 | raw file
  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. * Product attribute add/edit form main tab
  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_Edit_Tab_Main extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract
  34. {
  35. /**
  36. * Adding product form elements for editing attribute
  37. *
  38. * @return Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Main
  39. */
  40. protected function _prepareForm()
  41. {
  42. parent::_prepareForm();
  43. $attributeObject = $this->getAttributeObject();
  44. /* @var $form Varien_Data_Form */
  45. $form = $this->getForm();
  46. /* @var $fieldset Varien_Data_Form_Element_Fieldset */
  47. $fieldset = $form->getElement('base_fieldset');
  48. $frontendInputElm = $form->getElement('frontend_input');
  49. $additionalTypes = array(
  50. array(
  51. 'value' => 'price',
  52. 'label' => Mage::helper('catalog')->__('Price')
  53. ),
  54. array(
  55. 'value' => 'media_image',
  56. 'label' => Mage::helper('catalog')->__('Media Image')
  57. )
  58. );
  59. if ($attributeObject->getFrontendInput() == 'gallery') {
  60. $additionalTypes[] = array(
  61. 'value' => 'gallery',
  62. 'label' => Mage::helper('catalog')->__('Gallery')
  63. );
  64. }
  65. $response = new Varien_Object();
  66. $response->setTypes(array());
  67. Mage::dispatchEvent('adminhtml_product_attribute_types', array('response'=>$response));
  68. $_disabledTypes = array();
  69. $_hiddenFields = array();
  70. foreach ($response->getTypes() as $type) {
  71. $additionalTypes[] = $type;
  72. if (isset($type['hide_fields'])) {
  73. $_hiddenFields[$type['value']] = $type['hide_fields'];
  74. }
  75. if (isset($type['disabled_types'])) {
  76. $_disabledTypes[$type['value']] = $type['disabled_types'];
  77. }
  78. }
  79. Mage::register('attribute_type_hidden_fields', $_hiddenFields);
  80. Mage::register('attribute_type_disabled_types', $_disabledTypes);
  81. $frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes);
  82. $frontendInputElm->setValues($frontendInputValues);
  83. $yesnoSource = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray();
  84. $scopes = array(
  85. Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>Mage::helper('catalog')->__('Store View'),
  86. Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE =>Mage::helper('catalog')->__('Website'),
  87. Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>Mage::helper('catalog')->__('Global'),
  88. );
  89. if ($attributeObject->getAttributeCode() == 'status' || $attributeObject->getAttributeCode() == 'tax_class_id') {
  90. unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]);
  91. }
  92. $fieldset->addField('is_global', 'select', array(
  93. 'name' => 'is_global',
  94. 'label' => Mage::helper('catalog')->__('Scope'),
  95. 'title' => Mage::helper('catalog')->__('Scope'),
  96. 'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'),
  97. 'values'=> $scopes
  98. ), 'attribute_code');
  99. $fieldset->addField('apply_to', 'apply', array(
  100. 'name' => 'apply_to[]',
  101. 'label' => Mage::helper('catalog')->__('Apply To'),
  102. 'values' => Mage_Catalog_Model_Product_Type::getOptions(),
  103. 'mode_labels' => array(
  104. 'all' => Mage::helper('catalog')->__('All Product Types'),
  105. 'custom' => Mage::helper('catalog')->__('Selected Product Types')
  106. ),
  107. 'required' => true
  108. ), 'frontend_class');
  109. $fieldset->addField('is_configurable', 'select', array(
  110. 'name' => 'is_configurable',
  111. 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'),
  112. 'values' => $yesnoSource,
  113. ), 'apply_to');
  114. // frontend properties fieldset
  115. $fieldset = $form->addFieldset('front_fieldset', array('legend'=>Mage::helper('catalog')->__('Frontend Properties')));
  116. $fieldset->addField('is_searchable', 'select', array(
  117. 'name' => 'is_searchable',
  118. 'label' => Mage::helper('catalog')->__('Use in Quick Search'),
  119. 'title' => Mage::helper('catalog')->__('Use in Quick Search'),
  120. 'values' => $yesnoSource,
  121. ));
  122. $fieldset->addField('is_visible_in_advanced_search', 'select', array(
  123. 'name' => 'is_visible_in_advanced_search',
  124. 'label' => Mage::helper('catalog')->__('Use in Advanced Search'),
  125. 'title' => Mage::helper('catalog')->__('Use in Advanced Search'),
  126. 'values' => $yesnoSource,
  127. ));
  128. $fieldset->addField('is_comparable', 'select', array(
  129. 'name' => 'is_comparable',
  130. 'label' => Mage::helper('catalog')->__('Comparable on Front-end'),
  131. 'title' => Mage::helper('catalog')->__('Comparable on Front-end'),
  132. 'values' => $yesnoSource,
  133. ));
  134. $fieldset->addField('is_filterable', 'select', array(
  135. 'name' => 'is_filterable',
  136. 'label' => Mage::helper('catalog')->__("Use In Layered Navigation"),
  137. 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'),
  138. 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'),
  139. 'values' => array(
  140. array('value' => '0', 'label' => Mage::helper('catalog')->__('No')),
  141. array('value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')),
  142. array('value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)')),
  143. ),
  144. ));
  145. $fieldset->addField('is_filterable_in_search', 'select', array(
  146. 'name' => 'is_filterable_in_search',
  147. 'label' => Mage::helper('catalog')->__("Use In Search Results Layered Navigation"),
  148. 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'),
  149. 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'),
  150. 'values' => $yesnoSource,
  151. ));
  152. $fieldset->addField('is_used_for_promo_rules', 'select', array(
  153. 'name' => 'is_used_for_promo_rules',
  154. 'label' => Mage::helper('catalog')->__('Use for Promo Rule Conditions'),
  155. 'title' => Mage::helper('catalog')->__('Use for Promo Rule Conditions'),
  156. 'values' => $yesnoSource,
  157. ));
  158. $fieldset->addField('position', 'text', array(
  159. 'name' => 'position',
  160. 'label' => Mage::helper('catalog')->__('Position'),
  161. 'title' => Mage::helper('catalog')->__('Position in Layered Navigation'),
  162. 'note' => Mage::helper('catalog')->__('Position of attribute in layered navigation block'),
  163. 'class' => 'validate-digits',
  164. ));
  165. $fieldset->addField('is_wysiwyg_enabled', 'select', array(
  166. 'name' => 'is_wysiwyg_enabled',
  167. 'label' => Mage::helper('catalog')->__('Enable WYSIWYG'),
  168. 'title' => Mage::helper('catalog')->__('Enable WYSIWYG'),
  169. 'values' => $yesnoSource,
  170. ));
  171. $htmlAllowed = $fieldset->addField('is_html_allowed_on_front', 'select', array(
  172. 'name' => 'is_html_allowed_on_front',
  173. 'label' => Mage::helper('catalog')->__('Allow HTML Tags on Frontend'),
  174. 'title' => Mage::helper('catalog')->__('Allow HTML Tags on Frontend'),
  175. 'values' => $yesnoSource,
  176. ));
  177. if (!$attributeObject->getId() || $attributeObject->getIsWysiwygEnabled()) {
  178. $attributeObject->setIsHtmlAllowedOnFront(1);
  179. }
  180. $fieldset->addField('is_visible_on_front', 'select', array(
  181. 'name' => 'is_visible_on_front',
  182. 'label' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'),
  183. 'title' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'),
  184. 'values' => $yesnoSource,
  185. ));
  186. $fieldset->addField('used_in_product_listing', 'select', array(
  187. 'name' => 'used_in_product_listing',
  188. 'label' => Mage::helper('catalog')->__('Used in Product Listing'),
  189. 'title' => Mage::helper('catalog')->__('Used in Product Listing'),
  190. 'note' => Mage::helper('catalog')->__('Depends on design theme'),
  191. 'values' => $yesnoSource,
  192. ));
  193. $fieldset->addField('used_for_sort_by', 'select', array(
  194. 'name' => 'used_for_sort_by',
  195. 'label' => Mage::helper('catalog')->__('Used for Sorting in Product Listing'),
  196. 'title' => Mage::helper('catalog')->__('Used for Sorting in Product Listing'),
  197. 'note' => Mage::helper('catalog')->__('Depends on design theme'),
  198. 'values' => $yesnoSource,
  199. ));
  200. $form->getElement('apply_to')->setSize(5);
  201. if ($applyTo = $attributeObject->getApplyTo()) {
  202. $applyTo = is_array($applyTo) ? $applyTo : explode(',', $applyTo);
  203. $form->getElement('apply_to')->setValue($applyTo);
  204. } else {
  205. $form->getElement('apply_to')->addClass('no-display ignore-validate');
  206. }
  207. // define field dependencies
  208. $this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
  209. ->addFieldMap("is_wysiwyg_enabled", 'wysiwyg_enabled')
  210. ->addFieldMap("is_html_allowed_on_front", 'html_allowed_on_front')
  211. ->addFieldMap("frontend_input", 'frontend_input_type')
  212. ->addFieldDependence('wysiwyg_enabled', 'frontend_input_type', 'textarea')
  213. ->addFieldDependence('html_allowed_on_front', 'wysiwyg_enabled', '0')
  214. );
  215. Mage::dispatchEvent('adminhtml_catalog_product_attribute_edit_prepare_form', array(
  216. 'form' => $form,
  217. 'attribute' => $attributeObject
  218. ));
  219. return $this;
  220. }
  221. /**
  222. * Retrieve additional element types for product attributes
  223. *
  224. * @return array
  225. */
  226. protected function _getAdditionalElementTypes()
  227. {
  228. return array(
  229. 'apply' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_apply'),
  230. );
  231. }
  232. }