public function getAttributeValueField($code = '', $i, $j, $current = '') { $html = ''; if ($code) { $attribute = Mage::getModel('catalog/product')->getResource()->getAttribute($code); if ($attribute && ($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect') || $code == 'product_type') { $options = array(); if ($code == 'product_type') { $attribute_options = Mage_Catalog_Model_Product_Type::getOptions(); } else { $attribute_options = $attribute->getSource()->getAllOptions(); } foreach ($attribute_options as $option) { extract($option); $selected = ''; if ($current == $value) { $selected = 'selected="selected"'; } $options[] = "<option value=\"{$value}\" {$selected}>{$label}</option>"; } $html = '<select style="width: 100%; border: 0pt none; padding: 0pt;" name="option[' . $i . '][condition][' . $j . '][value]">' . implode('', $options) . '</select>'; } } if ($html) { return $html; } else { return '<input style="width:100%;border:0;padding:0;" type="text" class="input-text" name="option[' . $i . '][condition][' . $j . '][value]" value="' . $current . '"/>'; } }
protected function _prepareForm() { /* @var $form Varien_Data_Form */ $form = new Varien_Data_Form(); /* @var $fieldset Varien_Data_Form_Element_Fieldset */ $fieldset = $form->addFieldset('permissions_product_create', array('legend' => Mage::helper('aitpermissions')->__('Product Creation Permissions'))); $this->_addElementTypes($fieldset); $fieldset->addField('allow_create_product', 'select', array('name' => 'allow_create_product', 'label' => Mage::helper('aitpermissions')->__('Allow to Сreate Products'), 'title' => Mage::helper('aitpermissions')->__('Allow to Сreate Products'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray())); $fieldset->addField('apply_to', 'apply', array('name' => 'apply_to[]', 'label' => Mage::helper('catalog')->__('Allow to Create'), 'values' => Mage_Catalog_Model_Product_Type::getOptions(), 'mode_labels' => array('all' => Mage::helper('catalog')->__('All Product Types'), 'custom' => Mage::helper('catalog')->__('Selected Product Types'))), 'frontend_class'); $this->setForm($form); $this->_setFormValues($form); }
protected function _prepareForm() { $model = Mage::registry('entity_attribute'); $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')); $fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('catalog')->__('Attribute Properties'))); if ($model->getAttributeId()) { $fieldset->addField('attribute_id', 'hidden', array('name' => 'attribute_id')); } $yesno = array(array('value' => 0, 'label' => Mage::helper('catalog')->__('No')), array('value' => 1, 'label' => Mage::helper('catalog')->__('Yes'))); $fieldset->addField('attribute_code', 'text', array('name' => 'attribute_code', 'label' => Mage::helper('catalog')->__('Attribute Identifier'), 'title' => Mage::helper('catalog')->__('Attribute Identifier'), 'note' => Mage::helper('catalog')->__('For internal use. Must be unique with no spaces'), 'class' => 'validate-code', 'required' => true)); $fieldset->addField('is_global', 'select', array('name' => 'is_global', 'label' => Mage::helper('catalog')->__('Scope'), 'title' => Mage::helper('catalog')->__('Scope'), 'note' => Mage::helper('catalog')->__('Declare atrribute value saving scope'), 'values' => array(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE => Mage::helper('catalog')->__('Store View'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE => Mage::helper('catalog')->__('Website'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL => Mage::helper('catalog')->__('Global')))); $fieldset->addField('frontend_input', 'select', array('name' => 'frontend_input', 'label' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'), 'title' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'), 'value' => 'text', 'values' => array(array('value' => 'text', 'label' => Mage::helper('catalog')->__('Text Field')), array('value' => 'textarea', 'label' => Mage::helper('catalog')->__('Text Area')), array('value' => 'date', 'label' => Mage::helper('catalog')->__('Date')), array('value' => 'boolean', 'label' => Mage::helper('catalog')->__('Yes/No')), array('value' => 'multiselect', 'label' => Mage::helper('catalog')->__('Multiple Select')), array('value' => 'select', 'label' => Mage::helper('catalog')->__('Dropdown')), array('value' => 'price', 'label' => Mage::helper('catalog')->__('Price')), array('value' => 'image', 'label' => Mage::helper('catalog')->__('Image')), array('value' => 'gallery', 'label' => Mage::helper('catalog')->__('Gallery')), array('value' => 'media_image', 'label' => Mage::helper('catalog')->__('Media Image'))))); $fieldset->addField('default_value_text', 'text', array('name' => 'default_value_text', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'value' => $model->getDefaultValue())); $fieldset->addField('default_value_yesno', 'select', array('name' => 'default_value_yesno', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'values' => $yesno, 'value' => $model->getDefaultValue())); $fieldset->addField('default_value_date', 'date', array('name' => 'default_value_date', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'value' => $model->getDefaultValue())); $fieldset->addField('default_value_textarea', 'textarea', array('name' => 'default_value_textarea', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'value' => $model->getDefaultValue())); $fieldset->addField('is_unique', 'select', array('name' => 'is_unique', 'label' => Mage::helper('catalog')->__('Unique Value'), 'title' => Mage::helper('catalog')->__('Unique Value (not shared with other products)'), 'note' => Mage::helper('catalog')->__('Not shared with other products'), 'values' => $yesno)); $fieldset->addField('is_required', 'select', array('name' => 'is_required', 'label' => Mage::helper('catalog')->__('Values Required'), 'title' => Mage::helper('catalog')->__('Values Required'), 'values' => $yesno)); $fieldset->addField('frontend_class', 'select', array('name' => 'frontend_class', 'label' => Mage::helper('catalog')->__('Input Validation for Store Owner'), 'title' => Mage::helper('catalog')->__('Input Validation for Store Owner'), 'values' => array(array('value' => '', 'label' => Mage::helper('catalog')->__('None')), array('value' => 'validate-number', 'label' => Mage::helper('catalog')->__('Decimal Number')), array('value' => 'validate-digits', 'label' => Mage::helper('catalog')->__('Integer Number')), array('value' => 'validate-email', 'label' => Mage::helper('catalog')->__('Email')), array('value' => 'validate-url', 'label' => Mage::helper('catalog')->__('Url')), array('value' => 'validate-alpha', 'label' => Mage::helper('catalog')->__('Letters')), array('value' => 'validate-alphanum', 'label' => Mage::helper('catalog')->__('Letters(a-z) or Numbers(0-9)'))))); /* $fieldset->addField('use_in_super_product', 'select', array( 'name' => 'use_in_super_product', 'label' => Mage::helper('catalog')->__('Apply To Configurable/Grouped Product'), 'values' => $yesno, )); */ $fieldset->addField('apply_to', 'multiselect', array('name' => 'apply_to[]', 'label' => Mage::helper('catalog')->__('Apply To'), 'values' => Mage_Catalog_Model_Product_Type::getOptions(), 'value' => array(Mage_Catalog_Model_Product_Type::DEFAULT_TYPE), 'required' => true)); $fieldset->addField('is_configurable', 'select', array('name' => 'is_configurable', 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'), 'values' => $yesno)); // ----- // frontend properties fieldset $fieldset = $form->addFieldset('front_fieldset', array('legend' => Mage::helper('catalog')->__('Frontend Properties'))); $fieldset->addField('is_searchable', 'select', array('name' => 'is_searchable', 'label' => Mage::helper('catalog')->__('Use in quick search'), 'title' => Mage::helper('catalog')->__('Use in quick search'), 'values' => $yesno)); $fieldset->addField('is_visible_in_advanced_search', 'select', array('name' => 'is_visible_in_advanced_search', 'label' => Mage::helper('catalog')->__('Use in advanced search'), 'title' => Mage::helper('catalog')->__('Use in advanced search'), 'values' => $yesno)); $fieldset->addField('is_comparable', 'select', array('name' => 'is_comparable', 'label' => Mage::helper('catalog')->__('Comparable on Front-end'), 'title' => Mage::helper('catalog')->__('Comparable on Front-end'), 'values' => $yesno)); $fieldset->addField('is_filterable', 'select', array('name' => 'is_filterable', 'label' => Mage::helper('catalog')->__("Use In Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown'), 'values' => array(array('value' => '0', 'label' => Mage::helper('catalog')->__('No')), array('value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')), array('value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)'))))); if ($model->getIsUserDefined() || !$model->getId()) { $fieldset->addField('is_visible_on_front', 'select', array('name' => 'is_visible_on_front', 'label' => Mage::helper('catalog')->__('Visible on Catalog Pages on Front-end'), 'title' => Mage::helper('catalog')->__('Visible on Catalog Pages on Front-end'), 'values' => $yesno)); } if ($model->getId()) { $form->getElement('attribute_code')->setDisabled(1); $form->getElement('frontend_input')->setDisabled(1); } if (!$model->getIsUserDefined() && $model->getId()) { $form->getElement('is_unique')->setDisabled(1); } $form->addValues($model->getData()); if ($model->getApplyTo()) { $form->getElement('apply_to')->setValue(explode(',', $model->getApplyTo())); } $this->setForm($form); return parent::_prepareForm(); }
/** * Creates the form for the condition based selection of product attributes. * * @return FireGento_DynamicCategory_Block_Adminhtml_Category_Dynamic Self. */ public function _prepareLayout() { parent::_prepareLayout(); $model = Mage::getSingleton('mep/rule'); $data = array(); if ($this->getCategory() != null) { $conditions = $this->getCategory()->getConditionsSerialized(); if (!is_array($conditions)) { $conditions = unserialize($conditions); } $data['conditions'] = $conditions; } $model->loadPost($data); $form = new Varien_Data_Form(); $form->setHtmlIdPrefix('mep_'); $form->setDataObject($this->getCategory()); $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')->setTemplate('mep/fieldset.phtml')->setNewChildUrl($this->getUrl('adminhtml/dynamic/newConditionHtml/form/mep_conditions_fieldset')); $fieldset = $form->addFieldset('conditions_fieldset', array('legend' => $this->__('Export Rules')))->setRenderer($renderer); $fieldset->addField('conditions', 'text', array('name' => 'conditions', 'label' => $this->__('Conditions'), 'title' => $this->__('Conditions')))->setRule($model)->setRenderer(Mage::getBlockSingleton('mep/conditions')); $specialRules = $form->addFieldset('special_rules_fieldset', array('legend' => $this->__('Special filters'))); $specialRules->addType('apply', 'Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Apply'); $specialRules->addField('apply_to', 'apply', array('name' => 'settings[apply_to][]', 'label' => Mage::helper('catalog')->__('Apply To'), 'values' => Mage_Catalog_Model_Product_Type::getOptions(), 'mode_labels' => array('all' => Mage::helper('catalog')->__('All Product Types'), 'custom' => Mage::helper('catalog')->__('Selected Product Types')), 'required' => true), 'frontend_class'); $form->getElement('apply_to')->setValue($this->getApplyToValue($form)); $specialRules->addField('is_in_stock', 'select', array('name' => 'settings[is_in_stock]', 'label' => Mage::helper('catalog')->__('Stock Availability'), 'values' => array_merge(Mage::getSingleton('cataloginventory/source_stock')->toOptionArray(), array('2' => '')), 'value' => $this->getProfilSettingsValueForKey('is_in_stock'), 'note' => $this->__('Will be used for mains and inheritors products'))); $specialRules->addType('qty', 'Flagbit_MEP_Helper_QtyFilter'); $specialRules->addField('qty', 'qty', array('name' => 'settings[qty][threshold]', 'dropdownName' => 'settings[qty][operator]', 'dropdownStyle' => 'width: 150px', 'dropdownValue' => $this->getQtyOperatorValue(), 'label' => Mage::helper('catalog')->__('Qty'), 'style' => 'width:50px', 'note' => $this->__('Will be used for mains and inheritors products'), 'required' => true)); $form->getElement('qty')->setValue($this->getQtyFilterValue($form)); $profilData = Mage::helper('mep')->getCurrentProfileData(); $settings = $profilData['settings']; if (!$settings) { $form->getElement('apply_to')->addClass('no-display ignore-validate'); $form->getElement('qty')->addClass('no-display ignore-validate'); } $this->setForm($form); return $this; }
public function assignBackendModelToAttribute(Varien_Event_Observer $observer) { $backendModel = 'weee/attribute_backend_weee_tax'; $object = $observer->getEvent()->getAttribute(); if ($object->getFrontendInput() == 'weee') { $object->setBackendModel($backendModel); if (!$object->getApplyTo()) { $applyTo = array(); foreach (Mage_Catalog_Model_Product_Type::getOptions() as $option) { if ($option['value'] == 'grouped') { continue; } $applyTo[] = $option['value']; } $object->setApplyTo($applyTo); } } }
/** * Adding product form elements for editing attribute * * @return Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Main */ protected function _prepareForm() { parent::_prepareForm(); $attributeObject = $this->getAttributeObject(); /* @var $form Varien_Data_Form */ $form = $this->getForm(); /* @var $fieldset Varien_Data_Form_Element_Fieldset */ $fieldset = $form->getElement('base_fieldset'); $frontendInputElm = $form->getElement('frontend_input'); $additionalTypes = array(array('value' => 'price', 'label' => Mage::helper('catalog')->__('Price')), array('value' => 'media_image', 'label' => Mage::helper('catalog')->__('Media Image'))); if ($attributeObject->getFrontendInput() == 'gallery') { $additionalTypes[] = array('value' => 'gallery', 'label' => Mage::helper('catalog')->__('Gallery')); } $response = new Varien_Object(); $response->setTypes(array()); Mage::dispatchEvent('adminhtml_product_attribute_types', array('response' => $response)); $_disabledTypes = array(); $_hiddenFields = array(); foreach ($response->getTypes() as $type) { $additionalTypes[] = $type; if (isset($type['hide_fields'])) { $_hiddenFields[$type['value']] = $type['hide_fields']; } if (isset($type['disabled_types'])) { $_disabledTypes[$type['value']] = $type['disabled_types']; } } Mage::register('attribute_type_hidden_fields', $_hiddenFields); Mage::register('attribute_type_disabled_types', $_disabledTypes); $frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes); $frontendInputElm->setValues($frontendInputValues); $yesnoSource = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(); $scopes = array(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE => Mage::helper('catalog')->__('Store View'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE => Mage::helper('catalog')->__('Website'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL => Mage::helper('catalog')->__('Global')); if ($attributeObject->getAttributeCode() == 'status' || $attributeObject->getAttributeCode() == 'tax_class_id') { unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]); } $fieldset->addField('is_global', 'select', array('name' => 'is_global', 'label' => Mage::helper('catalog')->__('Scope'), 'title' => Mage::helper('catalog')->__('Scope'), 'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'), 'values' => $scopes), 'attribute_code'); $fieldset->addField('apply_to', 'apply', array('name' => 'apply_to[]', 'label' => Mage::helper('catalog')->__('Apply To'), 'values' => Mage_Catalog_Model_Product_Type::getOptions(), 'mode_labels' => array('all' => Mage::helper('catalog')->__('All Product Types'), 'custom' => Mage::helper('catalog')->__('Selected Product Types')), 'required' => true), 'frontend_class'); $fieldset->addField('is_configurable', 'select', array('name' => 'is_configurable', 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'), 'values' => $yesnoSource), 'apply_to'); // frontend properties fieldset $fieldset = $form->addFieldset('front_fieldset', array('legend' => Mage::helper('catalog')->__('Frontend Properties'))); $fieldset->addField('is_searchable', 'select', array('name' => 'is_searchable', 'label' => Mage::helper('catalog')->__('Use in Quick Search'), 'title' => Mage::helper('catalog')->__('Use in Quick Search'), 'values' => $yesnoSource)); $fieldset->addField('is_visible_in_advanced_search', 'select', array('name' => 'is_visible_in_advanced_search', 'label' => Mage::helper('catalog')->__('Use in Advanced Search'), 'title' => Mage::helper('catalog')->__('Use in Advanced Search'), 'values' => $yesnoSource)); $fieldset->addField('is_comparable', 'select', array('name' => 'is_comparable', 'label' => Mage::helper('catalog')->__('Comparable on Front-end'), 'title' => Mage::helper('catalog')->__('Comparable on Front-end'), 'values' => $yesnoSource)); $fieldset->addField('is_filterable', 'select', array('name' => 'is_filterable', 'label' => Mage::helper('catalog')->__("Use In Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => array(array('value' => '0', 'label' => Mage::helper('catalog')->__('No')), array('value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')), array('value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)'))))); $fieldset->addField('is_filterable_in_search', 'select', array('name' => 'is_filterable_in_search', 'label' => Mage::helper('catalog')->__("Use In Search Results Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => $yesnoSource)); $fieldset->addField('is_used_for_promo_rules', 'select', array('name' => 'is_used_for_promo_rules', 'label' => Mage::helper('catalog')->__('Use for Promo Rule Conditions'), 'title' => Mage::helper('catalog')->__('Use for Promo Rule Conditions'), 'values' => $yesnoSource)); $fieldset->addField('position', 'text', array('name' => 'position', 'label' => Mage::helper('catalog')->__('Position'), 'title' => Mage::helper('catalog')->__('Position in Layered Navigation'), 'note' => Mage::helper('catalog')->__('Position of attribute in layered navigation block'), 'class' => 'validate-digits')); $fieldset->addField('is_wysiwyg_enabled', 'select', array('name' => 'is_wysiwyg_enabled', 'label' => Mage::helper('catalog')->__('Enable WYSIWYG'), 'title' => Mage::helper('catalog')->__('Enable WYSIWYG'), 'values' => $yesnoSource)); $htmlAllowed = $fieldset->addField('is_html_allowed_on_front', 'select', array('name' => 'is_html_allowed_on_front', 'label' => Mage::helper('catalog')->__('Allow HTML Tags on Frontend'), 'title' => Mage::helper('catalog')->__('Allow HTML Tags on Frontend'), 'values' => $yesnoSource)); if (!$attributeObject->getId() || $attributeObject->getIsWysiwygEnabled()) { $attributeObject->setIsHtmlAllowedOnFront(1); } $fieldset->addField('is_visible_on_front', 'select', array('name' => 'is_visible_on_front', 'label' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'), 'title' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'), 'values' => $yesnoSource)); $fieldset->addField('used_in_product_listing', 'select', array('name' => 'used_in_product_listing', 'label' => Mage::helper('catalog')->__('Used in Product Listing'), 'title' => Mage::helper('catalog')->__('Used in Product Listing'), 'note' => Mage::helper('catalog')->__('Depends on design theme'), 'values' => $yesnoSource)); $fieldset->addField('used_for_sort_by', 'select', array('name' => 'used_for_sort_by', 'label' => Mage::helper('catalog')->__('Used for Sorting in Product Listing'), 'title' => Mage::helper('catalog')->__('Used for Sorting in Product Listing'), 'note' => Mage::helper('catalog')->__('Depends on design theme'), 'values' => $yesnoSource)); $form->getElement('apply_to')->setSize(5); if ($applyTo = $attributeObject->getApplyTo()) { $applyTo = is_array($applyTo) ? $applyTo : explode(',', $applyTo); $form->getElement('apply_to')->setValue($applyTo); } else { $form->getElement('apply_to')->addClass('no-display ignore-validate'); } // define field dependencies $this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')->addFieldMap("is_wysiwyg_enabled", 'wysiwyg_enabled')->addFieldMap("is_html_allowed_on_front", 'html_allowed_on_front')->addFieldMap("frontend_input", 'frontend_input_type')->addFieldDependence('wysiwyg_enabled', 'frontend_input_type', 'textarea')->addFieldDependence('html_allowed_on_front', 'wysiwyg_enabled', '0')); Mage::dispatchEvent('adminhtml_catalog_product_attribute_edit_prepare_form', array('form' => $form, 'attribute' => $attributeObject)); return $this; }
/** * Automaticaly assign backend model to weee attributes * * @param Varien_Event_Observer $observer * @return Mage_Weee_Model_Observer */ public function assignBackendModelToAttribute(Varien_Event_Observer $observer) { $backendModel = Mage_Weee_Model_Attribute_Backend_Weee_Tax::getBackendModelName(); /** @var $object Mage_Eav_Model_Entity_Attribute_Abstract */ $object = $observer->getEvent()->getAttribute(); if ($object->getFrontendInput() == 'weee') { $object->setBackendModel($backendModel); if (!$object->getApplyTo()) { $applyTo = array(); foreach (Mage_Catalog_Model_Product_Type::getOptions() as $option) { if ($option['value'] == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) { continue; } $applyTo[] = $option['value']; } $object->setApplyTo($applyTo); } } return $this; }
public function testGetOptions() { $options = Mage_Catalog_Model_Product_Type::getOptions(); $this->_assertOptions($options); }
public function toOptionArray() { return Mage_Catalog_Model_Product_Type::getOptions(); }
protected function _prepareForm() { $model = Mage::registry('entity_attribute'); $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')); $disableAttributeFields = array('sku' => array('is_global', 'is_unique'), 'url_key' => array('is_unique')); $fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('catalog')->__('Attribute Properties'))); if ($model->getAttributeId()) { $fieldset->addField('attribute_id', 'hidden', array('name' => 'attribute_id')); } $this->_addElementTypes($fieldset); $yesno = array(array('value' => 0, 'label' => Mage::helper('catalog')->__('No')), array('value' => 1, 'label' => Mage::helper('catalog')->__('Yes'))); $fieldset->addField('attribute_code', 'text', array('name' => 'attribute_code', 'label' => Mage::helper('catalog')->__('Attribute Code'), 'title' => Mage::helper('catalog')->__('Attribute Code'), 'note' => Mage::helper('catalog')->__('For internal use. Must be unique with no spaces'), 'class' => 'validate-code', 'required' => true)); $scopes = array(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE => Mage::helper('catalog')->__('Store View'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE => Mage::helper('catalog')->__('Website'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL => Mage::helper('catalog')->__('Global')); if ($model->getAttributeCode() == 'status' || $model->getAttributeCode() == 'tax_class_id') { unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]); } $fieldset->addField('is_global', 'select', array('name' => 'is_global', 'label' => Mage::helper('catalog')->__('Scope'), 'title' => Mage::helper('catalog')->__('Scope'), 'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'), 'values' => $scopes)); $inputTypes = array(array('value' => 'text', 'label' => Mage::helper('catalog')->__('Text Field')), array('value' => 'textarea', 'label' => Mage::helper('catalog')->__('Text Area')), array('value' => 'date', 'label' => Mage::helper('catalog')->__('Date')), array('value' => 'boolean', 'label' => Mage::helper('catalog')->__('Yes/No')), array('value' => 'multiselect', 'label' => Mage::helper('catalog')->__('Multiple Select')), array('value' => 'select', 'label' => Mage::helper('catalog')->__('Dropdown')), array('value' => 'price', 'label' => Mage::helper('catalog')->__('Price')), array('value' => 'gallery', 'label' => Mage::helper('catalog')->__('Gallery')), array('value' => 'media_image', 'label' => Mage::helper('catalog')->__('Media Image'))); $response = new Varien_Object(); $response->setTypes(array()); Mage::dispatchEvent('adminhtml_product_attribute_types', array('response' => $response)); $_disabledTypes = array(); $_hiddenFields = array(); foreach ($response->getTypes() as $type) { $inputTypes[] = $type; if (isset($type['hide_fields'])) { $_hiddenFields[$type['value']] = $type['hide_fields']; } if (isset($type['disabled_types'])) { $_disabledTypes[$type['value']] = $type['disabled_types']; } } Mage::register('attribute_type_hidden_fields', $_hiddenFields); Mage::register('attribute_type_disabled_types', $_disabledTypes); $fieldset->addField('frontend_input', 'select', array('name' => 'frontend_input', 'label' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'), 'title' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'), 'value' => 'text', 'values' => $inputTypes)); $fieldset->addField('default_value_text', 'text', array('name' => 'default_value_text', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'value' => $model->getDefaultValue())); $fieldset->addField('default_value_yesno', 'select', array('name' => 'default_value_yesno', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'values' => $yesno, 'value' => $model->getDefaultValue())); $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $fieldset->addField('default_value_date', 'date', array('name' => 'default_value_date', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'value' => $model->getDefaultValue(), 'format' => $dateFormatIso)); $fieldset->addField('default_value_textarea', 'textarea', array('name' => 'default_value_textarea', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'value' => $model->getDefaultValue())); $fieldset->addField('is_unique', 'select', array('name' => 'is_unique', 'label' => Mage::helper('catalog')->__('Unique Value'), 'title' => Mage::helper('catalog')->__('Unique Value (not shared with other products)'), 'note' => Mage::helper('catalog')->__('Not shared with other products'), 'values' => $yesno)); $fieldset->addField('is_required', 'select', array('name' => 'is_required', 'label' => Mage::helper('catalog')->__('Values Required'), 'title' => Mage::helper('catalog')->__('Values Required'), 'values' => $yesno)); $fieldset->addField('frontend_class', 'select', array('name' => 'frontend_class', 'label' => Mage::helper('catalog')->__('Input Validation for Store Owner'), 'title' => Mage::helper('catalog')->__('Input Validation for Store Owner'), 'values' => array(array('value' => '', 'label' => Mage::helper('catalog')->__('None')), array('value' => 'validate-number', 'label' => Mage::helper('catalog')->__('Decimal Number')), array('value' => 'validate-digits', 'label' => Mage::helper('catalog')->__('Integer Number')), array('value' => 'validate-email', 'label' => Mage::helper('catalog')->__('Email')), array('value' => 'validate-url', 'label' => Mage::helper('catalog')->__('Url')), array('value' => 'validate-alpha', 'label' => Mage::helper('catalog')->__('Letters')), array('value' => 'validate-alphanum', 'label' => Mage::helper('catalog')->__('Letters(a-zA-Z) or Numbers(0-9)'))))); /* $fieldset->addField('use_in_super_product', 'select', array( 'name' => 'use_in_super_product', 'label' => Mage::helper('catalog')->__('Apply To Configurable/Grouped Product'), 'values' => $yesno, )); */ $fieldset->addField('apply_to', 'apply', array('name' => 'apply_to[]', 'label' => Mage::helper('catalog')->__('Apply To'), 'values' => Mage_Catalog_Model_Product_Type::getOptions(), 'mode_labels' => array('all' => Mage::helper('catalog')->__('All Product Types'), 'custom' => Mage::helper('catalog')->__('Selected Product Types')), 'required' => true)); $fieldset->addField('is_configurable', 'select', array('name' => 'is_configurable', 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'), 'values' => $yesno)); // ----- // frontend properties fieldset $fieldset = $form->addFieldset('front_fieldset', array('legend' => Mage::helper('catalog')->__('Frontend Properties'))); $fieldset->addField('is_searchable', 'select', array('name' => 'is_searchable', 'label' => Mage::helper('catalog')->__('Use in quick search'), 'title' => Mage::helper('catalog')->__('Use in quick search'), 'values' => $yesno)); $fieldset->addField('is_visible_in_advanced_search', 'select', array('name' => 'is_visible_in_advanced_search', 'label' => Mage::helper('catalog')->__('Use in advanced search'), 'title' => Mage::helper('catalog')->__('Use in advanced search'), 'values' => $yesno)); $fieldset->addField('is_comparable', 'select', array('name' => 'is_comparable', 'label' => Mage::helper('catalog')->__('Comparable on Front-end'), 'title' => Mage::helper('catalog')->__('Comparable on Front-end'), 'values' => $yesno)); $fieldset->addField('is_filterable', 'select', array('name' => 'is_filterable', 'label' => Mage::helper('catalog')->__("Use In Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => array(array('value' => '0', 'label' => Mage::helper('catalog')->__('No')), array('value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')), array('value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)'))))); $fieldset->addField('is_filterable_in_search', 'select', array('name' => 'is_filterable_in_search', 'label' => Mage::helper('catalog')->__("Use In Search Results Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => $yesno)); $fieldset->addField('is_used_for_price_rules', 'select', array('name' => 'is_used_for_price_rules', 'label' => Mage::helper('catalog')->__('Use for Price Rule Conditions'), 'title' => Mage::helper('catalog')->__('Use for Price Rule Conditions'), 'values' => $yesno)); $fieldset->addField('position', 'text', array('name' => 'position', 'label' => Mage::helper('catalog')->__('Position'), 'title' => Mage::helper('catalog')->__('Position In Layered Navigation'), 'note' => Mage::helper('catalog')->__('Position of attribute in layered navigation block'), 'class' => 'validate-digits')); $htmlAllowed = $fieldset->addField('is_html_allowed_on_front', 'select', array('name' => 'is_html_allowed_on_front', 'label' => Mage::helper('catalog')->__('Allow HTML-tags on Front-end'), 'title' => Mage::helper('catalog')->__('Allow HTML-tags on Front-end'), 'values' => $yesno)); if (!$model->getId()) { $htmlAllowed->setValue(1); } $fieldset->addField('is_visible_on_front', 'select', array('name' => 'is_visible_on_front', 'label' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'), 'title' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'), 'values' => $yesno)); $fieldset->addField('used_in_product_listing', 'select', array('name' => 'used_in_product_listing', 'label' => Mage::helper('catalog')->__('Used in product listing'), 'title' => Mage::helper('catalog')->__('Used in product listing'), 'note' => Mage::helper('catalog')->__('Depends on design theme'), 'values' => $yesno)); $fieldset->addField('used_for_sort_by', 'select', array('name' => 'used_for_sort_by', 'label' => Mage::helper('catalog')->__('Used for sorting in product listing'), 'title' => Mage::helper('catalog')->__('Used for sorting in product listing'), 'note' => Mage::helper('catalog')->__('Depends on design theme'), 'values' => $yesno)); if ($model->getId()) { $form->getElement('attribute_code')->setDisabled(1); $form->getElement('frontend_input')->setDisabled(1); if (isset($disableAttributeFields[$model->getAttributeCode()])) { foreach ($disableAttributeFields[$model->getAttributeCode()] as $field) { $form->getElement($field)->setDisabled(1); } } } if (!$model->getIsUserDefined() && $model->getId()) { $form->getElement('is_unique')->setDisabled(1); } $form->addValues($model->getData()); $form->getElement('apply_to')->setSize(5); if ($applyTo = $model->getApplyTo()) { $applyTo = is_array($applyTo) ? $applyTo : explode(',', $applyTo); $form->getElement('apply_to')->setValue($applyTo); } else { $form->getElement('apply_to')->addClass('no-display ignore-validate'); } $this->setForm($form); return parent::_prepareForm(); }
public function getattributevaluefieldAction() { $result = array(); $name = $this->getRequest()->getParam('element_name'); $condition_name = $this->getRequest()->getParam('condition_name'); if ($code = $this->getRequest()->getParam('attribute_code')) { $attribute = Mage::getModel('catalog/product')->getResource()->getAttribute($code); if ($attribute && ($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect') || $code == 'product_type') { $options = array(); if ($code == 'product_type') { $attribute_options = Mage_Catalog_Model_Product_Type::getOptions(); } else { $attribute_options = $attribute->getSource()->getAllOptions(); } foreach ($attribute_options as $option) { extract($option); $options[] = "<option value=\"{$value}\">{$label}</option>"; } $current = ''; $conditions = array('<option ' . ($current == 'eq' ? 'selected="selected"' : '') . ' value="eq">' . $this->__('equal') . '</option>', '<option ' . ($current == 'neq' ? 'selected="selected"' : '') . ' value="neq">' . $this->__('not equal') . '</option>'); $result['condition'] = '<select style="width:120px" name="' . $condition_name . '">' . implode('', $conditions) . '</select>'; $result['select'] = '<select style="width: 100%; border: 0pt none; padding: 0pt;" name="' . $name . '">' . implode('', $options) . '</select>'; } } if (empty($result)) { $current = ''; $conditions = array('<option ' . ($current == 'eq' ? 'selected="selected"' : '') . ' value="eq">' . $this->__('equal') . '</option>', '<option ' . ($current == 'neq' ? 'selected="selected"' : '') . ' value="neq">' . $this->__('not equal') . '</option>', '<option ' . ($current == 'gt' ? 'selected="selected"' : '') . ' value="gt">' . $this->__('greater than') . '</option>', '<option ' . ($current == 'lt' ? 'selected="selected"' : '') . ' value="lt">' . $this->__('less than') . '</option>', '<option ' . ($current == 'gteq' ? 'selected="selected"' : '') . ' value="gteq">' . $this->__('greater than or equal to') . '</option>', '<option ' . ($current == 'lteq' ? 'selected="selected"' : '') . ' value="lteq">' . $this->__('less than or equal to') . '</option>', '<option ' . ($current == 'like' ? 'selected="selected"' : '') . ' value="like">' . $this->__('like') . '</option>', '<option ' . ($current == 'nlike' ? 'selected="selected"' : '') . ' value="nlike">' . $this->__('not like') . '</option>'); $result['condition'] = '<select style="width:120px" name="' . $condition_name . '">' . implode('', $conditions) . '</select>'; $result['select'] = '<input style="width:100%;border:0;padding:0;" type="text" class="input-text" name="' . $name . '" value=""/>'; } $this->getResponse()->setBody(Zend_Json::encode($result)); }
public function getProductType($val) { if (is_null($this->_productTypes)) { $this->_productTypes = array(); $retarray = Mage_Catalog_Model_Product_Type::getOptions(); foreach (Mage_Catalog_Model_Product_Type::getOptions() as $value) { $this->_productTypes['value'][] = $value['value']; $this->_productTypes['label'][] = $value['label']; } } $val = str_replace($this->_productTypes['value'], $this->_productTypes['label'], $val); return $val; }
public static function getAttributeValueField($code = '', $name = '', $current = '', $store_id = null) { if ($code) { $attribute = Mage::getModel('catalog/product')->getResource()->getAttribute($code); if ($attribute && ($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect')) { $options = array(); foreach ($attribute->getSource()->getAllOptions() as $option) { extract($option); $selected = ''; if ($current == $value) { $selected = 'selected="selected"'; } $options[] = "<option value=\"{$value}\" {$selected}>{$label}</option>"; } return '<select style="width: 100%; border: 0pt none; padding: 0pt;" name="' . $name . '">' . implode('', $options) . '</select>'; } elseif ($code == 'category_id') { $options = array(); $options[] = "<option value=\"\"></option>"; if (!$store_id) { $store_id = Mage::app()->getStore()->getId(); } $store = Mage::getModel('core/store')->load($store_id); $categoryes = Mage::getModel('catalog/category')->load($store->getRootCategoryId())->getAllChildren(true); foreach ($categoryes as $cat_id) { if ($cat_id == $store->getRootCategoryId()) { continue; } $category = Mage::getModel('catalog/category')->load($cat_id); $selected = ''; if ($current == $category->getId()) { $selected = 'selected="selected"'; } $options[] = "<option value=\"{$category->getId()}\" {$selected}>{$category->getName()}</option>"; } return '<select style="width: 100%; border: 0pt none; padding: 0pt;" name="' . $name . '">' . implode('', $options) . '</select>'; } elseif ($code == 'product_type') { $options = array(); foreach (Mage_Catalog_Model_Product_Type::getOptions() as $product_type) { $selected = ''; if ($current == $product_type['value']) { $selected = 'selected="selected"'; } $options[] = "<option value=\"{$product_type['value']}\" {$selected}>{$product_type['label']}</option>"; } return '<select style="width: 100%; border: 0pt none; padding: 0pt;" name="' . $name . '">' . implode('', $options) . '</select>'; } else { return '<input style="width:100%;border:0;padding:0;" type="text" class="input-text" name="' . $name . '" value="' . $current . '"/>'; } } }