diff --git a/.phpstan.baseline.neon b/.phpstan.baseline.neon index 0c7663936..31f0f964c 100644 --- a/.phpstan.baseline.neon +++ b/.phpstan.baseline.neon @@ -438,12 +438,6 @@ parameters: count: 1 path: app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php - - - message: '#^Ternary operator condition is always true\.$#' - identifier: ternary.alwaysTrue - count: 1 - path: app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php - - message: '#^Method Mage_Adminhtml_Controller_Action\:\:_setForcedFormKeyActions\(\) invoked with 2 parameters, 1 required\.$#' identifier: arguments.count @@ -2467,34 +2461,22 @@ parameters: path: app/code/core/Mage/Customer/Block/Account/Navigation.php - - message: '#^Method Mage_Customer_Block_Address_Edit\:\:getCountryId\(\) should return int but returns string\.$#' - identifier: return.type - count: 1 - path: app/code/core/Mage/Customer/Block/Address/Edit.php - - - - message: '#^Return type \(int\) of method Mage_Customer_Block_Address_Edit\:\:getCountryId\(\) should be compatible with return type \(string\) of method Mage_Directory_Block_Data\:\:getCountryId\(\)$#' - identifier: method.childReturnType - count: 1 - path: app/code/core/Mage/Customer/Block/Address/Edit.php - - - - message: '#^Method Mage_Customer_Block_Form_Register\:\:getCountryId\(\) should return int but returns string\.$#' + message: '#^Method Mage_Customer_Block_Newsletter\:\:getAction\(\) should return Mage_Core_Controller_Varien_Action but returns string\.$#' identifier: return.type count: 1 - path: app/code/core/Mage/Customer/Block/Form/Register.php + path: app/code/core/Mage/Customer/Block/Newsletter.php - - message: '#^Return type \(int\) of method Mage_Customer_Block_Form_Register\:\:getCountryId\(\) should be compatible with return type \(string\) of method Mage_Directory_Block_Data\:\:getCountryId\(\)$#' - identifier: method.childReturnType - count: 1 - path: app/code/core/Mage/Customer/Block/Form/Register.php + message: '#^Method Mage_Eav_Model_Entity_Attribute_Source_Interface\:\:getAllOptions\(\) invoked with 1 parameter, 0 required\.$#' + identifier: arguments.count + count: 2 + path: app/code/core/Mage/Customer/Helper/Address.php - - message: '#^Method Mage_Customer_Block_Newsletter\:\:getAction\(\) should return Mage_Core_Controller_Varien_Action but returns string\.$#' - identifier: return.type - count: 1 - path: app/code/core/Mage/Customer/Block/Newsletter.php + message: '#^Method Mage_Eav_Model_Entity_Attribute_Source_Interface\:\:getAllOptions\(\) invoked with 1 parameter, 0 required\.$#' + identifier: arguments.count + count: 2 + path: app/code/core/Mage/Customer/Helper/Data.php - message: '#^Property Mage_Customer_Helper_Data\:\:\$_customer \(Mage_Customer_Model_Customer\) in empty\(\) is not falsy\.$#' @@ -4830,24 +4812,6 @@ parameters: count: 19 path: app/design/adminhtml/default/default/template/catalog/category/widget/tree.phtml - - - message: '#^Variable \$this might not be defined\.$#' - identifier: variable.undefined - count: 2 - path: app/design/adminhtml/default/default/template/catalog/product/attribute/new/created.phtml - - - - message: '#^Call to protected method _getHeader\(\) of class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main\.$#' - identifier: method.protected - count: 1 - path: app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml - - - - message: '#^Variable \$this might not be defined\.$#' - identifier: variable.undefined - count: 5 - path: app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/add.phtml - - message: '#^Call to protected method _getHeader\(\) of class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Toolbar_Main\.$#' identifier: method.protected @@ -5004,6 +4968,18 @@ parameters: count: 63 path: app/design/adminhtml/default/default/template/downloadable/sales/order/view/items/renderer/downloadable.phtml + - + message: '#^Call to protected method _getHeader\(\) of class Mage_Eav_Block_Adminhtml_Attribute_Set_Add\.$#' + identifier: method.protected + count: 1 + path: app/design/adminhtml/default/default/template/eav/attribute/set/add.phtml + + - + message: '#^Call to protected method _getHeader\(\) of class Mage_Eav_Block_Adminhtml_Attribute_Set_Edit\.$#' + identifier: method.protected + count: 1 + path: app/design/adminhtml/default/default/template/eav/attribute/set/edit.phtml + - message: '#^Variable \$this might not be defined\.$#' identifier: variable.undefined @@ -6306,12 +6282,6 @@ parameters: count: 10 path: app/design/frontend/base/default/template/checkout/multishipping/success.phtml - - - message: '#^Cannot call method isEnabled\(\) on Mage_Core_Block_Abstract\|false\.$#' - identifier: method.nonObject - count: 4 - path: app/design/frontend/base/default/template/checkout/onepage/billing.phtml - - message: '#^Variable \$this might not be defined\.$#' identifier: variable.undefined @@ -6576,42 +6546,6 @@ parameters: count: 4 path: app/design/frontend/base/default/template/customer/balance.phtml - - - message: '#^Variable \$action might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - - - message: '#^Variable \$address might not be defined\.$#' - identifier: variable.undefined - count: 2 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - - - message: '#^Variable \$countries might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - - - message: '#^Variable \$data might not be defined\.$#' - identifier: variable.undefined - count: 12 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - - - message: '#^Variable \$primaryTypes might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - - - message: '#^Variable \$this might not be defined\.$#' - identifier: variable.undefined - count: 50 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - message: '#^Variable \$action might not be defined\.$#' identifier: variable.undefined @@ -6633,7 +6567,7 @@ parameters: - message: '#^Variable \$this might not be defined\.$#' identifier: variable.undefined - count: 36 + count: 23 path: app/design/frontend/base/default/template/customer/form/edit.phtml - @@ -6648,12 +6582,6 @@ parameters: count: 16 path: app/design/frontend/base/default/template/customer/form/newsletter.phtml - - - message: '#^Cannot call method isEnabled\(\) on Mage_Core_Block_Abstract\|false\.$#' - identifier: method.nonObject - count: 3 - path: app/design/frontend/base/default/template/customer/form/register.phtml - - message: '#^PHPDoc tag @var contains unresolvable type\.$#' identifier: varTag.unresolvableType @@ -7572,42 +7500,6 @@ parameters: count: 3 path: app/design/frontend/rwd/default/template/customer/account/navigation.phtml - - - message: '#^Variable \$action might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - - - message: '#^Variable \$address might not be defined\.$#' - identifier: variable.undefined - count: 2 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - - - message: '#^Variable \$countries might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - - - message: '#^Variable \$data might not be defined\.$#' - identifier: variable.undefined - count: 12 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - - - message: '#^Variable \$primaryTypes might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - - - message: '#^Variable \$this might not be defined\.$#' - identifier: variable.undefined - count: 51 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - message: '#^Variable \$action might not be defined\.$#' identifier: variable.undefined @@ -7626,12 +7518,6 @@ parameters: count: 13 path: app/design/frontend/rwd/default/template/customer/form/confirmation.phtml - - - message: '#^Variable \$this might not be defined\.$#' - identifier: variable.undefined - count: 36 - path: app/design/frontend/rwd/default/template/customer/form/edit.phtml - - message: '#^Variable \$this might not be defined\.$#' identifier: variable.undefined diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute.php index 840a4e199..68ee8a146 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute.php @@ -6,6 +6,7 @@ * @package Mage_Adminhtml * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2022-2023 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -15,13 +16,22 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Container +class Mage_Adminhtml_Block_Catalog_Product_Attribute extends Mage_Eav_Block_Adminhtml_Attribute { public function __construct() { + $this->entityType = Mage::registry('entity_type'); + + $this->_blockGroup = 'adminhtml'; $this->_controller = 'catalog_product_attribute'; - $this->_headerText = Mage::helper('catalog')->__('Manage Attributes'); - $this->_addButtonLabel = Mage::helper('catalog')->__('Add New Attribute'); - parent::__construct(); + + $this->_headerText = $this->__( + 'Manage %s Attributes', + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()) + ); + + $this->_addButtonLabel = Mage::helper('eav')->__('Add New Attribute'); + + Mage_Adminhtml_Block_Widget_Grid_Container::__construct(); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit.php index dfe751e77..b7229e1b4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit.php @@ -16,78 +16,42 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit extends Mage_Adminhtml_Block_Widget_Form_Container +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit extends Mage_Eav_Block_Adminhtml_Attribute_Edit { public function __construct() { + $this->entityType = Mage::registry('entity_type'); + $this->entityAttribute = Mage::registry('entity_attribute'); + $this->_objectId = 'attribute_id'; + $this->_blockGroup = 'adminhtml'; $this->_controller = 'catalog_product_attribute'; - parent::__construct(); + Mage_Adminhtml_Block_Widget_Form_Container::__construct(); if ($this->getRequest()->getParam('popup')) { $this->_removeButton('back'); - $this->_addButton( - 'close', - [ - 'label' => Mage::helper('catalog')->__('Close Window'), - 'class' => 'cancel', - 'onclick' => 'window.close()', - 'level' => -1 - ] - ); + $this->_addButton('close', [ + 'label' => Mage::helper('catalog')->__('Close Window'), + 'class' => 'cancel', + 'onclick' => 'window.close()', + 'level' => -1 + ]); } else { - $this->_addButton( - 'save_and_edit_button', - [ - 'label' => Mage::helper('catalog')->__('Save and Continue Edit'), - 'onclick' => 'saveAndContinueEdit()', - 'class' => 'save' - ], - 100 - ); + $this->_addButton('save_and_edit_button', [ + 'label' => Mage::helper('catalog')->__('Save and Continue Edit'), + 'onclick' => 'saveAndContinueEdit()', + 'class' => 'save' + ], 100); } $this->_updateButton('save', 'label', Mage::helper('catalog')->__('Save Attribute')); $this->_updateButton('save', 'onclick', 'saveAttribute()'); - if (!Mage::registry('entity_attribute')->getIsUserDefined()) { - $this->_removeButton('delete'); + if ($this->entityAttribute->getIsUserDefined()) { + $this->_updateButton('delete', 'label', $this->__('Delete Attribute')); } else { - $this->_updateButton('delete', 'label', Mage::helper('catalog')->__('Delete Attribute')); - } - } - - /** - * @return string - */ - #[\Override] - public function getHeaderText() - { - if (Mage::registry('entity_attribute')->getId()) { - $frontendLabel = Mage::registry('entity_attribute')->getFrontendLabel(); - if (is_array($frontendLabel)) { - $frontendLabel = $frontendLabel[0]; - } - return Mage::helper('catalog')->__('Edit Product Attribute "%s"', $this->escapeHtml($frontendLabel)); + $this->_removeButton('delete'); } - return Mage::helper('catalog')->__('New Product Attribute'); - } - - /** - * @return string - */ - public function getValidationUrl() - { - return $this->getUrl('*/*/validate', ['_current' => true]); - } - - /** - * @return string - */ - #[\Override] - public function getSaveUrl() - { - return $this->getUrl('*/' . $this->_controller . '/save', ['_current' => true, 'back' => null]); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Form.php index 7bb3d1063..869fef83c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Form.php @@ -16,14 +16,6 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Form extends Mage_Adminhtml_Block_Widget_Form +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Form extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Form { - #[\Override] - protected function _prepareForm() - { - $form = new Varien_Data_Form(['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']); - $form->setUseContainer(true); - $this->setForm($form); - return parent::_prepareForm(); - } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Front.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Front.php deleted file mode 100644 index 5b59490bf..000000000 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Front.php +++ /dev/null @@ -1,85 +0,0 @@ - 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']); - - $fieldset = $form->addFieldset('base_fieldset', ['legend' => Mage::helper('catalog')->__('Frontend Properties')]); - - $yesno = [ - [ - 'value' => 0, - 'label' => Mage::helper('catalog')->__('No') - ], - [ - 'value' => 1, - 'label' => Mage::helper('catalog')->__('Yes') - ]]; - - $fieldset->addField('is_searchable', 'select', [ - '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', [ - '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', [ - 'name' => 'is_comparable', - 'label' => Mage::helper('catalog')->__('Comparable on the Frontend'), - 'title' => Mage::helper('catalog')->__('Comparable on the Frontend'), - 'values' => $yesno, - ]); - - $fieldset->addField('is_filterable', 'select', [ - 'name' => 'is_filterable', - 'label' => Mage::helper('catalog')->__("Use in Layered Navigation
(Can be used only with catalog input type 'Dropdown')"), - 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown'), - 'values' => [ - ['value' => '0', 'label' => Mage::helper('catalog')->__('No')], - ['value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')], - ['value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)')], - ], - ]); - - $fieldset->addField('is_visible_on_front', 'select', [ - '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, - ]); - - $form->setValues($model->getData()); - - $this->setForm($form); - - return parent::_prepareForm(); - } -} diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php index 20c69f3c9..497b5c76d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php @@ -19,79 +19,35 @@ class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Main extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract { /** - * Adding product form elements for editing attribute - * - * @return $this + * Add additional form elements for editing product attributes */ #[\Override] protected function _prepareForm() { parent::_prepareForm(); + $attributeObject = $this->getAttributeObject(); + $entityTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); + + /** @var Varien_Data_Form $form */ $form = $this->getForm(); + /** @var Varien_Data_Form_Element_Fieldset $fieldset */ $fieldset = $form->getElement('base_fieldset'); - $fieldset->getElements() - ->searchById('attribute_code') - ->setData( - 'class', - 'validate-code-event ' . $fieldset->getElements()->searchById('attribute_code')->getData('class') - )->setData( - 'note', - $fieldset->getElements()->searchById('attribute_code')->getData('note') - . Mage::helper('eav')->__('. Do not use "event" for an attribute code, it is a reserved keyword.') - ); - - $frontendInputElm = $form->getElement('frontend_input'); - $additionalTypes = [ - [ - 'value' => 'price', - 'label' => Mage::helper('catalog')->__('Price') - ], - [ - 'value' => 'media_image', - 'label' => Mage::helper('catalog')->__('Media Image') - ] - ]; - if ($attributeObject->getFrontendInput() == 'gallery') { - $additionalTypes[] = [ - 'value' => 'gallery', - 'label' => Mage::helper('catalog')->__('Gallery') - ]; - } - - $response = new Varien_Object(); - $response->setTypes([]); - Mage::dispatchEvent('adminhtml_product_attribute_types', ['response' => $response]); - $_disabledTypes = []; - $_hiddenFields = []; - 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']; - } + $inputTypes = Mage::helper('eav')->getInputTypes($entityTypeCode); + if ($attributeObject->getFrontendInput() !== 'gallery') { + unset($inputTypes['gallery']); } - 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(); + $form->getElement('frontend_input')->setValues($inputTypes); $scopes = [ - Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE => Mage::helper('catalog')->__('Store View'), + 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'), + Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL => Mage::helper('catalog')->__('Global'), ]; - if ($attributeObject->getAttributeCode() === 'status' - || $attributeObject->getAttributeCode() === 'tax_class_id' - ) { + if (in_array($attributeObject->getAttributeCode(), ['status', 'tax_class_id'])) { unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]); } @@ -112,43 +68,45 @@ protected function _prepareForm() 'custom' => Mage::helper('catalog')->__('Selected Product Types') ], 'required' => true - ], 'frontend_class'); + ]); - $fieldset->addField('is_configurable', 'select', [ + $fieldset->addField('is_configurable', 'boolean', [ 'name' => 'is_configurable', 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'), - 'values' => $yesnoSource, - ], 'apply_to'); + ]); + + $form->getElement('frontend_input') + ->setLabel(Mage::helper('catalog')->__('Input Type for Store Owner')) + ->setTitle(Mage::helper('catalog')->__('Input Type for Store Owner')); + + $form->getElement('frontend_class') + ->setLabel(Mage::helper('catalog')->__('Input Validation for Store Owner')) + ->setTitle(Mage::helper('catalog')->__('Input Validation for Store Owner')); // frontend properties fieldset $fieldset = $form->addFieldset('front_fieldset', ['legend' => Mage::helper('catalog')->__('Frontend Properties')]); - $fieldset->addField('is_searchable', 'select', [ + $fieldset->addField('is_searchable', 'boolean', [ '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', [ + $fieldset->addField('is_visible_in_advanced_search', 'boolean', [ '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', [ + $fieldset->addField('is_comparable', 'boolean', [ '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', [ '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' => [ ['value' => '0', 'label' => Mage::helper('catalog')->__('No')], ['value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')], @@ -156,19 +114,15 @@ protected function _prepareForm() ], ]); - $fieldset->addField('is_filterable_in_search', 'select', [ + $fieldset->addField('is_filterable_in_search', 'boolean', [ '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', [ + $fieldset->addField('is_used_for_promo_rules', 'boolean', [ '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', [ @@ -179,43 +133,39 @@ protected function _prepareForm() 'class' => 'validate-digits', ]); - $fieldset->addField('is_wysiwyg_enabled', 'select', [ + $fieldset->addField('is_html_allowed_on_front', 'boolean', [ + 'name' => 'is_html_allowed_on_front', + 'label' => Mage::helper('catalog')->__('Allow HTML Tags on Frontend'), + 'title' => Mage::helper('catalog')->__('Allow HTML Tags on Frontend'), + ]); + + $fieldset->addField('is_wysiwyg_enabled', 'boolean', [ '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', [ - '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); - } + // if (!$attributeObject->getId() || $attributeObject->getIsWysiwygEnabled()) { + // $attributeObject->setIsHtmlAllowedOnFront(1); + // } - $fieldset->addField('is_visible_on_front', 'select', [ + $fieldset->addField('is_visible_on_front', 'boolean', [ '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', [ + $fieldset->addField('used_in_product_listing', 'boolean', [ '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', [ + $fieldset->addField('used_for_sort_by', 'boolean', [ '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); @@ -227,34 +177,56 @@ protected function _prepareForm() $form->getElement('apply_to')->addClass('no-display ignore-validate'); } - // define field dependencies /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $block */ - $block = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence'); - $this->setChild('form_after', $block - ->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')); + $block = $this->_getDependence(); + + $block + ->addFieldDependence('is_filterable', 'frontend_input', ['select', 'multiselect', 'price']) + ->addFieldDependence('is_filterable_in_search', 'frontend_input', ['select', 'multiselect', 'price']) + ->addComplexFieldDependence('is_required', $block::MODE_NOT, [ + 'frontend_input' => ['media_image'], + ]) + ->addComplexFieldDependence('is_unique', $block::MODE_NOT, [ + 'frontend_input' => ['media_image'], + ]) + ->addComplexFieldDependence('is_global', $block::MODE_NOT, [ + 'frontend_input' => ['price'], + ]) + ->addComplexFieldDependence('is_configurable', $block::MODE_AND, [ + 'is_global' => '1', + 'frontend_input' => ['select'], + ]) + ->addComplexFieldDependence('position', $block::MODE_NOT, [ + 'is_filterable' => '0', + ]) + ->addComplexFieldDependence('used_for_sort_by', $block::MODE_NOT, [ + 'frontend_input' => ['multiselect', 'textarea', 'gallery'], + ]) + ->addComplexFieldDependence('is_html_allowed_on_front', $block::MODE_AND, [ + 'frontend_input' => ['text', 'textarea', 'select', 'multiselect', 'customselect'], + ]) + ->addComplexFieldDependence('is_wysiwyg_enabled', $block::MODE_AND, [ + 'frontend_input' => 'textarea', + 'is_html_allowed_on_front' => '1', + ]); Mage::dispatchEvent('adminhtml_catalog_product_attribute_edit_prepare_form', [ - 'form' => $form, - 'attribute' => $attributeObject + 'form' => $form, + 'attribute' => $attributeObject, + 'dependence' => $block, ]); return $this; } /** - * Retrieve additional element types for product attributes - * - * @return array + * Set additional element types for product attribute edit form */ #[\Override] protected function _getAdditionalElementTypes() { return [ - 'apply' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_apply'), + 'apply' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_product_helper_form_apply'), ]; } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/System.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/System.php deleted file mode 100644 index 1dc08263e..000000000 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/System.php +++ /dev/null @@ -1,117 +0,0 @@ -addFieldset('base_fieldset', ['legend' => Mage::helper('catalog')->__('System Properties')]); - - if ($model->getAttributeId()) { - $fieldset->addField('attribute_id', 'hidden', [ - 'name' => 'attribute_id', - ]); - } - - $yesno = [ - [ - 'value' => 0, - 'label' => Mage::helper('catalog')->__('No') - ], - [ - 'value' => 1, - 'label' => Mage::helper('catalog')->__('Yes') - ]]; - - /*$fieldset->addField('attribute_model', 'text', array( - 'name' => 'attribute_model', - 'label' => Mage::helper('catalog')->__('Attribute Model'), - 'title' => Mage::helper('catalog')->__('Attribute Model'), - )); - - $fieldset->addField('backend_model', 'text', array( - 'name' => 'backend_model', - 'label' => Mage::helper('catalog')->__('Backend Model'), - 'title' => Mage::helper('catalog')->__('Backend Model'), - ));*/ - - $fieldset->addField('backend_type', 'select', [ - 'name' => 'backend_type', - 'label' => Mage::helper('catalog')->__('Data Type for Saving in Database'), - 'title' => Mage::helper('catalog')->__('Data Type for Saving in Database'), - 'options' => [ - 'text' => Mage::helper('catalog')->__('Text'), - 'varchar' => Mage::helper('catalog')->__('Varchar'), - 'static' => Mage::helper('catalog')->__('Static'), - 'datetime' => Mage::helper('catalog')->__('Datetime'), - 'decimal' => Mage::helper('catalog')->__('Decimal'), - 'int' => Mage::helper('catalog')->__('Integer'), - ], - ]); - - /*$fieldset->addField('backend_table', 'text', array( - 'name' => 'backend_table', - 'label' => Mage::helper('catalog')->__('Backend Table'), - 'title' => Mage::helper('catalog')->__('Backend Table Title'), - )); - - $fieldset->addField('frontend_model', 'text', array( - 'name' => 'frontend_model', - 'label' => Mage::helper('catalog')->__('Frontend Model'), - 'title' => Mage::helper('catalog')->__('Frontend Model'), - ));*/ - - /*$fieldset->addField('is_visible', 'select', array( - 'name' => 'is_visible', - 'label' => Mage::helper('catalog')->__('Visible'), - 'title' => Mage::helper('catalog')->__('Visible'), - 'values' => $yesno, - ));*/ - - /*$fieldset->addField('source_model', 'text', array( - 'name' => 'source_model', - 'label' => Mage::helper('catalog')->__('Source Model'), - 'title' => Mage::helper('catalog')->__('Source Model'), - ));*/ - - $fieldset->addField('is_global', 'select', [ - 'name' => 'is_global', - 'label' => Mage::helper('catalog')->__('Globally Editable'), - 'title' => Mage::helper('catalog')->__('Globally Editable'), - 'values' => $yesno, - ]); - - $form->setValues($model->getData()); - - if ($model->getAttributeId()) { - $form->getElement('backend_type')->setDisabled(1); - if ($model->getIsGlobal()) { - #$form->getElement('is_global')->setDisabled(1); - } - } else { - } - - $this->setForm($form); - - return parent::_prepareForm(); - } -} diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tabs.php index e0a1fa279..7be9a6d4d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tabs.php @@ -16,42 +16,11 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tabs extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Tabs { public function __construct() { parent::__construct(); $this->setId('product_attribute_tabs'); - $this->setDestElementId('edit_form'); - $this->setTitle(Mage::helper('catalog')->__('Attribute Information')); - } - - #[\Override] - protected function _beforeToHtml() - { - $this->addTab('main', [ - 'label' => Mage::helper('catalog')->__('Properties'), - 'title' => Mage::helper('catalog')->__('Properties'), - 'content' => $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_edit_tab_main')->toHtml(), - 'active' => true - ]); - - $model = Mage::registry('entity_attribute'); - - $this->addTab('labels', [ - 'label' => Mage::helper('catalog')->__('Manage Label / Options'), - 'title' => Mage::helper('catalog')->__('Manage Label / Options'), - 'content' => $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_edit_tab_options')->toHtml(), - ]); - - /*if ('select' == $model->getFrontendInput()) { - $this->addTab('options_section', array( - 'label' => Mage::helper('catalog')->__('Options Control'), - 'title' => Mage::helper('catalog')->__('Options Control'), - 'content' => $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_edit_tab_options')->toHtml(), - )); - }*/ - - return parent::_beforeToHtml(); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php index e9640a1ab..e9588ea24 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Grid.php @@ -16,23 +16,8 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Grid extends Mage_Eav_Block_Adminhtml_Attribute_Grid_Abstract +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Grid extends Mage_Eav_Block_Adminhtml_Attribute_Grid { - /** - * Prepare product attributes grid collection object - * - * @return $this - */ - #[\Override] - protected function _prepareCollection() - { - $collection = Mage::getResourceModel('catalog/product_attribute_collection') - ->addVisibleFilter(); - $this->setCollection($collection); - - return parent::_prepareCollection(); - } - /** * Prepare product attributes grid columns * diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Attribute.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set.php similarity index 54% rename from app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Attribute.php rename to app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set.php index c28b76205..964e61774 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Attribute.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set.php @@ -5,7 +5,7 @@ * @category Mage * @package Mage_Adminhtml * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) - * @copyright Copyright (c) 2022-2023 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2022-2024 The OpenMage Contributors (https://openmage.org) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -14,11 +14,6 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main_Tree_Attribute extends Mage_Adminhtml_Block_Template +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set extends Mage_Eav_Block_Adminhtml_Attribute_Set { - #[\Override] - protected function _construct() - { - $this->setTemplate('catalog/product/attribute/set/main/tree/attribute.phtml'); - } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Grid.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Grid.php index 154b7da50..d80d292a7 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Grid.php @@ -14,50 +14,6 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Grid extends Mage_Adminhtml_Block_Widget_Grid +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Grid extends Mage_Eav_Block_Adminhtml_Attribute_Set_Grid { - public function __construct() - { - parent::__construct(); - $this->setId('setGrid'); - $this->setDefaultSort('set_name'); - $this->setDefaultDir('ASC'); - $this->setSaveParametersInSession(true); - } - - #[\Override] - protected function _prepareCollection() - { - $collection = Mage::getResourceModel('eav/entity_attribute_set_collection') - ->setEntityTypeFilter(Mage::registry('entityType')); - - $this->setCollection($collection); - return parent::_prepareCollection(); - } - - /** - * @return $this - * @throws Exception - */ - #[\Override] - protected function _prepareColumns() - { - $this->addColumn('set_name', [ - 'header' => Mage::helper('catalog')->__('Set Name'), - 'align' => 'left', - 'index' => 'attribute_set_name', - ]); - - return $this; - } - - /** - * @param Varien_Object $row - * @return string - */ - #[\Override] - public function getRowUrl($row) - { - return $this->getUrl('*/*/edit', ['id' => $row->getAttributeSetId()]); - } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php index 5a700b3f5..8041e4d47 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php @@ -11,406 +11,33 @@ */ /** - * Adminhtml Catalog Attribute Set Main Block + * Adminhtml Catalog Product Attribute Set Edit Form * * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main extends Mage_Adminhtml_Block_Template +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main extends Mage_Eav_Block_Adminhtml_Attribute_Set_Edit { - /** - * Initialize template - */ - #[\Override] - protected function _construct() + public function __construct() { - $this->setTemplate('catalog/product/attribute/set/main.phtml'); + parent::__construct(); + $this->setTemplateIfExists('catalog/product/attribute/set/main.phtml'); } - /** - * Prepare Global Layout - * - * @return $this - */ #[\Override] - protected function _prepareLayout() - { - $setId = $this->_getSetId(); - - $this->setChild( - 'group_tree', - $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main_tree_group') - ); - - $this->setChild( - 'edit_set_form', - $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main_formset') - ); - - $this->setChild( - 'delete_group_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ - 'label' => Mage::helper('catalog')->__('Delete Selected Group'), - 'onclick' => 'editSet.submit();', - 'class' => 'delete' - ]) - ); - - $this->setChild( - 'add_group_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ - 'label' => Mage::helper('catalog')->__('Add New'), - 'onclick' => 'editSet.addGroup();', - 'class' => 'add' - ]) - ); - - $this->setChild( - 'back_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ - 'label' => Mage::helper('catalog')->__('Back'), - 'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/')), - 'class' => 'back' - ]) - ); - - $this->setChild( - 'reset_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ - 'label' => Mage::helper('catalog')->__('Reset'), - 'onclick' => 'window.location.reload()' - ]) - ); - - $this->setChild( - 'save_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ - 'label' => Mage::helper('catalog')->__('Save Attribute Set'), - 'onclick' => 'editSet.save();', - 'class' => 'save' - ]) - ); - - $this->setChild( - 'delete_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ - 'label' => Mage::helper('catalog')->__('Delete Attribute Set'), - 'onclick' => Mage::helper('core/js')->getDeleteConfirmJs( - $this->getUrlSecure('*/*/delete', ['id' => $setId]), - Mage::helper('catalog')->__('All products of this set will be deleted! Are you sure you want to delete this attribute set?') - ), - 'class' => 'delete' - ]) - ); - - $this->setChild( - 'rename_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ - 'label' => Mage::helper('catalog')->__('New Set Name'), - 'onclick' => 'editSet.rename()' - ]) - ); - - return parent::_prepareLayout(); - } - - /** - * Retrieve Attribute Set Group Tree HTML - * - * @return string - */ - public function getGroupTreeHtml() - { - return $this->getChildHtml('group_tree'); - } - - /** - * Retrieve Attribute Set Edit Form HTML - * - * @return string - */ - public function getSetFormHtml() - { - return $this->getChildHtml('edit_set_form'); - } - - /** - * Retrieve Block Header Text - * - * @return string - */ - protected function _getHeader() - { - return Mage::helper('catalog')->__("Edit Attribute Set '%s'", $this->_getAttributeSet()->getAttributeSetName()); - } - - /** - * Retrieve Attribute Set Save URL - * - * @return string - */ - public function getMoveUrl() - { - return $this->getUrl('*/catalog_product_set/save', ['id' => $this->_getSetId()]); - } - - /** - * Retrieve Attribute Set Group Save URL - * - * @return string - */ - public function getGroupUrl() - { - return $this->getUrl('*/catalog_product_group/save', ['id' => $this->_getSetId()]); - } - - /** - * Retrieve Attribute Set Group Tree as JSON format - * - * @return string - */ public function getGroupTreeJson() { - $items = []; - $setId = $this->_getSetId(); - - /** @var Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection $groups */ - $groups = Mage::getModel('eav/entity_attribute_group') - ->getResourceCollection() - ->setAttributeSetFilter($setId) - ->setSortOrder() - ->load(); - $configurable = Mage::getResourceModel('catalog/product_type_configurable_attribute') - ->getUsedAttributes($setId); - - /** @var Mage_Eav_Model_Entity_Attribute_Group $node */ - foreach ($groups as $node) { - $item = []; - $item['text'] = $node->getAttributeGroupName(); - $item['id'] = $node->getAttributeGroupId(); - $item['cls'] = 'folder'; - $item['allowDrop'] = true; - $item['allowDrag'] = true; - - $nodeChildren = Mage::getResourceModel('catalog/product_attribute_collection') - ->setAttributeGroupFilter($node->getId()) - ->addVisibleFilter() - ->checkConfigurableProducts() - ->load(); + ->getUsedAttributes($this->_getSetId()); - if ($nodeChildren->getSize() > 0) { - $item['children'] = []; - foreach ($nodeChildren->getItems() as $child) { - /** @var Mage_Eav_Model_Entity_Attribute $child */ - $attr = [ - 'text' => $child->getAttributeCode(), - 'id' => $child->getAttributeId(), - 'cls' => (!$child->getIsUserDefined()) ? 'system-leaf' : 'leaf', - 'allowDrop' => false, - 'allowDrag' => true, - 'leaf' => true, - 'is_user_defined' => $child->getIsUserDefined(), - 'is_configurable' => (int)in_array($child->getAttributeId(), $configurable), - 'entity_id' => $child->getEntityAttributeId() - ]; + $items = $this->getGroupTree(); - $item['children'][] = $attr; - } + foreach ($items as &$item) { + foreach ($item['children'] as &$child) { + $child['is_configurable'] = (int) in_array($child['id'], $configurable); } - - $items[] = $item; } return Mage::helper('core')->jsonEncode($items); } - - /** - * Retrieve Unused in Attribute Set Attribute Tree as JSON - * - * @return string - */ - public function getAttributeTreeJson() - { - $items = []; - $setId = $this->_getSetId(); - - $collection = Mage::getResourceModel('catalog/product_attribute_collection') - ->setAttributeSetFilter($setId) - ->load(); - - $attributesIds = ['0']; - /** @var Mage_Eav_Model_Entity_Attribute $item */ - foreach ($collection->getItems() as $item) { - $attributesIds[] = $item->getAttributeId(); - } - - $attributes = Mage::getResourceModel('catalog/product_attribute_collection') - ->setAttributesExcludeFilter($attributesIds) - ->addVisibleFilter() - ->setOrder('attribute_code', 'asc') - ->load(); - - foreach ($attributes as $child) { - $attr = [ - 'text' => $child->getAttributeCode(), - 'id' => $child->getAttributeId(), - 'cls' => 'leaf', - 'allowDrop' => false, - 'allowDrag' => true, - 'leaf' => true, - 'is_user_defined' => $child->getIsUserDefined(), - 'is_configurable' => false, - 'entity_id' => $child->getEntityId() - ]; - - $items[] = $attr; - } - - if (count($items) == 0) { - $items[] = [ - 'text' => Mage::helper('catalog')->__('Empty'), - 'id' => 'empty', - 'cls' => 'folder', - 'allowDrop' => false, - 'allowDrag' => false, - ]; - } - - return Mage::helper('core')->jsonEncode($items); - } - - /** - * Retrieve Back Button HTML - * - * @return string - */ - public function getBackButtonHtml() - { - return $this->getChildHtml('back_button'); - } - - /** - * Retrieve Reset Button HTML - * - * @return string - */ - public function getResetButtonHtml() - { - return $this->getChildHtml('reset_button'); - } - - /** - * Retrieve Save Button HTML - * - * @return string - */ - public function getSaveButtonHtml() - { - return $this->getChildHtml('save_button'); - } - - /** - * Retrieve Delete Button HTML - * - * @return string - */ - public function getDeleteButtonHtml() - { - if ($this->getIsCurrentSetDefault()) { - return ''; - } - return $this->getChildHtml('delete_button'); - } - - /** - * Retrieve Delete Group Button HTML - * - * @return string - */ - public function getDeleteGroupButton() - { - return $this->getChildHtml('delete_group_button'); - } - - /** - * Retrieve Add New Group Button HTML - * - * @return string - */ - public function getAddGroupButton() - { - return $this->getChildHtml('add_group_button'); - } - - /** - * Retrieve Rename Button HTML - * - * @return string - */ - public function getRenameButton() - { - return $this->getChildHtml('rename_button'); - } - - /** - * Retrieve current Attribute Set object - * - * @return Mage_Eav_Model_Entity_Attribute_Set - */ - protected function _getAttributeSet() - { - return Mage::registry('current_attribute_set'); - } - - /** - * Retrieve current attribute set Id - * - * @return int - */ - protected function _getSetId() - { - return $this->_getAttributeSet()->getId(); - } - - /** - * Check Current Attribute Set is a default - * - * @return bool - */ - public function getIsCurrentSetDefault() - { - $isDefault = $this->getData('is_current_set_default'); - if (is_null($isDefault)) { - $defaultSetId = Mage::getSingleton('eav/config') - ->getEntityType(Mage::registry('entityType')) - ->getDefaultAttributeSetId(); - $isDefault = $this->_getSetId() == $defaultSetId; - $this->setData('is_current_set_default', $isDefault); - } - return $isDefault; - } - - /** - * Retrieve current Attribute Set object - * - * @deprecated use _getAttributeSet - * @return Mage_Eav_Model_Entity_Attribute_Set - */ - protected function _getSetData() - { - return $this->_getAttributeSet(); - } - - /** - * Prepare HTML - * - * @return string - */ - #[\Override] - protected function _toHtml() - { - Mage::dispatchEvent('adminhtml_catalog_product_attribute_set_main_html_before', ['block' => $this]); - return parent::_toHtml(); - } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formattribute.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formattribute.php deleted file mode 100644 index 99611fbc2..000000000 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formattribute.php +++ /dev/null @@ -1,55 +0,0 @@ -addFieldset('set_fieldset', ['legend' => Mage::helper('catalog')->__('Add New Attribute')]); - - $fieldset->addField( - 'new_attribute', - 'text', - [ - 'label' => Mage::helper('catalog')->__('Name'), - 'name' => 'new_attribute', - 'required' => true, - ] - ); - - $fieldset->addField( - 'submit', - 'note', - [ - 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData([ - 'label' => Mage::helper('catalog')->__('Add Attribute'), - 'onclick' => 'this.form.submit();', - 'class' => 'add' - ]) - ->toHtml(), - ] - ); - - $form->setUseContainer(true); - $form->setMethod('post'); - $this->setForm($form); - return $this; - } -} diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formgroup.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formgroup.php deleted file mode 100644 index 0dc0a57f8..000000000 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formgroup.php +++ /dev/null @@ -1,73 +0,0 @@ -addFieldset('set_fieldset', ['legend' => Mage::helper('catalog')->__('Add New Group')]); - - $fieldset->addField( - 'attribute_group_name', - 'text', - [ - 'label' => Mage::helper('catalog')->__('Name'), - 'name' => 'attribute_group_name', - 'required' => true, - ] - ); - - $fieldset->addField( - 'submit', - 'note', - [ - 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData([ - 'label' => Mage::helper('catalog')->__('Add Group'), - 'onclick' => 'this.form.submit();', - 'class' => 'add' - ]) - ->toHtml(), - ] - ); - - $fieldset->addField( - 'attribute_set_id', - 'hidden', - [ - 'name' => 'attribute_set_id', - 'value' => $this->_getSetId(), - ] - ); - - $form->setUseContainer(true); - $form->setMethod('post'); - $form->setAction($this->getUrl('*/catalog_product_group/save')); - $this->setForm($form); - return $this; - } - - protected function _getSetId() - { - return ((int) $this->getRequest()->getParam('id') > 0) - ? (int) $this->getRequest()->getParam('id') - : Mage::getSingleton('eav/config')->getEntityType(Mage::registry('entityType')) - ->getDefaultAttributeSetId(); - } -} diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php index ffef858bb..ef0ad0a00 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formset.php @@ -14,57 +14,6 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main_Formset extends Mage_Adminhtml_Block_Widget_Form +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main_Formset extends Mage_Eav_Block_Adminhtml_Attribute_Set_Edit_Formset { - /** - * Prepares attribute set form - * - */ - #[\Override] - protected function _prepareForm() - { - $data = Mage::getModel('eav/entity_attribute_set') - ->load($this->getRequest()->getParam('id')); - - $form = new Varien_Data_Form(); - $fieldset = $form->addFieldset('set_name', ['legend' => Mage::helper('catalog')->__('Edit Set Name')]); - $fieldset->addField('attribute_set_name', 'text', [ - 'label' => Mage::helper('catalog')->__('Name'), - 'note' => Mage::helper('catalog')->__('For internal use.'), - 'name' => 'attribute_set_name', - 'required' => true, - 'class' => 'required-entry validate-no-html-tags', - 'value' => $data->getAttributeSetName() - ]); - - if (!$this->getRequest()->getParam('id', false)) { - $fieldset->addField('gotoEdit', 'hidden', [ - 'name' => 'gotoEdit', - 'value' => '1' - ]); - - $sets = Mage::getModel('eav/entity_attribute_set') - ->getResourceCollection() - ->setEntityTypeFilter(Mage::registry('entityType')) - ->setOrder('attribute_set_name', 'asc') - ->load() - ->toOptionArray(); - - $fieldset->addField('skeleton_set', 'select', [ - 'label' => Mage::helper('catalog')->__('Based On'), - 'name' => 'skeleton_set', - 'required' => true, - 'class' => 'required-entry', - 'values' => $sets, - ]); - } - - $form->setMethod('post'); - $form->setUseContainer(true); - $form->setId('set_prop_form'); - $form->setAction($this->getUrl('*/*/save')); - $form->setOnsubmit('return false;'); - $this->setForm($form); - return $this; - } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Group.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Group.php index 10aedba5f..cedc52985 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Group.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Tree/Group.php @@ -14,11 +14,11 @@ * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main_Tree_Group extends Mage_Adminhtml_Block_Template +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main_Tree_Group extends Mage_Eav_Block_Adminhtml_Attribute_Set_Edit_Tree_Group { - #[\Override] - protected function _construct() + public function __construct() { - $this->setTemplate('catalog/product/attribute/set/main/tree/group.phtml'); + parent::__construct(); + $this->setTemplateIfExists('catalog/product/attribute/set/main/tree/group.phtml'); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Add.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Add.php index baca073d8..68c660831 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Add.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Add.php @@ -11,80 +11,16 @@ */ /** + * Adminhtml "Add New Product Attribute Set" + * * @category Mage * @package Mage_Adminhtml */ -class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Toolbar_Add extends Mage_Adminhtml_Block_Template +class Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Toolbar_Add extends Mage_Eav_Block_Adminhtml_Attribute_Set_Add { - #[\Override] - protected function _construct() - { - $this->setTemplate('catalog/product/attribute/set/toolbar/add.phtml'); - } - - #[\Override] - protected function _prepareLayout() - { - $this->setChild( - 'save_button', - $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData([ - 'label' => Mage::helper('catalog')->__('Save Attribute Set'), - 'onclick' => 'if (addSet.submit()) disableElements(\'save\');', - 'class' => 'save' - ]) - ); - $this->setChild( - 'back_button', - $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData([ - 'label' => Mage::helper('catalog')->__('Back'), - 'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/')), - 'class' => 'back' - ]) - ); - - $this->setChild( - 'setForm', - $this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main_formset') - ); - return parent::_prepareLayout(); - } - - /** - * @return string - */ - protected function _getHeader() - { - return Mage::helper('catalog')->__('Add New Attribute Set'); - } - - /** - * @return string - */ - protected function getSaveButtonHtml() - { - return $this->getChildHtml('save_button'); - } - - /** - * @return string - */ - protected function getBackButtonHtml() - { - return $this->getChildHtml('back_button'); - } - - /** - * @return string - */ - protected function getFormHtml() - { - return $this->getChildHtml('setForm'); - } - - protected function getFormId() + public function __construct() { - return $this->getChild('setForm')->getForm()->getId(); + parent::__construct(); + $this->setTemplateIfExists('catalog/product/attribute/set/toolbar/add.phtml'); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main.php index 15ebe8236..d475ff66b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main.php @@ -11,7 +11,7 @@ */ /** - * Adminhtml catalog product sets main page toolbar + * Adminhtml "Manage Product Attribute Sets" grid toolbar * * @category Mage * @package Mage_Adminhtml @@ -31,7 +31,7 @@ protected function _prepareLayout() 'addButton', $this->getLayout()->createBlock('adminhtml/widget_button') ->setData([ - 'label' => Mage::helper('catalog')->__('Add New Set'), + 'label' => Mage::helper('eav')->__('Add New Set'), 'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/add')), 'class' => 'add', ]) @@ -52,7 +52,7 @@ protected function getNewButtonHtml() */ protected function _getHeader() { - return Mage::helper('catalog')->__('Manage Attribute Sets'); + return Mage::helper('eav')->__('Manage Product Attribute Sets'); } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main/Filter.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main/Filter.php deleted file mode 100644 index 7fba13776..000000000 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main/Filter.php +++ /dev/null @@ -1,47 +0,0 @@ -getResourceCollection() - ->load() - ->toOptionArray(); - - $form->addField( - 'set_switcher', - 'select', - [ - 'name' => 'set_switcher', - 'required' => true, - 'class' => 'left-col-block', - 'no_span' => true, - 'values' => $collection, - 'onchange' => 'this.form.submit()', - ] - ); - - $form->setUseContainer(true); - $form->setMethod('post'); - $this->setForm($form); - return $this; - } -} diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php index 33b3bebd9..a0e9eccaf 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php @@ -38,6 +38,11 @@ protected function _prepareLayout() } if ($setId) { + $storeId = 0; + if ($this->getRequest()->getParam('store')) { + $storeId = Mage::app()->getStore($this->getRequest()->getParam('store'))->getId(); + } + $groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection') ->setAttributeSetFilter($setId) ->setSortOrder() @@ -48,6 +53,7 @@ protected function _prepareLayout() // do not add groups without attributes foreach ($attributes as $key => $attribute) { + $attribute->setStoreId($storeId); if (!$attribute->getIsVisible()) { unset($attributes[$key]); } @@ -111,11 +117,6 @@ protected function _prepareLayout() 'class' => 'ajax', ]); - $storeId = 0; - if ($this->getRequest()->getParam('store')) { - $storeId = Mage::app()->getStore($this->getRequest()->getParam('store'))->getId(); - } - $alertPriceAllow = Mage::getStoreConfig('catalog/productalert/allow_price'); $alertStockAllow = Mage::getStoreConfig('catalog/productalert/allow_stock'); diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php index 94eb5ac5d..76477f193 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php @@ -101,46 +101,6 @@ function(v, elem){ $customerStoreId = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId(); } - $prefixElement = $form->getElement('prefix'); - if ($prefixElement) { - /** @var Mage_Customer_Helper_Data $helper */ - $helper = $this->helper('customer'); - $prefixOptions = $helper->getNamePrefixOptions($customerStoreId); - if (!empty($prefixOptions)) { - $fieldset->removeField($prefixElement->getId()); - $prefixField = $fieldset->addField( - $prefixElement->getId(), - 'select', - $prefixElement->getData(), - $form->getElement('group_id')->getId() - ); - $prefixField->setValues($prefixOptions); - if ($customer->getId()) { - $prefixField->addElementValues($customer->getPrefix()); - } - } - } - - $suffixElement = $form->getElement('suffix'); - if ($suffixElement) { - /** @var Mage_Customer_Helper_Data $helper */ - $helper = $this->helper('customer'); - $suffixOptions = $helper->getNameSuffixOptions($customerStoreId); - if (!empty($suffixOptions)) { - $fieldset->removeField($suffixElement->getId()); - $suffixField = $fieldset->addField( - $suffixElement->getId(), - 'select', - $suffixElement->getData(), - $form->getElement('lastname')->getId() - ); - $suffixField->setValues($suffixOptions); - if ($customer->getId()) { - $suffixField->addElementValues($customer->getSuffix()); - } - } - } - $minPasswordLength = Mage::getModel('customer/customer')->getMinPasswordLength(); if ($customer->getId()) { if (!$customer->isReadonly()) { diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php index d7ecc817e..4a6b24079 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Addresses.php @@ -114,6 +114,7 @@ public function initForm() $addressModel = Mage::getModel('customer/address'); $addressModel->setCountryId(Mage::helper('core')->getDefaultCountry($customer->getStore())); + $addressModel->setCustomer($customer); /** @var Mage_Customer_Model_Form $addressForm */ $addressForm = Mage::getModel('customer/form'); $addressForm->setFormCode('adminhtml_customer_address') @@ -164,40 +165,6 @@ public function initForm() $customerStoreId = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId(); } - $prefixElement = $form->getElement('prefix'); - if ($prefixElement) { - /** @var Mage_Customer_Helper_Data $helper */ - $helper = $this->helper('customer'); - $prefixOptions = $helper->getNamePrefixOptions($customerStoreId); - if (!empty($prefixOptions)) { - $fieldset->removeField($prefixElement->getId()); - $prefixField = $fieldset->addField( - $prefixElement->getId(), - 'select', - $prefixElement->getData(), - '^' - ); - $prefixField->setValues($prefixOptions); - } - } - - $suffixElement = $form->getElement('suffix'); - if ($suffixElement) { - /** @var Mage_Customer_Helper_Data $helper */ - $helper = $this->helper('customer'); - $suffixOptions = $helper->getNameSuffixOptions($customerStoreId); - if (!empty($suffixOptions)) { - $fieldset->removeField($suffixElement->getId()); - $suffixField = $fieldset->addField( - $suffixElement->getId(), - 'select', - $suffixElement->getData(), - $form->getElement('lastname')->getId() - ); - $suffixField->setValues($suffixOptions); - } - } - $addressCollection = $customer->getAddresses(); $this->assign('customer', $customer); $this->assign('addressCollection', $addressCollection); @@ -270,12 +237,10 @@ public function getDefaultCountriesJson() * * @param string|int|array $values * @return $this + * @deprecated */ public function addValuesToNamePrefixElement($values) { - if ($this->getForm() && $this->getForm()->getElement('prefix')) { - $this->getForm()->getElement('prefix')->addElementValues($values); - } return $this; } @@ -284,12 +249,10 @@ public function addValuesToNamePrefixElement($values) * * @param string|int|array $values * @return $this + * @deprecated */ public function addValuesToNameSuffixElement($values) { - if ($this->getForm() && $this->getForm()->getElement('suffix')) { - $this->getForm()->getElement('suffix')->addElementValues($values); - } return $this; } } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php index bd2909e5c..fafbe89db 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit.php @@ -28,7 +28,7 @@ public function __construct() $this->_updateButton('save', 'label', Mage::helper('customer')->__('Save Customer Group')); $this->_updateButton('delete', 'label', Mage::helper('customer')->__('Delete Customer Group')); - if (!Mage::registry('current_group')->getId() || Mage::registry('current_group')->usesAsDefault()) { + if (is_null(Mage::registry('current_group')->getId()) || Mage::registry('current_group')->usesAsDefault()) { $this->_removeButton('delete'); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php index 33734af95..31e02099b 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php @@ -34,46 +34,64 @@ protected function _prepareLayout() 'required-entry validate-length maximum-length-%d', Mage_Customer_Model_Group::GROUP_CODE_MAX_LENGTH ); - $name = $fieldset->addField( - 'customer_group_code', - 'text', - [ - 'name' => 'code', - 'label' => Mage::helper('customer')->__('Group Name'), - 'title' => Mage::helper('customer')->__('Group Name'), - 'note' => Mage::helper('customer')->__('Maximum length must be less then %s symbols', Mage_Customer_Model_Group::GROUP_CODE_MAX_LENGTH), - 'class' => $validateClass, - 'required' => true, - ] - ); + $name = $fieldset->addField('customer_group_code', 'text', [ + 'name' => 'code', + 'label' => Mage::helper('customer')->__('Group Name'), + 'title' => Mage::helper('customer')->__('Group Name'), + 'note' => Mage::helper('customer')->__('Maximum length must be less then %s symbols', Mage_Customer_Model_Group::GROUP_CODE_MAX_LENGTH), + 'class' => $validateClass, + 'required' => true, + ]); - if ($customerGroup->getId() == 0 && $customerGroup->getCustomerGroupCode()) { + if ($customerGroup->getId() == Mage_Customer_Model_Group::NOT_LOGGED_IN_ID && $customerGroup->getCustomerGroupCode()) { $name->setDisabled(true); } - $fieldset->addField( - 'tax_class_id', - 'select', - [ - 'name' => 'tax_class', - 'label' => Mage::helper('customer')->__('Tax Class'), - 'title' => Mage::helper('customer')->__('Tax Class'), - 'class' => 'required-entry', - 'required' => true, - 'values' => Mage::getSingleton('tax/class_source_customer')->toOptionArray() - ] - ); + $fieldset->addField('tax_class_id', 'select', [ + 'name' => 'tax_class', + 'label' => Mage::helper('customer')->__('Tax Class'), + 'title' => Mage::helper('customer')->__('Tax Class'), + 'class' => 'required-entry', + 'required' => true, + 'values' => Mage::getSingleton('tax/class_source_customer')->toOptionArray() + ]); + + $setsCustomer = Mage::getResourceModel('eav/entity_attribute_set_collection') + ->setEntityTypeFilter(Mage::getResourceModel('customer/customer')->getEntityType()->getId()) + ->setOrder('attribute_set_name', 'asc') + ->load() + ->toOptionArray(); + + $fieldset->addField('customer_attribute_set_id', 'select', [ + 'name' => 'customer_attribute_set', + 'label' => Mage::helper('customer')->__('Customer Attribute Set'), + 'title' => Mage::helper('customer')->__('Customer Attribute Set'), + 'class' => 'required-entry', + 'required' => true, + 'values' => $setsCustomer + ]); + + $setsAddress = Mage::getResourceModel('eav/entity_attribute_set_collection') + ->setEntityTypeFilter(Mage::getResourceModel('customer/address')->getEntityType()->getId()) + ->setOrder('attribute_set_name', 'asc') + ->load() + ->toOptionArray(); + + $fieldset->addField('customer_address_attribute_set_id', 'select', [ + 'name' => 'customer_address_attribute_set', + 'label' => Mage::helper('customer')->__('Customer Address Attribute Set'), + 'title' => Mage::helper('customer')->__('Customer Address Attribute Set'), + 'class' => 'required-entry', + 'required' => true, + 'values' => $setsAddress + ]); if (!is_null($customerGroup->getId())) { // If edit add id - $form->addField( - 'id', - 'hidden', - [ - 'name' => 'id', - 'value' => $customerGroup->getId(), - ] - ); + $form->addField('id', 'hidden', [ + 'name' => 'id', + 'value' => $customerGroup->getId(), + ]); } if (Mage::getSingleton('adminhtml/session')->getCustomerGroupData()) { diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Abstract.php index 31c89b74b..26730b700 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Abstract.php @@ -145,7 +145,7 @@ protected function _addAttributesToForm($attributes, Varien_Data_Form_Abstract $ $element->setRenderer($renderers[$attribute->getAttributeCode()]); } - if ($inputType == 'select' || $inputType == 'multiselect') { + if (in_array($inputType, ['select', 'multiselect', 'customselect'])) { $element->setValues($attribute->getFrontend()->getSelectOptions()); } elseif ($inputType == 'date') { $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php index 724d032fa..932fc77e1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Form/Address.php @@ -110,46 +110,6 @@ protected function _prepareForm() } $this->_addAttributesToForm($attributes, $fieldset); - $prefixElement = $this->_form->getElement('prefix'); - if ($prefixElement) { - /** @var Mage_Customer_Helper_Data $helper */ - $helper = $this->helper('customer'); - $prefixOptions = $helper->getNamePrefixOptions($this->getStore()); - if (!empty($prefixOptions)) { - $fieldset->removeField($prefixElement->getId()); - $prefixField = $fieldset->addField( - $prefixElement->getId(), - 'select', - $prefixElement->getData(), - '^' - ); - $prefixField->setValues($prefixOptions); - if ($this->getAddressId()) { - $prefixField->addElementValues($this->getAddress()->getPrefix()); - } - } - } - - $suffixElement = $this->_form->getElement('suffix'); - if ($suffixElement) { - /** @var Mage_Customer_Helper_Data $helper */ - $helper = $this->helper('customer'); - $suffixOptions = $helper->getNameSuffixOptions($this->getStore()); - if (!empty($suffixOptions)) { - $fieldset->removeField($suffixElement->getId()); - $suffixField = $fieldset->addField( - $suffixElement->getId(), - 'select', - $suffixElement->getData(), - $this->_form->getElement('lastname')->getId() - ); - $suffixField->setValues($suffixOptions); - if ($this->getAddressId()) { - $suffixField->addElementValues($this->getAddress()->getSuffix()); - } - } - } - $regionElement = $this->_form->getElement('region_id'); if ($regionElement) { $regionElement->setNoDisplay(true); diff --git a/app/code/core/Mage/Adminhtml/Block/Website/Switcher.php b/app/code/core/Mage/Adminhtml/Block/Website/Switcher.php new file mode 100644 index 000000000..96bb2a71b --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Block/Website/Switcher.php @@ -0,0 +1,141 @@ +setTemplate('website/switcher.phtml'); + $this->setUseConfirm(true); + $this->setUseAjax(true); + $this->setLabel($this->__('Choose Website:')); + $this->setDefaultWebsiteName($this->__('All Websites')); + } + + /** + * @return Mage_Core_Model_Resource_Website_Collection + * @throws Mage_Core_Exception + * @deprecated + */ + public function getWebsiteCollection() + { + $collection = Mage::getModel('core/website')->getResourceCollection(); + + $websiteIds = $this->getWebsiteIds(); + if (!is_null($websiteIds)) { + $collection->addIdFilter($this->getWebsiteIds()); + } + + return $collection->load(); + } + + /** + * Get websites + * + * @return array + */ + public function getWebsites() + { + $websites = Mage::app()->getWebsites(); + if ($websiteIds = $this->getWebsiteIds()) { + foreach (array_keys($websites) as $websiteId) { + if (!in_array($websiteId, $websiteIds)) { + unset($websites[$websiteId]); + } + } + } + return $websites; + } + + /** + * @return string + */ + public function getSwitchUrl() + { + if ($url = $this->getData('switch_url')) { + return $url; + } + return $this->getUrl('*/*/*', ['_current' => true, $this->_websiteVarName => null]); + } + + /** + * @param string $varName + * @return $this + */ + public function setWebsiteVarName($varName) + { + $this->_websiteVarName = $varName; + return $this; + } + + /** + * @return mixed + * @throws Exception + */ + public function getWebsiteId() + { + return $this->getRequest()->getParam($this->_websiteVarName); + } + + /** + * @return bool + */ + public function isShow() + { + return !Mage::app()->isSingleStoreMode(); + } + + /** + * @return string + */ + #[\Override] + protected function _toHtml() + { + if (!Mage::app()->isSingleStoreMode()) { + return parent::_toHtml(); + } + return ''; + } + + /** + * Set/Get whether the switcher should show default option + * + * @param bool $hasDefaultOption + * @return bool + */ + public function hasDefaultOption($hasDefaultOption = null) + { + if ($hasDefaultOption !== null) { + $this->_hasDefaultOption = $hasDefaultOption; + } + return $this->_hasDefaultOption; + } +} diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Form.php b/app/code/core/Mage/Adminhtml/Block/Widget/Form.php index f64fe630e..55236a015 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Form.php @@ -191,10 +191,10 @@ protected function _setFieldset($attributes, $fieldset, $exclude = []) $element->setAfterElementHtml($this->_getAdditionalElementHtml($element)); - if ($inputType == 'select') { - $element->setValues($attribute->getSource()->getAllOptions(true, true)); + if ($inputType == 'select' || $inputType == 'customselect') { + $element->setValues($attribute->getSource()->getAllOptions(true, false)); } elseif ($inputType == 'multiselect') { - $element->setValues($attribute->getSource()->getAllOptions(false, true)); + $element->setValues($attribute->getSource()->getAllOptions(false, false)); $element->setCanBeEmpty(true); } elseif ($inputType == 'date') { $element->setFormat(Mage::app()->getLocale()->getDateFormatWithLongYear()); diff --git a/app/code/core/Mage/Adminhtml/Model/Observer/Eav/Customer.php b/app/code/core/Mage/Adminhtml/Model/Observer/Eav/Customer.php new file mode 100644 index 000000000..7a30ebb23 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/Observer/Eav/Customer.php @@ -0,0 +1,60 @@ +getAttribute(); + $attributeTypeCode = $attribute->getEntityType()->getEntityTypeCode(); + + /** @var Varien_Data_Form $form */ + $form = $observer->getForm(); + + /** @var Varien_Data_Form_Element_Fieldset $fieldset */ + $fieldset = $form->getElement('base_fieldset'); + + $fieldset->addField('is_visible', 'boolean', [ + 'name' => 'is_visible', + 'label' => Mage::helper('adminhtml')->__('Is Visible'), + 'title' => Mage::helper('adminhtml')->__('Is Visible'), + ], 'frontend_class'); + + $fieldset->addField('multiline_count', 'number', [ + 'name' => 'multiline_count', + 'label' => Mage::helper('eav')->__('Multiline Count'), + 'title' => Mage::helper('eav')->__('Multiline Count'), + 'value' => 1, + 'min' => 1, + ], 'frontend_input'); + + if ($attribute->getAttributeCode() === 'street') { + $form->getElement('multiline_count') + ->setMin(Mage_Customer_Helper_Address::STREET_LINES_MIN) + ->setMax(Mage_Customer_Helper_Address::STREET_LINES_MAX); + } + + /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $dependenceBlock */ + $dependenceBlock = $observer->getDependence(); + + $dependenceBlock->addFieldMap('frontend_input', 'frontend_input') + ->addFieldMap('multiline_count', 'multiline_count') + ->addFieldDependence('multiline_count', 'frontend_input', 'multiline'); + + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/Model/Observer/Eav/Product.php b/app/code/core/Mage/Adminhtml/Model/Observer/Eav/Product.php new file mode 100644 index 000000000..ecd79f6a1 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/Observer/Eav/Product.php @@ -0,0 +1,26 @@ +getEntityType(Mage_Catalog_Model_Product::ENTITY)); + } + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Address/Street.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Address/Street.php deleted file mode 100644 index 176e602db..000000000 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Address/Street.php +++ /dev/null @@ -1,70 +0,0 @@ -getAttribute('customer_address', 'street'); - $value = $this->getValue(); - switch ($this->getScope()) { - case 'websites': - $website = Mage::app()->getWebsite($this->getWebsiteCode()); - $attribute->setWebsite($website); - $attribute->load($attribute->getId()); - if ($attribute->getData('multiline_count') != $value) { - $attribute->setData('scope_multiline_count', $value); - } - break; - - case 'default': - $attribute->setData('multiline_count', $value); - break; - } - $attribute->save(); - return $this; - } - - /** - * Processing object after delete data - * - * @return Mage_Core_Model_Abstract - */ - #[\Override] - protected function _afterDelete() - { - $result = parent::_afterDelete(); - - if ($this->getScope() == 'websites') { - $attribute = Mage::getSingleton('eav/config')->getAttribute('customer_address', 'street'); - $website = Mage::app()->getWebsite($this->getWebsiteCode()); - $attribute->setWebsite($website); - $attribute->load($attribute->getId()); - $attribute->setData('scope_multiline_count', null); - $attribute->save(); - } - - return $result; - } -} diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Address.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Address.php deleted file mode 100644 index 8bebf9a26..000000000 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Address.php +++ /dev/null @@ -1,33 +0,0 @@ -getAttribute('customer_address', $this->_getAttributeCode()); - return $result; - } -} diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Customer.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Customer.php deleted file mode 100644 index 2fd071cab..000000000 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Customer/Show/Customer.php +++ /dev/null @@ -1,109 +0,0 @@ -getField()); - } - - /** - * Retrieve attribute objects - * - * @return array - */ - protected function _getAttributeObjects() - { - return [ - Mage::getSingleton('eav/config')->getAttribute('customer', $this->_getAttributeCode()) - ]; - } - - /** - * Actions after save - * - * @return $this - */ - #[\Override] - protected function _afterSave() - { - $result = parent::_afterSave(); - - $valueConfig = [ - '' => ['is_required' => 0, 'is_visible' => 0], - 'opt' => ['is_required' => 0, 'is_visible' => 1], - '1' => ['is_required' => 0, 'is_visible' => 1], - 'req' => ['is_required' => 1, 'is_visible' => 1], - ]; - - $value = $this->getValue(); - $data = $valueConfig[$value] ?? $valueConfig['']; - - if ($this->getScope() == 'websites') { - $website = Mage::app()->getWebsite($this->getWebsiteCode()); - $dataFieldPrefix = 'scope_'; - } else { - $website = null; - $dataFieldPrefix = ''; - } - - foreach ($this->_getAttributeObjects() as $attributeObject) { - if ($website) { - $attributeObject->setWebsite($website); - $attributeObject->load($attributeObject->getId()); - } - $attributeObject->setData($dataFieldPrefix . 'is_required', $data['is_required']); - $attributeObject->setData($dataFieldPrefix . 'is_visible', $data['is_visible']); - $attributeObject->save(); - } - - return $result; - } - - /** - * Processing object after delete data - * - * @return Mage_Core_Model_Abstract - */ - #[\Override] - protected function _afterDelete() - { - $result = parent::_afterDelete(); - - if ($this->getScope() == 'websites') { - $website = Mage::app()->getWebsite($this->getWebsiteCode()); - foreach ($this->_getAttributeObjects() as $attributeObject) { - $attributeObject->setWebsite($website); - $attributeObject->load($attributeObject->getId()); - $attributeObject->setData('scope_is_required', null); - $attributeObject->setData('scope_is_visible', null); - $attributeObject->save(); - } - } - - return $result; - } -} diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php new file mode 100644 index 000000000..a0f8276ed --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php @@ -0,0 +1,49 @@ +entityTypeCode = Mage_Catalog_Model_Category::ENTITY; + } + + #[\Override] + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Catalog')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Category Attributes')); + + $this->_setActiveMenu('catalog/attributes/category_attributes') + ->_addBreadcrumb( + $this->__('Catalog'), + $this->__('Catalog') + ) + ->_addBreadcrumb( + $this->__('Manage Category Attributes'), + $this->__('Manage Category Attributes') + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php new file mode 100644 index 000000000..c761e58b7 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php @@ -0,0 +1,49 @@ +entityTypeCode = Mage_Catalog_Model_Category::ENTITY; + } + + #[\Override] + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Catalog')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Category Attribute Sets')); + + $this->_setActiveMenu('catalog/attributes/category_sets') + ->_addBreadcrumb( + $this->__('Catalog'), + $this->__('Catalog') + ) + ->_addBreadcrumb( + $this->__('Manage Category Attribute Sets'), + $this->__('Manage Category Attribute Sets') + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php index 1a187dc19..7ebef879f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php @@ -12,14 +12,9 @@ /** * Catalog product attribute controller - * - * @category Mage - * @package Mage_Adminhtml */ -class Mage_Adminhtml_Catalog_Product_AttributeController extends Mage_Adminhtml_Controller_Action +class Mage_Adminhtml_Catalog_Product_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { - protected $_entityTypeId; - /** * ACL resource * @see Mage_Adminhtml_Controller_Action::_isAllowed() @@ -27,29 +22,17 @@ class Mage_Adminhtml_Catalog_Product_AttributeController extends Mage_Adminhtml_ public const ADMIN_RESOURCE = 'catalog/attributes/attributes'; /** - * List of tags from setting - */ - public const XML_PATH_ALLOWED_TAGS = 'system/catalog/frontend/allowed_html_tags_list'; - - /** - * Get list of allowed text formatted as array - * - * @return array + * List of tags from setting */ - protected function _getAllowedTags() - { - return explode(',', Mage::getStoreConfig(self::XML_PATH_ALLOWED_TAGS)); - } + public const XML_PATH_ALLOWED_TAGS = 'system/catalog/frontend/allowed_html_tags_list'; #[\Override] - public function preDispatch() + protected function _construct() { - $this->_setForcedFormKeyActions('delete'); - parent::preDispatch(); - $this->_entityTypeId = Mage::getModel('eav/entity')->setType(Mage_Catalog_Model_Product::ENTITY)->getTypeId(); - return $this; + $this->entityTypeCode = Mage_Catalog_Model_Product::ENTITY; } + #[\Override] protected function _initAction() { $this->_title($this->__('Catalog')) @@ -60,206 +43,30 @@ protected function _initAction() $this->loadLayout('popup'); } else { $this->loadLayout() - ->_setActiveMenu('catalog/attributes/attributes') - ->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog')) - ->_addBreadcrumb( - Mage::helper('catalog')->__('Manage Product Attributes'), - Mage::helper('catalog')->__('Manage Product Attributes') - ) - ; + ->_setActiveMenu('catalog/attributes/attributes') + ->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog')) + ->_addBreadcrumb( + Mage::helper('catalog')->__('Manage Product Attributes'), + Mage::helper('catalog')->__('Manage Product Attributes') + ); } return $this; } - public function indexAction() - { - $this->_initAction() - ->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute')) - ->renderLayout(); - } - - public function newAction() - { - $this->_forward('edit'); - } - - public function editAction() - { - $id = $this->getRequest()->getParam('attribute_id'); - $model = Mage::getModel('catalog/resource_eav_attribute') - ->setEntityTypeId($this->_entityTypeId); - if ($id) { - $model->load($id); - - if (!$model->getId()) { - Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('catalog')->__('This attribute no longer exists') - ); - $this->_redirect('*/*/'); - return; - } - - // entity type check - if ($model->getEntityTypeId() != $this->_entityTypeId) { - Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('catalog')->__('This attribute cannot be edited.') - ); - $this->_redirect('*/*/'); - return; - } - } - - // set entered data if was error when we do save - $data = Mage::getSingleton('adminhtml/session')->getAttributeData(true); - if (!empty($data)) { - $model->addData($data); - } - - Mage::register('entity_attribute', $model); - - $this->_initAction(); - - $this->_title($id ? $model->getName() : $this->__('New Attribute')); - - $item = $id ? Mage::helper('catalog')->__('Edit Product Attribute') - : Mage::helper('catalog')->__('New Product Attribute'); - - $this->_addBreadcrumb($item, $item); - - $this->getLayout()->getBlock('attribute_edit_js') - ->setIsPopup((bool)$this->getRequest()->getParam('popup')); - - $this->renderLayout(); - } - - public function validateAction() - { - $response = new Varien_Object(); - $response->setError(false); - - $attributeCode = $this->getRequest()->getParam('attribute_code'); - $attributeId = $this->getRequest()->getParam('attribute_id'); - $attribute = Mage::getModel('catalog/resource_eav_attribute') - ->loadByCode($this->_entityTypeId, $attributeCode); - - if ($attribute->getId() && !$attributeId) { - Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('catalog')->__('Attribute with the same code already exists') - ); - $this->_initLayoutMessages('adminhtml/session'); - $response->setError(true); - $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); - } - - $this->getResponse()->setBody($response->toJson()); - } - /** - * Filter post data + * Get list of allowed text formatted as array * - * @param array $data * @return array */ - protected function _filterPostData($data) + protected function _getAllowedTags() { - if ($data) { - /** @var Mage_Catalog_Helper_Data $helperCatalog */ - $helperCatalog = Mage::helper('catalog'); - //labels - $data['frontend_label'] = (array) $data['frontend_label']; - foreach ($data['frontend_label'] as & $value) { - if ($value) { - $value = $helperCatalog->stripTags($value); - } - } - - if (!empty($data['option']) && !empty($data['option']['value']) && is_array($data['option']['value'])) { - $allowableTags = isset($data['is_html_allowed_on_front']) && $data['is_html_allowed_on_front'] - ? sprintf('<%s>', implode('><', $this->_getAllowedTags())) : null; - foreach ($data['option']['value'] as $key => $values) { - foreach ($values as $storeId => $storeLabel) { - $data['option']['value'][$key][$storeId] - = $helperCatalog->stripTags($storeLabel, $allowableTags); - } - } - } - } - return $data; + return explode(',', Mage::getStoreConfig(self::XML_PATH_ALLOWED_TAGS)); } - public function saveAction() + #[\Override] + protected function _filterPostData($data) { - $data = $this->getRequest()->getPost(); if ($data) { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('adminhtml/session'); - - $redirectBack = $this->getRequest()->getParam('back', false); - /** @var Mage_Catalog_Model_Entity_Attribute $model */ - $model = Mage::getModel('catalog/resource_eav_attribute'); - /** @var Mage_Catalog_Helper_Product $helper */ - $helper = Mage::helper('catalog/product'); - - $id = $this->getRequest()->getParam('attribute_id'); - - //validate attribute_code - if (isset($data['attribute_code'])) { - $validatorAttrCode = new Zend_Validate_Regex(['pattern' => '/^(?!event$)[a-z][a-z_0-9]{1,254}$/']); - if (!$validatorAttrCode->isValid($data['attribute_code'])) { - $session->addError( - Mage::helper('catalog')->__('Attribute code is invalid. Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter. Do not use "event" for an attribute code.') - ); - $this->_redirect('*/*/edit', ['attribute_id' => $id, '_current' => true]); - return; - } - } - - //validate frontend_input - if (isset($data['frontend_input'])) { - /** @var Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype_Validator $validatorInputType */ - $validatorInputType = Mage::getModel('eav/adminhtml_system_config_source_inputtype_validator'); - if (!$validatorInputType->isValid($data['frontend_input'])) { - foreach ($validatorInputType->getMessages() as $message) { - $session->addError($message); - } - $this->_redirect('*/*/edit', ['attribute_id' => $id, '_current' => true]); - return; - } - } - - if ($id) { - $model->load($id); - - if (!$model->getId()) { - $session->addError( - Mage::helper('catalog')->__('This Attribute no longer exists') - ); - $this->_redirect('*/*/'); - return; - } - - // entity type check - if ($model->getEntityTypeId() != $this->_entityTypeId) { - $session->addError( - Mage::helper('catalog')->__('This attribute cannot be updated.') - ); - $session->setAttributeData($data); - $this->_redirect('*/*/'); - return; - } - - $data['backend_model'] = $model->getBackendModel(); - $data['attribute_code'] = $model->getAttributeCode(); - $data['is_user_defined'] = $model->getIsUserDefined(); - $data['frontend_input'] = $model->getFrontendInput(); - } else { - /** - * @todo add to helper and specify all relations for properties - */ - $data['source_model'] = $helper->getAttributeSourceModelByInputType($data['frontend_input']); - $data['backend_model'] = $helper->getAttributeBackendModelByInputType($data['frontend_input']); - } - if (!isset($data['is_configurable'])) { $data['is_configurable'] = 0; } @@ -269,104 +76,38 @@ public function saveAction() if (!isset($data['is_filterable_in_search'])) { $data['is_filterable_in_search'] = 0; } - - if (!$model->getBackendType() && (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0)) { - $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']); - } - - $defaultValueField = $model->getDefaultValueByInput($data['frontend_input']); - if ($defaultValueField) { - $data['default_value'] = $this->getRequest()->getParam($defaultValueField); - } - if (!isset($data['apply_to'])) { $data['apply_to'] = []; } - - if ($model) { - $data['entity_type_id'] = $model->getEntityTypeId(); - } - - //filter - $data = $this->_filterPostData($data); - $model->addData($data); - - if (!$id) { - $data['entity_type_id'] = $this->_entityTypeId; - $model->setEntityTypeId($this->_entityTypeId); - $model->setIsUserDefined(1); - } - - if ($this->getRequest()->getParam('set') && $this->getRequest()->getParam('group')) { - // For creating product attribute on product page we need specify attribute set and group - $model->setAttributeSetId($this->getRequest()->getParam('set')); - $model->setAttributeGroupId($this->getRequest()->getParam('group')); + $data['frontend_label'] = (array) $data['frontend_label']; + foreach ($data['frontend_label'] as & $value) { + if ($value) { + $value = Mage::helper('catalog')->stripTags($value); + } } - - try { - $model->save(); - $session->addSuccess( - Mage::helper('catalog')->__('The product attribute has been saved.') - ); - - /** - * Clear translation cache because attribute labels are stored in translation - */ - Mage::app()->cleanCache([Mage_Core_Model_Translate::CACHE_TAG]); - $session->setAttributeData(false); - if ($this->getRequest()->getParam('popup')) { - $this->_redirect('adminhtml/catalog_product/addAttribute', [ - 'id' => $this->getRequest()->getParam('product'), - 'attribute' => $model->getId(), - '_current' => true - ]); - } elseif ($redirectBack) { - $this->_redirect('*/*/edit', ['attribute_id' => $model->getId(),'_current' => true]); - } else { - $this->_redirect('*/*/', []); + if (!empty($data['option']) && !empty($data['option']['value']) && is_array($data['option']['value'])) { + $allowedTags = !empty($data['is_html_allowed_on_front']) ? $this->_getAllowedTags() : []; + foreach ($data['option']['value'] as $key => $values) { + foreach ($values as $storeId => $storeLabel) { + $data['option']['value'][$key][$storeId] = Mage::helper('catalog')->stripTags($storeLabel, $allowedTags); + } } - return; - } catch (Exception $e) { - $session->addError($e->getMessage()); - $session->setAttributeData($data); - $this->_redirect('*/*/edit', ['attribute_id' => $id, '_current' => true]); - return; } } - $this->_redirect('*/*/'); + return $data; } - public function deleteAction() + #[\Override] + public function saveAction() { - if ($id = $this->getRequest()->getParam('attribute_id')) { - $model = Mage::getModel('catalog/resource_eav_attribute'); + $request = $this->getRequest(); - // entity type check - $model->load($id); - if ($model->getEntityTypeId() != $this->_entityTypeId || !$model->getIsUserDefined()) { - Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('catalog')->__('This attribute cannot be deleted.') - ); - $this->_redirect('*/*/'); - return; - } - - try { - $model->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess( - Mage::helper('catalog')->__('The product attribute has been deleted.') - ); - $this->_redirect('*/*/'); - return; - } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - $this->_redirect('*/*/edit', ['attribute_id' => $this->getRequest()->getParam('attribute_id')]); - return; - } + // For creating product attribute on product page we need specify attribute set and group + if ($request->getParam('set') && $request->getParam('group')) { + $request->setPost('attribute_set_id', $request->getParam('set')); + $request->setPost('attribute_group_id', $request->getParam('group')); } - Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('catalog')->__('Unable to find an attribute to delete.') - ); - $this->_redirect('*/*/'); + + parent::saveAction(); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php index 0b4ad4df1..01a6e4169 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php @@ -12,11 +12,8 @@ /** * Adminhtml entity sets controller - * - * @category Mage - * @package Mage_Adminhtml */ -class Mage_Adminhtml_Catalog_Product_SetController extends Mage_Adminhtml_Controller_Action +class Mage_Adminhtml_Catalog_Product_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { /** * ACL resource @@ -24,219 +21,42 @@ class Mage_Adminhtml_Catalog_Product_SetController extends Mage_Adminhtml_Contro */ public const ADMIN_RESOURCE = 'catalog/attributes/sets'; - public function indexAction() + #[\Override] + protected function _construct() { - $this->_title($this->__('Catalog')) - ->_title($this->__('Attributes')) - ->_title($this->__('Manage Attribute Sets')); - - $this->_setTypeId(); - - $this->loadLayout(); - $this->_setActiveMenu('catalog/attributes/sets'); - - $this->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog')); - $this->_addBreadcrumb( - Mage::helper('catalog')->__('Manage Attribute Sets'), - Mage::helper('catalog')->__('Manage Attribute Sets') - ); - - $this->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_toolbar_main')); - $this->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_grid')); - - $this->renderLayout(); + $this->entityTypeCode = Mage_Catalog_Model_Product::ENTITY; } - public function editAction() + #[\Override] + public function preDispatch() { - $this->_title($this->__('Catalog')) - ->_title($this->__('Attributes')) - ->_title($this->__('Manage Attribute Sets')); - - $this->_setTypeId(); - $attributeSet = Mage::getModel('eav/entity_attribute_set') - ->load($this->getRequest()->getParam('id')); - - if (!$attributeSet->getId()) { - $this->_redirect('*/*/index'); - return; - } - - $this->_title($attributeSet->getId() ? $attributeSet->getAttributeSetName() : $this->__('New Set')); - - Mage::register('current_attribute_set', $attributeSet); - - $this->loadLayout(); - $this->_setActiveMenu('catalog/attributes/sets'); - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); - - $this->_addBreadcrumb(Mage::helper('catalog')->__('Catalog'), Mage::helper('catalog')->__('Catalog')); - $this->_addBreadcrumb( - Mage::helper('catalog')->__('Manage Product Sets'), - Mage::helper('catalog')->__('Manage Product Sets') - ); - - $this->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_main')); + parent::preDispatch(); - $this->renderLayout(); - } + // For backwards compatibility set camelCase registry key with type id + Mage::register('entityType', $this->entityType->getEntityTypeId()); - public function setGridAction() - { - $this->_setTypeId(); - $this->getResponse()->setBody( - $this->getLayout() - ->createBlock('adminhtml/catalog_product_attribute_set_grid') - ->toHtml() - ); + return $this; } - /** - * Save attribute set action - * - * [POST] Create attribute set from another set and redirect to edit page - * [AJAX] Save attribute set data - * - */ - public function saveAction() + #[\Override] + protected function _initAction() { - $entityTypeId = $this->_getEntityTypeId(); - $hasError = false; - $attributeSetId = $this->getRequest()->getParam('id', false); - $isNewSet = $this->getRequest()->getParam('gotoEdit', false) == '1'; - - /** @var Mage_Eav_Model_Entity_Attribute_Set $model */ - $model = Mage::getModel('eav/entity_attribute_set') - ->setEntityTypeId($entityTypeId); - - /** @var Mage_Adminhtml_Helper_Data $helper */ - $helper = Mage::helper('adminhtml'); - - try { - if ($isNewSet) { - //filter html tags - $name = $helper->stripTags($this->getRequest()->getParam('attribute_set_name')); - $model->setAttributeSetName(trim($name)); - } else { - if ($attributeSetId) { - $model->load($attributeSetId); - } - if (!$model->getId()) { - Mage::throwException(Mage::helper('catalog')->__('This attribute set no longer exists.')); - } - $data = Mage::helper('core')->jsonDecode($this->getRequest()->getPost('data')); + parent::_initAction(); - //filter html tags - $data['attribute_set_name'] = $helper->stripTags($data['attribute_set_name']); - - $model->organizeData($data); - } - - $model->validate(); - if ($isNewSet) { - $model->save(); - $model->initFromSkeleton($this->getRequest()->getParam('skeleton_set')); - } - $model->save(); - $this->_getSession()->addSuccess(Mage::helper('catalog')->__('The attribute set has been saved.')); - } catch (Mage_Core_Exception $e) { - $this->_getSession()->addError($e->getMessage()); - $hasError = true; - } catch (Exception $e) { - $this->_getSession()->addException( - $e, - Mage::helper('catalog')->__('An error occurred while saving the attribute set.') - ); - $hasError = true; - } - - if ($isNewSet) { - if ($hasError) { - $this->_redirect('*/*/add'); - } else { - $this->_redirect('*/*/edit', ['id' => $model->getId()]); - } - } else { - $response = []; - if ($hasError) { - $this->_initLayoutMessages('adminhtml/session'); - $response['error'] = 1; - $response['message'] = $this->getLayout()->getMessagesBlock()->getGroupedHtml(); - } else { - $response['error'] = 0; - $response['url'] = $this->getUrl('*/*/'); - } - $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); - } - } - - public function addAction() - { $this->_title($this->__('Catalog')) ->_title($this->__('Attributes')) - ->_title($this->__('Manage Attribute Sets')) - ->_title($this->__('New Set')); - - $this->_setTypeId(); - - $this->loadLayout(); - $this->_setActiveMenu('catalog/sets'); - - $this->_addContent($this->getLayout()->createBlock('adminhtml/catalog_product_attribute_set_toolbar_add')); - - $this->renderLayout(); - } - - public function deleteAction() - { - $setId = $this->getRequest()->getParam('id'); - try { - Mage::getModel('eav/entity_attribute_set') - ->setId($setId) - ->delete(); - - $this->_getSession()->addSuccess($this->__('The attribute set has been removed.')); - $this->getResponse()->setRedirect($this->getUrl('*/*/')); - } catch (Exception $e) { - $this->_getSession()->addError($this->__('An error occurred while deleting this set.')); - $this->_redirectReferer(); - } - } - - /** - * Controller pre-dispatch method - * - * @return Mage_Adminhtml_Controller_Action - */ - #[\Override] - public function preDispatch() - { - $this->_setForcedFormKeyActions('delete'); - return parent::preDispatch(); - } - - /** - * Define in register catalog_product entity type code as entityType - * - */ - protected function _setTypeId() - { - Mage::register( - 'entityType', - Mage::getModel('catalog/product')->getResource()->getTypeId() - ); - } + ->_title($this->__('Manage Attribute Sets')); - /** - * Retrieve catalog product entity type id - * - * @return int - */ - protected function _getEntityTypeId() - { - if (is_null(Mage::registry('entityType'))) { - $this->_setTypeId(); - } - return Mage::registry('entityType'); + $this->_setActiveMenu('catalog/attributes/sets') + ->_addBreadcrumb( + $this->__('Catalog'), + $this->__('Catalog') + ) + ->_addBreadcrumb( + $this->__('Manage Attribute Sets'), + $this->__('Manage Attribute Sets') + ); + + return $this; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php new file mode 100644 index 000000000..9f650f6d2 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php @@ -0,0 +1,49 @@ +entityTypeCode = Mage_Customer_Model_Address::ENTITY; + } + + #[\Override] + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Customers')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Customer Address Attributes')); + + $this->_setActiveMenu('customer/attributes/customer_address_attributes') + ->_addBreadcrumb( + $this->__('Customers'), + $this->__('Customers') + ) + ->_addBreadcrumb( + $this->__('Manage Customer Address Attributes'), + $this->__('Manage Customer Address Attributes') + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php new file mode 100644 index 000000000..d47906084 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php @@ -0,0 +1,49 @@ +entityTypeCode = Mage_Customer_Model_Address::ENTITY; + } + + #[\Override] + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Customers')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Customer Address Attribute Sets')); + + $this->_setActiveMenu('customer/attributes/customer_address_sets') + ->_addBreadcrumb( + $this->__('Customers'), + $this->__('Customers') + ) + ->_addBreadcrumb( + $this->__('Manage Customer Address Attribute Sets'), + $this->__('Manage Customer Address Attribute Sets') + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php new file mode 100644 index 000000000..88340faa5 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php @@ -0,0 +1,49 @@ +entityTypeCode = Mage_Customer_Model_Customer::ENTITY; + } + + #[\Override] + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Customers')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Customer Attributes')); + + $this->_setActiveMenu('customer/attributes/customer_attributes') + ->_addBreadcrumb( + $this->__('Customers'), + $this->__('Customers') + ) + ->_addBreadcrumb( + $this->__('Manage Customer Attributes'), + $this->__('Manage Customer Attributes') + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php index 6899657fe..56ebba258 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php @@ -75,16 +75,15 @@ public function newAction() $currentGroup = Mage::registry('current_group'); if (!is_null($currentGroup->getId())) { + $this->_title($currentGroup->getCode()); $this->_addBreadcrumb(Mage::helper('customer')->__('Edit Group'), Mage::helper('customer')->__('Edit Customer Groups')); } else { + $this->_title($this->__('New Group')); $this->_addBreadcrumb(Mage::helper('customer')->__('New Group'), Mage::helper('customer')->__('New Customer Groups')); } - $this->_title($currentGroup->getId() ? $currentGroup->getCode() : $this->__('New Group')); - $this->getLayout()->getBlock('content') - ->append($this->getLayout()->createBlock('adminhtml/customer_group_edit', 'group') - ->setEditMode((bool)Mage::registry('current_group')->getId())); + ->append($this->getLayout()->createBlock('adminhtml/customer_group_edit', 'group')); $this->renderLayout(); } @@ -108,28 +107,25 @@ public function saveAction() $customerGroup->load((int)$id); } - $taxClass = (int)$this->getRequest()->getParam('tax_class'); - - if ($taxClass) { - try { - $customerGroupCode = (string)$this->getRequest()->getParam('code'); - - if (!empty($customerGroupCode)) { - $customerGroup->setCode($customerGroupCode); - } + try { + $customerGroupCode = (string)$this->getRequest()->getParam('code'); - $customerGroup->setTaxClassId($taxClass)->save(); - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customer')->__('The customer group has been saved.')); - $this->getResponse()->setRedirect($this->getUrl('*/customer_group')); - return; - } catch (Exception $e) { - Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - Mage::getSingleton('adminhtml/session')->setCustomerGroupData($customerGroup->getData()); - $this->getResponse()->setRedirect($this->getUrl('*/customer_group/edit', ['id' => $id])); - return; + if (!empty($customerGroupCode)) { + $customerGroup->setCode($customerGroupCode); } - } else { - $this->_forward('new'); + + $customerGroup + ->setCustomerAttributeSetId((int)$this->getRequest()->getParam('customer_attribute_set')) + ->setCustomerAddressAttributeSetId((int)$this->getRequest()->getParam('customer_address_attribute_set')) + ->setTaxClassId((int)$this->getRequest()->getParam('tax_class')) + ->save(); + + Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('customer')->__('The customer group has been saved.')); + $this->getResponse()->setRedirect($this->getUrl('*/customer_group')); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + Mage::getSingleton('adminhtml/session')->setCustomerGroupData($customerGroup->getData()); + $this->getResponse()->setRedirect($this->getUrl('*/customer_group/edit', ['id' => $id])); } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php new file mode 100644 index 000000000..e19465d56 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php @@ -0,0 +1,49 @@ +entityTypeCode = Mage_Customer_Model_Customer::ENTITY; + } + + #[\Override] + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Customers')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Customer Attribute Sets')); + + $this->_setActiveMenu('customer/attributes/customer_sets') + ->_addBreadcrumb( + $this->__('Customers'), + $this->__('Customers') + ) + ->_addBreadcrumb( + $this->__('Manage Customer Attribute Sets'), + $this->__('Manage Customer Attribute Sets') + ); + + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index 1be9c1a0b..a5203af87 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -127,6 +127,40 @@ + + + + + adminhtml/observer_eav_product + setEntityTypeRegistryIfNotExist + + + + + + + adminhtml/observer_eav_product + setEntityTypeRegistryIfNotExist + + + + + + + + adminhtml/observer_eav_customer + attributeEditPrepareForm + + + + + + + adminhtml/observer_eav_customer + attributeEditPrepareForm + + + diff --git a/app/code/core/Mage/Catalog/Helper/Data.php b/app/code/core/Mage/Catalog/Helper/Data.php index 8c3afb100..af9e1b913 100644 --- a/app/code/core/Mage/Catalog/Helper/Data.php +++ b/app/code/core/Mage/Catalog/Helper/Data.php @@ -6,6 +6,7 @@ * @package Mage_Catalog * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2019-2024 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -184,29 +185,25 @@ public function splitSku($sku, $length = 30) /** * Retrieve attribute hidden fields * + * @deprecated Instead use Mage::helper('eav')->getInputTypeHiddenFields() + * @see Mage_Eav_Helper_Data::getInputTypeHiddenFields() * @return array */ public function getAttributeHiddenFields() { - if (Mage::registry('attribute_type_hidden_fields')) { - return Mage::registry('attribute_type_hidden_fields'); - } else { - return []; - } + return Mage::helper('eav')->getInputTypeHiddenFields(Mage_Catalog_Model_Product::ENTITY); } /** * Retrieve attribute disabled types * + * @deprecated Instead use Mage::helper('eav')->getInputTypeDisabledApplyToOptions() + * @see Mage_Eav_Helper_Data::getInputTypeDisabledApplyToOptions() * @return array */ public function getAttributeDisabledTypes() { - if (Mage::registry('attribute_type_disabled_types')) { - return Mage::registry('attribute_type_disabled_types'); - } else { - return []; - } + return Mage::helper('eav')->getInputTypeDisabledApplyToOptions(Mage_Catalog_Model_Product::ENTITY); } /** diff --git a/app/code/core/Mage/Catalog/Helper/Product.php b/app/code/core/Mage/Catalog/Helper/Product.php index 2f541f7e6..b63d78e22 100644 --- a/app/code/core/Mage/Catalog/Helper/Product.php +++ b/app/code/core/Mage/Catalog/Helper/Product.php @@ -214,63 +214,46 @@ public function canUseCanonicalTag($store = null) } /** - * Return information array of product attribute input types - * Only a small number of settings returned, so we won't break anything in current dataflow - * As soon as development process goes on we need to add there all possible settings + * Return information array of product attribute by input type * + * @deprecated Instead use Mage::helper('eav')->getInputTypes() + * @see Mage_Eav_Helper_Data::getInputTypes() * @param string $inputType * @return array */ public function getAttributeInputTypes($inputType = null) { - /** - * @todo specify there all relations for properties depending on input type - */ - $inputTypes = [ - 'multiselect' => [ - 'backend_model' => 'eav/entity_attribute_backend_array' - ], - 'boolean' => [ - 'source_model' => 'eav/entity_attribute_source_boolean' - ] - ]; - - if (is_null($inputType)) { + $inputTypes = Mage::helper('eav')->getInputTypes(Mage_Catalog_Model_Product::ENTITY); + if ($inputType === null) { return $inputTypes; - } elseif (isset($inputTypes[$inputType])) { - return $inputTypes[$inputType]; } - return []; + return $inputTypes[$inputType] ?? []; } /** * Return default attribute backend model by input type * + * @deprecated Instead use Mage::helper('eav')->getAttributeBackendModel() + * @see Mage_Eav_Helper_Data::getAttributeBackendModel() * @param string $inputType * @return string|null */ public function getAttributeBackendModelByInputType($inputType) { - $inputTypes = $this->getAttributeInputTypes(); - if (!empty($inputTypes[$inputType]['backend_model'])) { - return $inputTypes[$inputType]['backend_model']; - } - return null; + return Mage::helper('eav')->getAttributeBackendModel(Mage_Catalog_Model_Product::ENTITY, $inputType); } /** * Return default attribute source model by input type * + * @deprecated Instead use Mage::helper('eav')->getAttributeSourceModel() + * @see Mage_Eav_Helper_Data::getAttributeSourceModel() * @param string $inputType * @return string|null */ public function getAttributeSourceModelByInputType($inputType) { - $inputTypes = $this->getAttributeInputTypes(); - if (!empty($inputTypes[$inputType]['source_model'])) { - return $inputTypes[$inputType]['source_model']; - } - return null; + return Mage::helper('eav')->getAttributeSourceModel(Mage_Catalog_Model_Product::ENTITY, $inputType); } /** diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php index 8fee5aab4..0ebb3e585 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php @@ -6,6 +6,7 @@ * @package Mage_Catalog * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2020-2024 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -116,7 +117,7 @@ public function options($attributeId, $store = null) */ public function types() { - return Mage::getModel('catalog/product_attribute_source_inputtype')->toOptionArray(); + return Mage::helper('eav')->getInputTypes(Mage_Catalog_Model_Product::ENTITY); } /** @@ -129,33 +130,27 @@ public function create($data) { /** @var Mage_Catalog_Model_Resource_Eav_Attribute $model */ $model = Mage::getModel('catalog/resource_eav_attribute'); - /** @var Mage_Catalog_Helper_Product $helper */ - $helper = Mage::helper('catalog/product'); if (empty($data['attribute_code']) || (isset($data['frontend_label']) && !is_array($data['frontend_label']))) { $this->_fault('invalid_parameters'); } - //validate attribute_code - if (!preg_match('/^[a-z][a-z_0-9]{0,254}$/', $data['attribute_code'])) { + // Validate attribute_code + $regex = sprintf( + '/^[a-z][a-z_0-9]{%d,%d}$/', + Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MIN_LENGTH, + Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH + ); + if (!preg_match($regex, $data['attribute_code'])) { $this->_fault('invalid_code'); } - //validate frontend_input - $allowedTypes = []; - foreach ($this->types() as $type) { - $allowedTypes[] = $type['value']; - } + // Validate frontend_input + $allowedTypes = array_column($this->types(), 'value'); if (!in_array($data['frontend_input'], $allowedTypes)) { $this->_fault('invalid_frontend_input'); } - $data['source_model'] = $helper->getAttributeSourceModelByInputType($data['frontend_input']); - $data['backend_model'] = $helper->getAttributeBackendModelByInputType($data['frontend_input']); - if (!$model->getBackendType() && (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0)) { - $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']); - } - $this->_prepareDataForSave($data); $model->addData($data); @@ -164,7 +159,7 @@ public function create($data) try { $model->save(); - // clear translation cache because attribute labels are stored in translation + // Clear translation cache because attribute labels are stored in translation Mage::app()->cleanCache([Mage_Core_Model_Translate::CACHE_TAG]); } catch (Exception $e) { $this->_fault('unable_to_save', $e->getMessage()); diff --git a/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Inputtype.php b/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Inputtype.php index a2538d26c..a2fec2271 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Inputtype.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Source/Inputtype.php @@ -13,8 +13,8 @@ /** * Product attribute source input types * - * @category Mage - * @package Mage_Catalog + * @deprecated Instead use Mage::helper('eav')->getInputTypes() + * @see Mage_Eav_Helper_Data::getInputTypes() */ class Mage_Catalog_Model_Product_Attribute_Source_Inputtype extends Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype { @@ -25,39 +25,6 @@ class Mage_Catalog_Model_Product_Attribute_Source_Inputtype extends Mage_Eav_Mod #[\Override] public function toOptionArray() { - $inputTypes = [ - [ - 'value' => 'price', - 'label' => Mage::helper('catalog')->__('Price') - ], - [ - 'value' => 'media_image', - 'label' => Mage::helper('catalog')->__('Media Image') - ] - ]; - - $response = new Varien_Object(); - $response->setTypes([]); - Mage::dispatchEvent('adminhtml_product_attribute_types', ['response' => $response]); - $_disabledTypes = []; - $_hiddenFields = []; - 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']; - } - } - - if (Mage::registry('attribute_type_hidden_fields') === null) { - Mage::register('attribute_type_hidden_fields', $_hiddenFields); - } - if (Mage::registry('attribute_type_disabled_types') === null) { - Mage::register('attribute_type_disabled_types', $_disabledTypes); - } - - return array_merge(parent::toOptionArray(), $inputTypes); + return Mage::helper('eav')->getInputTypes(Mage_Catalog_Model_Product::ENTITY); } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Collection.php index 2d20ce7bf..015b9d0cd 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Attribute/Collection.php @@ -47,4 +47,15 @@ public function setEntityTypeFilter($typeId) { return $this; } + + /** + * Specify filter by "is_visible" field + * + * @return $this + */ + #[\Override] + public function addVisibleFilter() + { + return $this->addFieldToFilter('additional_table.is_visible', 1); + } } diff --git a/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php b/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php index d68007a0a..aeb889af6 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php @@ -60,28 +60,28 @@ */ class Mage_Catalog_Model_Resource_Eav_Attribute extends Mage_Eav_Model_Entity_Attribute { - public const SCOPE_STORE = 0; - public const SCOPE_GLOBAL = 1; - public const SCOPE_WEBSITE = 2; + public const SCOPE_STORE = 0; + public const SCOPE_GLOBAL = 1; + public const SCOPE_WEBSITE = 2; - public const MODULE_NAME = 'Mage_Catalog'; - public const ENTITY = 'catalog_eav_attribute'; + public const MODULE_NAME = 'Mage_Catalog'; + public const ENTITY = 'catalog_eav_attribute'; /** * @var string */ - protected $_eventPrefix = 'catalog_entity_attribute'; + protected $_eventPrefix = 'catalog_entity_attribute'; /** * @var string */ - protected $_eventObject = 'attribute'; + protected $_eventObject = 'attribute'; /** * Array with labels * * @var array|null */ - protected static $_labels = null; + protected static $_labels = null; #[\Override] protected function _construct() diff --git a/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Collection.php b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Collection.php index 1bc50a120..3220c8eaa 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Collection.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Collection.php @@ -134,6 +134,7 @@ public function addIsFilterableInSearchFilter() * * @return $this */ + #[\Override] public function addVisibleFilter() { return $this->addFieldToFilter('additional_table.is_visible', 1); diff --git a/app/code/core/Mage/Catalog/etc/adminhtml.xml b/app/code/core/Mage/Catalog/etc/adminhtml.xml index 74f4a4747..d34f87680 100644 --- a/app/code/core/Mage/Catalog/etc/adminhtml.xml +++ b/app/code/core/Mage/Catalog/etc/adminhtml.xml @@ -7,6 +7,7 @@ * @package Mage_Catalog * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2022 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -34,13 +35,21 @@ Attributes - Manage Attributes + Manage Product Attributes adminhtml/catalog_product_attribute/ - Manage Attribute Sets + Manage Product Attribute Sets adminhtml/catalog_product_set/ + + Manage Category Attributes + adminhtml/catalog_category_attribute/ + + + Manage Category Attribute Sets + adminhtml/catalog_category_set/ + 20 @@ -75,11 +84,17 @@ Attributes - Manage Attributes + Manage Product Attributes - Manage Attribute Sets + Manage Product Attribute Sets + + Manage Category Attributes + + + Manage Category Attribute Sets + diff --git a/app/code/core/Mage/Catalog/etc/config.xml b/app/code/core/Mage/Catalog/etc/config.xml index 88df9e1b1..be24f8396 100644 --- a/app/code/core/Mage/Catalog/etc/config.xml +++ b/app/code/core/Mage/Catalog/etc/config.xml @@ -635,7 +635,62 @@ + + + all_children + 1 + + + children + 1 + + + url_path + 1 + + + path_in_store + 1 + + + + + + + price + decimal + default_value_text + + + + weight + decimal + default_value_text + + + + gallery + varchar + + + + media_image + varchar + + + + + + + + + image + varchar + default_value_text + + + diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Billing.php b/app/code/core/Mage/Checkout/Block/Onepage/Billing.php index 02d366502..b258a24ae 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Billing.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Billing.php @@ -50,6 +50,56 @@ protected function _construct() parent::_construct(); } + /** + * Create form block for template file + */ + #[\Override] + protected function _beforeToHtml() + { + if ($this->getAddress()->getFirstname()) { + $address = $this->getAddress(); + } else { + $address = Mage::getModel('customer/address'); + $address->setCustomer($this->getQuote()->getCustomer()); + } + + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode('customer_address_edit') + ->setEntity($address) + ->setEntityType('customer_address') + ->initDefaultValues(); + + /** @var Mage_Eav_Block_Widget_Form $block */ + $block = $this->getLayout()->createBlock('eav/widget_form'); + $block->setTranslationHelper($this->helper('customer')); + $block->setForm($form); + $block->setFieldIdFormat('billing:%s'); + $block->setFieldNameFormat('billing[%s]'); + + if (!$this->isCustomerLoggedIn()) { + /** @var Mage_Customer_Model_Form $form */ + $registerForm = Mage::getModel('customer/form'); + $registerForm->setFormCode('checkout_register') + ->setEntity($this->getQuote()->getCustomer()) + ->initDefaultValues(); + + $block->mergeFormAttributes($registerForm); + } + + $groups = array_keys($block->getGroupedAttributes()); + if ($groups[0] === 'General') { + if ($this->isCustomerLoggedIn()) { + $block->setDefaultLabel('Account Information'); + } else { + $block->setDefaultLabel('Address Information'); + } + } + $this->setChild('form_checkout_address_create', $block); + + return parent::_beforeToHtml(); + } + /** * @return bool */ diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index 8c16f216d..f0c1d3223 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -402,6 +402,17 @@ protected function _validateCustomerData(array $data) // set customer password $customer->setPassword($customerRequest->getParam('customer_password')); $customer->setPasswordConfirmation($customerRequest->getParam('confirm_password')); + + // TODO, need to separate from customer and customer address + // store additional EAV fields in session + $extraFields = []; + foreach ($customerForm->getAttributes() as $attribute) { + if ($attribute->getIsUserDefined()) { + $code = $attribute->getAttributeCode(); + $extraFields[$code] = $data[$code]; + } + } + $this->_checkoutSession->setExtraFields($extraFields); } else { // spoof customer password for guest $password = $customer->generatePassword(); @@ -699,6 +710,15 @@ protected function _prepareNewCustomerQuote() $customerBilling->setIsDefaultShipping(true); } + // TODO, need to separate from customer and customer address + // copy additional EAV fields from session to customer object + if ($quote->getCheckoutMethod() == self::METHOD_REGISTER) { + $extraFields = $this->_checkoutSession->getExtraFields(); + if ($extraFields) { + $customer->addData($extraFields); + } + } + Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer); $customer->setPassword($customer->decryptPassword($quote->getPasswordHash())); $customer->setPasswordCreatedAt(time()); diff --git a/app/code/core/Mage/Checkout/sql/checkout_setup/install-1.6.0.0.php b/app/code/core/Mage/Checkout/sql/checkout_setup/install-1.6.0.0.php index 27a1ab174..d3191abe9 100644 --- a/app/code/core/Mage/Checkout/sql/checkout_setup/install-1.6.0.0.php +++ b/app/code/core/Mage/Checkout/sql/checkout_setup/install-1.6.0.0.php @@ -6,6 +6,7 @@ * @package Mage_Checkout * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2017-2022 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -79,41 +80,6 @@ $setup = $installer->getConnection(); -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/prefix_show') - ->where('value NOT LIKE ?', '0'); -$showPrefix = (bool)Mage::helper('customer/address')->getConfig('prefix_show') - || ($setup->fetchOne($select) > 0); - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/middlename_show') - ->where('value NOT LIKE ?', '0'); -$showMiddlename = (bool)Mage::helper('customer/address')->getConfig('middlename_show') - || ($setup->fetchOne($select) > 0); - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/suffix_show') - ->where('value NOT LIKE ?', '0'); -$showSuffix = (bool)Mage::helper('customer/address')->getConfig('suffix_show') - || ($setup->fetchOne($select) > 0); - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/dob_show') - ->where('value NOT LIKE ?', '0'); -$showDob = (bool)Mage::helper('customer/address')->getConfig('dob_show') - || ($setup->fetchOne($select) > 0); - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/taxvat_show') - ->where('value NOT LIKE ?', '0'); -$showTaxVat = (bool)Mage::helper('customer/address')->getConfig('taxvat_show') - || ($setup->fetchOne($select) > 0); - $customerEntityTypeId = $installer->getEntityTypeId('customer'); $addressEntityTypeId = $installer->getEntityTypeId('customer_address'); @@ -142,42 +108,24 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, @@ -232,22 +180,6 @@ 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'fax'), 'sort_order' => $elementSort++ ]); -if ($showDob) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'dob'), - 'sort_order' => $elementSort++ - ]); -} -if ($showTaxVat) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'taxvat'), - 'sort_order' => $elementSort++ - ]); -} /** ***************************************************************************** @@ -274,42 +206,24 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, @@ -364,22 +278,6 @@ 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'fax'), 'sort_order' => $elementSort++ ]); -if ($showDob) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'dob'), - 'sort_order' => $elementSort++ - ]); -} -if ($showTaxVat) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'taxvat'), - 'sort_order' => $elementSort++ - ]); -} /** ***************************************************************************** @@ -402,42 +300,24 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, @@ -508,42 +388,24 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, @@ -631,64 +493,30 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'email'), 'sort_order' => $elementSort++ ]); -if ($showDob) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'dob'), - 'sort_order' => $elementSort++ - ]); -} -if ($showTaxVat) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'taxvat'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_fieldset'), [ 'type_id' => $formTypeId, diff --git a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.3-0.9.4.php b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.3-0.9.4.php index 1dcf5813a..b94727bef 100644 --- a/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.3-0.9.4.php +++ b/app/code/core/Mage/Checkout/sql/checkout_setup/mysql4-upgrade-0.9.3-0.9.4.php @@ -6,6 +6,7 @@ * @package Mage_Checkout * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2020-2022 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -15,41 +16,6 @@ $setup = $installer->getConnection(); -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/prefix_show') - ->where('value!=?', '0'); -$showPrefix = (bool)Mage::helper('customer/address')->getConfig('prefix_show') - || ($setup->fetchOne($select) > 0); - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/middlename_show') - ->where('value!=?', '0'); -$showMiddlename = (bool)Mage::helper('customer/address')->getConfig('middlename_show') - || ($setup->fetchOne($select) > 0); - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/suffix_show') - ->where('value!=?', '0'); -$showSuffix = (bool)Mage::helper('customer/address')->getConfig('suffix_show') - || ($setup->fetchOne($select) > 0); - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/dob_show') - ->where('value!=?', '0'); -$showDob = (bool)Mage::helper('customer/address')->getConfig('dob_show') - || ($setup->fetchOne($select) > 0); - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/taxvat_show') - ->where('value!=?', '0'); -$showTaxVat = (bool)Mage::helper('customer/address')->getConfig('taxvat_show') - || ($setup->fetchOne($select) > 0); - $customerEntityTypeId = $installer->getEntityTypeId('customer'); $addressEntityTypeId = $installer->getEntityTypeId('customer_address'); @@ -78,42 +44,24 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, @@ -168,22 +116,6 @@ 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'fax'), 'sort_order' => $elementSort++ ]); -if ($showDob) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'dob'), - 'sort_order' => $elementSort++ - ]); -} -if ($showTaxVat) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'taxvat'), - 'sort_order' => $elementSort++ - ]); -} /** ***************************************************************************** @@ -210,42 +142,24 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, @@ -300,22 +214,6 @@ 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'fax'), 'sort_order' => $elementSort++ ]); -if ($showDob) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'dob'), - 'sort_order' => $elementSort++ - ]); -} -if ($showTaxVat) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'taxvat'), - 'sort_order' => $elementSort++ - ]); -} /** ***************************************************************************** @@ -338,42 +236,24 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, @@ -444,42 +324,24 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => null, + 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => null, - 'attribute_id' => $installer->getAttributeId($addressEntityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => null, @@ -567,64 +429,30 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'email'), 'sort_order' => $elementSort++ ]); -if ($showDob) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'dob'), - 'sort_order' => $elementSort++ - ]); -} -if ($showTaxVat) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($customerEntityTypeId, 'taxvat'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_fieldset'), [ 'type_id' => $formTypeId, diff --git a/app/code/core/Mage/ConfigurableSwatches/etc/jstranslator.xml b/app/code/core/Mage/ConfigurableSwatches/etc/jstranslator.xml index 3cdf4998c..d8ca0aed0 100644 --- a/app/code/core/Mage/ConfigurableSwatches/etc/jstranslator.xml +++ b/app/code/core/Mage/ConfigurableSwatches/etc/jstranslator.xml @@ -23,4 +23,10 @@ Out of Stock + + diff --git a/app/code/core/Mage/Core/Block/Template.php b/app/code/core/Mage/Core/Block/Template.php index f5bc7470a..049221b3b 100644 --- a/app/code/core/Mage/Core/Block/Template.php +++ b/app/code/core/Mage/Core/Block/Template.php @@ -104,6 +104,19 @@ public function setTemplate($template) return $this; } + /** + * Set path to template only if it exists + */ + public function setTemplateIfExists(string $template): Mage_Core_Block_Template + { + $oldTemplate = $this->getTemplate(); + $this->setTemplate($template); + if (!$this->getTemplateFile()) { + $this->setTemplate($oldTemplate); + } + return $this; + } + /** * Get absolute path to template * diff --git a/app/code/core/Mage/Customer/Block/Address/Edit.php b/app/code/core/Mage/Customer/Block/Address/Edit.php index a0672be89..8ca309c3f 100644 --- a/app/code/core/Mage/Customer/Block/Address/Edit.php +++ b/app/code/core/Mage/Customer/Block/Address/Edit.php @@ -21,11 +21,9 @@ * @method $this setSuccessUrl(string $value) * @method $this setTitle(string $value) */ -class Mage_Customer_Block_Address_Edit extends Mage_Directory_Block_Data +class Mage_Customer_Block_Address_Edit extends Mage_Core_Block_Template { protected $_address; - protected $_countryCollection; - protected $_regionCollection; #[\Override] protected function _prepareLayout() @@ -59,10 +57,37 @@ protected function _prepareLayout() return $this; } + /** + * Create form block for template file + */ + #[\Override] + protected function _beforeToHtml() + { + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode('customer_address_edit') + ->setEntity($this->_address) + ->initDefaultValues(); + + /** @var Mage_Eav_Block_Widget_Form $block */ + $block = $this->getLayout()->createBlock('eav/widget_form'); + $block->setTranslationHelper($this->helper('customer')); + $block->setForm($form); + + $groups = array_keys($block->getGroupedAttributes()); + if ($groups[0] === 'General') { + $block->setDefaultLabel('Address Information'); + } + $this->setChild('form_customer_address_edit', $block); + + return parent::_beforeToHtml(); + } + /** * Generate name block html * * @return string + * @deprecated */ public function getNameBlockHtml() { @@ -122,19 +147,30 @@ public function getAddress() } /** - * @return int + * @return string + * @deprecated */ - #[\Override] public function getCountryId() { if ($countryId = $this->getAddress()->getCountryId()) { return $countryId; } - return parent::getCountryId(); + return Mage::helper('core')->getDefaultCountry(); + } + + /** + * @return string + * @deprecated + */ + public function getCountryHtmlSelect() + { + return $this->getLayout()->createBlock('directory/data') + ->getCountryHtmlSelect($this->getCountryId()); } /** * @return int + * @deprecated */ public function getRegionId() { diff --git a/app/code/core/Mage/Customer/Block/Form/Edit.php b/app/code/core/Mage/Customer/Block/Form/Edit.php index b76cd115c..e69996aba 100644 --- a/app/code/core/Mage/Customer/Block/Form/Edit.php +++ b/app/code/core/Mage/Customer/Block/Form/Edit.php @@ -6,6 +6,7 @@ * @package Mage_Customer * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2022-2023 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -17,4 +18,29 @@ */ class Mage_Customer_Block_Form_Edit extends Mage_Customer_Block_Account_Dashboard { + /** + * Create form block for template file + */ + #[\Override] + protected function _beforeToHtml() + { + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode('customer_account_edit') + ->setEntity($this->getCustomer()) + ->initDefaultValues(); + + /** @var Mage_Eav_Block_Widget_Form $block */ + $block = $this->getLayout()->createBlock('eav/widget_form'); + $block->setTranslationHelper($this->helper('customer')); + $block->setForm($form); + + $groups = array_keys($block->getGroupedAttributes()); + if ($groups[0] === 'General') { + $block->setDefaultLabel('Account Information'); + } + $this->setChild('form_customer_account_edit', $block); + + return parent::_beforeToHtml(); + } } diff --git a/app/code/core/Mage/Customer/Block/Form/Register.php b/app/code/core/Mage/Customer/Block/Form/Register.php index 3b8026de6..5f065c775 100644 --- a/app/code/core/Mage/Customer/Block/Form/Register.php +++ b/app/code/core/Mage/Customer/Block/Form/Register.php @@ -21,7 +21,7 @@ * @method $this setShowAddressFields(bool $value) * @method $this setSuccessUrl(string $value) */ -class Mage_Customer_Block_Form_Register extends Mage_Directory_Block_Data +class Mage_Customer_Block_Form_Register extends Mage_Core_Block_Template { /** * Address instance with data @@ -37,6 +37,46 @@ protected function _prepareLayout() return parent::_prepareLayout(); } + /** + * Create form block for template file + */ + #[\Override] + protected function _beforeToHtml() + { + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode('customer_account_create') + ->setEntity(Mage::getModel('customer/customer')) + ->initDefaultValues(); + + $this->restoreSessionData($form); + + /** @var Mage_Eav_Block_Widget_Form $block */ + $block = $this->getLayout()->createBlock('eav/widget_form'); + $block->setTranslationHelper($this->helper('customer')); + $block->setForm($form); + + if ($this->getShowAddressFields()) { + /** @var Mage_Customer_Model_Form $form */ + $addressForm = Mage::getModel('customer/form'); + $addressForm->setFormCode('customer_address_edit') + ->setEntity($this->getAddress()) + ->initDefaultValues(); + + $this->restoreSessionData($addressForm); + + $block->mergeFormAttributes($addressForm); + } + + $groups = array_keys($block->getGroupedAttributes()); + if ($groups[0] === 'General') { + $block->setDefaultLabel('Account Information'); + } + $this->setChild('form_customer_account_create', $block); + + return parent::_beforeToHtml(); + } + /** * Retrieve form posting url * @@ -93,77 +133,79 @@ public function getFormData() } /** - * Retrieve customer country identifier + * Restore entity data from session + * Entity and form code must be defined for the form * - * @return int + * @param string|null $scope + * @return $this */ - #[\Override] - public function getCountryId() + public function restoreSessionData(Mage_Customer_Model_Form $form, $scope = null) { - $countryId = $this->getFormData()->getCountryId(); - if ($countryId) { - return $countryId; + if ($this->getFormData()->getCustomerData()) { + $request = $form->prepareRequest($this->getFormData()->getData()); + $data = $form->extractData($request, $scope, false); + $form->restoreData($data); } - return parent::getCountryId(); + + return $this; } /** - * Retrieve customer region identifier + * Return customer address instance * - * @return string|int|null + * @return Mage_Customer_Model_Address */ - public function getRegion() + public function getAddress() { - if (($region = $this->getFormData()->getRegion()) !== false) { - return $region; + if (is_null($this->_address)) { + $this->_address = Mage::getModel('customer/address'); } - if (($region = $this->getFormData()->getRegionId()) !== false) { - return $region; + return $this->_address; + } + + /** + * @return string + * @deprecated + */ + public function getCountryId() + { + if ($countryId = $this->getFormData()->getCountryId()) { + return $countryId; } - return null; + return Mage::helper('core')->getDefaultCountry(); } /** - * Newsletter module availability - * - * @return bool + * @return string + * @deprecated */ - public function isNewsletterEnabled() + public function getCountryHtmlSelect() { - return Mage::helper('core')->isModuleOutputEnabled('Mage_Newsletter'); + return $this->getLayout()->createBlock('directory/data') + ->getCountryHtmlSelect($this->getCountryId()); } /** - * Return customer address instance - * - * @return Mage_Customer_Model_Address + * @return string|int|null + * @deprecated */ - public function getAddress() + public function getRegion() { - if (is_null($this->_address)) { - $this->_address = Mage::getModel('customer/address'); + if (($region = $this->getFormData()->getRegion()) !== false) { + return $region; } - - return $this->_address; + return null; } /** - * Restore entity data from session - * Entity and form code must be defined for the form + * Newsletter module availability * - * @param string|null $scope - * @return $this + * @return bool */ - public function restoreSessionData(Mage_Customer_Model_Form $form, $scope = null) + public function isNewsletterEnabled() { - if ($this->getFormData()->getCustomerData()) { - $request = $form->prepareRequest($this->getFormData()->getData()); - $data = $form->extractData($request, $scope, false); - $form->restoreData($data); - } - - return $this; + return Mage::helper('core')->isModuleOutputEnabled('Mage_Newsletter'); } /** diff --git a/app/code/core/Mage/Customer/Block/Widget/Abstract.php b/app/code/core/Mage/Customer/Block/Widget/Abstract.php index 5de95d8bc..7273e3553 100644 --- a/app/code/core/Mage/Customer/Block/Widget/Abstract.php +++ b/app/code/core/Mage/Customer/Block/Widget/Abstract.php @@ -6,6 +6,7 @@ * @package Mage_Customer * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2020-2023 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -17,6 +18,8 @@ * * @method Mage_Core_Model_Abstract getObject() * @method $this setObject(Mage_Core_Model_Abstract $value) + * @method $this setFieldIdFormat(string $field) + * @method $this setFieldNameFormat(string $field) */ class Mage_Customer_Block_Widget_Abstract extends Mage_Core_Block_Template { diff --git a/app/code/core/Mage/Customer/Helper/Address.php b/app/code/core/Mage/Customer/Helper/Address.php index 8fe3c309c..5e95434b6 100644 --- a/app/code/core/Mage/Customer/Helper/Address.php +++ b/app/code/core/Mage/Customer/Helper/Address.php @@ -6,6 +6,7 @@ * @package Mage_Customer * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2020-2023 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -26,6 +27,9 @@ class Mage_Customer_Helper_Address extends Mage_Core_Helper_Abstract public const XML_PATH_VIV_TAX_CALCULATION_ADDRESS_TYPE = 'customer/create_account/tax_calculation_address_type'; public const XML_PATH_VAT_FRONTEND_VISIBILITY = 'customer/create_account/vat_frontend_visibility'; + public const STREET_LINES_MIN = 1; + public const STREET_LINES_MAX = 4; + protected $_moduleName = 'Mage_Customer'; /** @@ -99,6 +103,52 @@ public function getConfig($key, $store = null) return isset($this->_config[$websiteId][$key]) ? (string)$this->_config[$websiteId][$key] : null; } + /** + * Retrieve name prefix dropdown options + * + * @param Mage_Core_Model_Store|int|string|null $store + * @return array|bool + */ + public function getNamePrefixOptions($store = null) + { + $attribute = Mage::getSingleton('eav/config')->getAttribute('customer_address', 'prefix'); + $attribute->setStoreId(Mage::app()->getStore($store)->getId()); + $options = $attribute->getSource()->getAllOptions(false); + + if (empty($options)) { + return false; + } + $result = []; + foreach ($options as $option) { + $value = $this->escapeHtml(trim($option['label'])); + $result[$value] = $value; + } + return $result; + } + + /** + * Retrieve name suffix dropdown options + * + * @param Mage_Core_Model_Store|int|string|null $store + * @return array|bool + */ + public function getNameSuffixOptions($store = null) + { + $attribute = Mage::getSingleton('eav/config')->getAttribute('customer_address', 'suffix'); + $attribute->setStoreId(Mage::app()->getStore($store)->getId()); + $options = $attribute->getSource()->getAllOptions(false); + + if (empty($options)) { + return false; + } + $result = []; + foreach ($options as $option) { + $value = $this->escapeHtml(trim($option['label'])); + $result[$value] = $value; + } + return $result; + } + /** * Return Number of Lines in a Street Address for store * @@ -115,7 +165,7 @@ public function getStreetLines($store = null) if ($lines <= 0) { $lines = 2; } - $this->_streetLines[$websiteId] = min(20, $lines); + $this->_streetLines[$websiteId] = max(self::STREET_LINES_MIN, min(self::STREET_LINES_MAX, $lines)); } return $this->_streetLines[$websiteId]; diff --git a/app/code/core/Mage/Customer/Helper/Data.php b/app/code/core/Mage/Customer/Helper/Data.php index 25c3168e9..8a1d54f5b 100644 --- a/app/code/core/Mage/Customer/Helper/Data.php +++ b/app/code/core/Mage/Customer/Helper/Data.php @@ -381,9 +381,19 @@ public function isRegistrationAllowed() */ public function getNamePrefixOptions($store = null) { - return $this->_prepareNamePrefixSuffixOptions( - Mage::helper('customer/address')->getConfig('prefix_options', $store) - ); + $attribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'prefix'); + $attribute->setStoreId(Mage::app()->getStore($store)->getId()); + $options = $attribute->getSource()->getAllOptions(false); + + if (empty($options)) { + return false; + } + $result = []; + foreach ($options as $option) { + $value = $this->escapeHtml(trim($option['label'])); + $result[$value] = $value; + } + return $result; } /** @@ -394,27 +404,16 @@ public function getNamePrefixOptions($store = null) */ public function getNameSuffixOptions($store = null) { - return $this->_prepareNamePrefixSuffixOptions( - Mage::helper('customer/address')->getConfig('suffix_options', $store) - ); - } + $attribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'suffix'); + $attribute->setStoreId(Mage::app()->getStore($store)->getId()); + $options = $attribute->getSource()->getAllOptions(false); - /** - * Unserialize and clear name prefix or suffix options - * - * @param string $options - * @return array|bool - */ - protected function _prepareNamePrefixSuffixOptions($options) - { - $options = trim($options); if (empty($options)) { return false; } $result = []; - $options = explode(';', $options); - foreach ($options as $value) { - $value = $this->escapeHtml(trim($value)); + foreach ($options as $option) { + $value = $this->escapeHtml(trim($option['label'])); $result[$value] = $value; } return $result; diff --git a/app/code/core/Mage/Customer/Model/Address.php b/app/code/core/Mage/Customer/Model/Address.php index 28434e267..104929a44 100644 --- a/app/code/core/Mage/Customer/Model/Address.php +++ b/app/code/core/Mage/Customer/Model/Address.php @@ -26,6 +26,8 @@ */ class Mage_Customer_Model_Address extends Mage_Customer_Model_Address_Abstract { + public const ENTITY = 'customer_address'; + protected $_customer; #[\Override] @@ -88,6 +90,17 @@ public function setCustomer(Mage_Customer_Model_Customer $customer) return $this; } + /** + * Retrieve customer address attribute set identifier + * + * @return int + */ + public function getAttributeSetId() + { + $customer = $this->getCustomer() ?: Mage::getModel('customer/customer'); + return $customer->getAddressAttributeSetId(); + } + /** * Delete customer address * diff --git a/app/code/core/Mage/Customer/Model/Customer.php b/app/code/core/Mage/Customer/Model/Customer.php index 8cdbb2283..2e10d4c3c 100644 --- a/app/code/core/Mage/Customer/Model/Customer.php +++ b/app/code/core/Mage/Customer/Model/Customer.php @@ -95,7 +95,9 @@ * @method string getSuffix() * * @method int getTagId() - * @method $this setTaxClassId(bool $value) + * @method $this setAttributeSetId(int $value) + * @method $this setAddressAttributeSetId(int $value) + * @method $this setTaxClassId(int $value) * @method string getTaxvat() * @method $this setTotal(float $value) * @@ -104,6 +106,8 @@ */ class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract { + public const ENTITY = 'customer'; + /** * Configuration paths for email templates and identities */ @@ -137,7 +141,7 @@ class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract public const SUBSCRIBED_YES = 'yes'; public const SUBSCRIBED_NO = 'no'; - public const CACHE_TAG = 'customer'; + public const CACHE_TAG = self::ENTITY; /** * Minimum Password Length @@ -160,14 +164,14 @@ class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract * * @var string */ - protected $_eventPrefix = 'customer'; + protected $_eventPrefix = self::ENTITY; /** * Name of the event object * * @var string */ - protected $_eventObject = 'customer'; + protected $_eventObject = self::ENTITY; /** * List of errors @@ -930,7 +934,6 @@ public function getGroupId() * Retrieve customer tax class identifier * * @return int - * @throws Mage_Core_Model_Store_Exception */ public function getTaxClassId() { @@ -940,6 +943,32 @@ public function getTaxClassId() return $this->getData('tax_class_id'); } + /** + * Retrieve customer attribute set identifier + * + * @return int + */ + public function getAttributeSetId() + { + if (!$this->getData('attribute_set_id')) { + $this->setAttributeSetId(Mage::getModel('customer/group')->getCustomerAttributeSetId($this->getGroupId())); + } + return $this->getData('attribute_set_id'); + } + + /** + * Retrieve customer address attribute set identifier + * + * @return int + */ + public function getAddressAttributeSetId() + { + if (!$this->getData('address_attribute_set_id')) { + $this->setAddressAttributeSetId(Mage::getModel('customer/group')->getCustomerAddressAttributeSetId($this->getGroupId())); + } + return $this->getData('address_attribute_set_id'); + } + /** * Check store availability for customer * @@ -1072,15 +1101,15 @@ public function validate() $entityType = Mage::getSingleton('eav/config')->getEntityType('customer'); $attribute = Mage::getModel('customer/attribute')->loadByCode($entityType, 'dob'); - if ($attribute->getIsRequired() && trim($this->getDob()) == '') { + if ($attribute->getIsVisible() && $attribute->getIsRequired() && trim($this->getDob()) == '') { $errors[] = Mage::helper('customer')->__('The Date of Birth is required.'); } $attribute = Mage::getModel('customer/attribute')->loadByCode($entityType, 'taxvat'); - if ($attribute->getIsRequired() && trim($this->getTaxvat()) == '') { + if ($attribute->getIsVisible() && $attribute->getIsRequired() && trim($this->getTaxvat()) == '') { $errors[] = Mage::helper('customer')->__('The TAX/VAT number is required.'); } $attribute = Mage::getModel('customer/attribute')->loadByCode($entityType, 'gender'); - if ($attribute->getIsRequired() && trim($this->getGender()) == '') { + if ($attribute->getIsVisible() && $attribute->getIsRequired() && trim($this->getGender()) == '') { $errors[] = Mage::helper('customer')->__('Gender is required.'); } diff --git a/app/code/core/Mage/Customer/Model/Form.php b/app/code/core/Mage/Customer/Model/Form.php index 7231baabf..e28f3fcd9 100644 --- a/app/code/core/Mage/Customer/Model/Form.php +++ b/app/code/core/Mage/Customer/Model/Form.php @@ -42,6 +42,7 @@ class Mage_Customer_Model_Form extends Mage_Eav_Model_Form protected function _getFormAttributeCollection() { return parent::_getFormAttributeCollection() - ->addFieldToFilter('attribute_code', ['neq' => 'created_at']); + ->addFieldToFilter('ea.attribute_code', ['neq' => 'created_at']) + ->filterAttributeSet($this->getEntity()->getAttributeSetId()); } } diff --git a/app/code/core/Mage/Customer/Model/Group.php b/app/code/core/Mage/Customer/Model/Group.php index 3a56ce9bf..cb71f2015 100644 --- a/app/code/core/Mage/Customer/Model/Group.php +++ b/app/code/core/Mage/Customer/Model/Group.php @@ -30,14 +30,15 @@ class Mage_Customer_Model_Group extends Mage_Core_Model_Abstract /** * Xml config path for create account default group */ - public const XML_PATH_DEFAULT_ID = 'customer/create_account/default_group'; + public const XML_PATH_DEFAULT_ID = 'customer/create_account/default_group'; - public const NOT_LOGGED_IN_ID = 0; - public const CUST_GROUP_ALL = 32000; + public const ENTITY = 'customer_group'; - public const ENTITY = 'customer_group'; + public const NOT_LOGGED_IN_ID = 0; - public const GROUP_CODE_MAX_LENGTH = 32; + public const CUST_GROUP_ALL = 32000; + + public const GROUP_CODE_MAX_LENGTH = 32; /** * Prefix of model events names @@ -55,6 +56,7 @@ class Mage_Customer_Model_Group extends Mage_Core_Model_Abstract */ protected $_eventObject = 'object'; + /** @deprecated */ protected static $_taxClassIds = []; #[\Override] @@ -91,15 +93,37 @@ public function getCode() public function getTaxClassId($groupId = null) { if (!is_null($groupId)) { - if (empty(self::$_taxClassIds[$groupId])) { - $this->load($groupId); - self::$_taxClassIds[$groupId] = $this->getData('tax_class_id'); - } - $this->setData('tax_class_id', self::$_taxClassIds[$groupId]); + $taxClassId = $this->getResource()->loadGroupTableData($groupId)['tax_class_id']; + self::$_taxClassIds[$groupId] = $taxClassId; + return $taxClassId; } return $this->getData('tax_class_id'); } + /** + * @param int|null $groupId + * @return int + */ + public function getCustomerAttributeSetId($groupId = null) + { + if (!is_null($groupId)) { + return $this->getResource()->loadGroupTableData($groupId)['customer_attribute_set_id']; + } + return $this->getData('customer_attribute_set_id'); + } + + /** + * @param int|null $groupId + * @return int + */ + public function getCustomerAddressAttributeSetId($groupId = null) + { + if (!is_null($groupId)) { + return $this->getResource()->loadGroupTableData($groupId)['customer_address_attribute_set_id']; + } + return $this->getData('customer_address_attribute_set_id'); + } + /** * @return bool */ diff --git a/app/code/core/Mage/Customer/Model/Resource/Group.php b/app/code/core/Mage/Customer/Model/Resource/Group.php index a31c1c9ad..93baea73f 100644 --- a/app/code/core/Mage/Customer/Model/Resource/Group.php +++ b/app/code/core/Mage/Customer/Model/Resource/Group.php @@ -18,6 +18,11 @@ */ class Mage_Customer_Model_Resource_Group extends Mage_Core_Model_Resource_Db_Abstract { + /** + * Store data from customer_group table + */ + protected static array $_groupTableData = []; + #[\Override] protected function _construct() { @@ -76,4 +81,15 @@ protected function _afterDelete(Mage_Core_Model_Abstract $group) } return parent::_afterDelete($group); } + + /** + * Load group and store data in static property + */ + public static function loadGroupTableData(int $groupId): array + { + if (empty(self::$_groupTableData[$groupId])) { + self::$_groupTableData[$groupId] = Mage::getModel('customer/group')->load($groupId)->getData(); + } + return self::$_groupTableData[$groupId]; + } } diff --git a/app/code/core/Mage/Customer/etc/adminhtml.xml b/app/code/core/Mage/Customer/etc/adminhtml.xml index 8bf4d2015..abee559cf 100644 --- a/app/code/core/Mage/Customer/etc/adminhtml.xml +++ b/app/code/core/Mage/Customer/etc/adminhtml.xml @@ -7,6 +7,7 @@ * @package Mage_Customer * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2022 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -15,7 +16,6 @@ Customers 40 - Manage Customers @@ -27,6 +27,28 @@ adminhtml/customer_group/ 10 + + Attributes + + + Manage Customer Attributes + adminhtml/customer_attribute/ + + + Manage Customer Attribute Sets + adminhtml/customer_set/ + + + Manage Customer Address Attributes + adminhtml/customer_address_attribute/ + + + Manage Customer Address Attribute Sets + adminhtml/customer_address_set/ + + + 20 + Online Customers adminhtml/customer_online/ @@ -51,6 +73,23 @@ Manage Customers 0 + + Attributes + + + Manage Customer Attributes + + + Manage Customer Attribute Sets + + + Manage Customer Address Attributes + + + Manage Customer Address Attribute Sets + + + Online Customers 100 diff --git a/app/code/core/Mage/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index af62924c0..de30da2cb 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -455,6 +455,139 @@ + + + + rp_token_created_at + 1 + + + rp_token + 1 + + + rp_customer_id + 1 + + + reward_warning_notification + 1 + + + reward_update_notification + 1 + + + password_hash + 1 + + + website_id + 1 + + + store_id + 1 + + + created_at + 1 + + + created_in + 1 + + + default_billing + 1 + + + default_shipping + 1 + + + disable_auto_group_change + 1 + + + group_id + 1 + + + confirmation + 1 + + + password_created_at + 1 + + + middlename + + + + + + + + middlename + + + + + + + + + + + adminhtml_checkout + + + + adminhtml_customer + + + + checkout_register + + + + customer_account_create + + + + customer_account_edit + + + + + + adminhtml_customer_address + + + + checkout_address_create + + + + customer_address_edit + + + + customer_register_address + + + + + + + + multiline + text + + + @@ -551,16 +684,6 @@ customer_password_link_account_new_email_template customer_password_link_email_template -
- 2 - - - 1 - - - - -
1 diff --git a/app/code/core/Mage/Customer/etc/system.xml b/app/code/core/Mage/Customer/etc/system.xml index 739fea0d6..eb770cb73 100644 --- a/app/code/core/Mage/Customer/etc/system.xml +++ b/app/code/core/Mage/Customer/etc/system.xml @@ -7,6 +7,7 @@ * @package Mage_Customer * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2017-2024 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -363,103 +364,6 @@ -
- - 40 - 1 - 1 - 1 - - - - 10 - 1 - 1 - 0 - adminhtml/system_config_backend_customer_address_street - Leave empty for default (2). Valid range: 1-4 - - - - select - adminhtml/system_config_source_nooptreq - 20 - adminhtml/system_config_backend_customer_show_address - The title that goes before name (Mr., Mrs., etc.) - 1 - 1 - 0 - - - - 30 - Put semicolon in the beginning for empty first option.
Leave empty for open text field.]]>
- 1 - 1 - 1 -
- - - select - adminhtml/system_config_source_yesno - Always optional. - adminhtml/system_config_backend_customer_show_address - 40 - 1 - 1 - 0 - - - - select - adminhtml/system_config_source_nooptreq - The suffix that goes after name (Jr., Sr., etc.) - adminhtml/system_config_backend_customer_show_address - 50 - 1 - 1 - 0 - - - - 60 - Put semicolon in the beginning for empty first option.
Leave empty for open text field.]]>
- 1 - 1 - 1 -
- - - select - adminhtml/system_config_source_nooptreq - 70 - adminhtml/system_config_backend_customer_show_customer - 1 - 1 - 0 - - - - select - adminhtml/system_config_source_nooptreq - adminhtml/system_config_backend_customer_show_customer - 80 - 1 - 1 - 0 - - - - select - adminhtml/system_config_source_nooptreq - adminhtml/system_config_backend_customer_show_customer - 90 - 1 - 1 - 0 - -
-
90 diff --git a/app/code/core/Mage/Customer/sql/customer_setup/mysql4-data-upgrade-1.4.0.0.7-1.4.0.0.8.php b/app/code/core/Mage/Customer/sql/customer_setup/mysql4-data-upgrade-1.4.0.0.7-1.4.0.0.8.php index de10e9213..2615cfcba 100644 --- a/app/code/core/Mage/Customer/sql/customer_setup/mysql4-data-upgrade-1.4.0.0.7-1.4.0.0.8.php +++ b/app/code/core/Mage/Customer/sql/customer_setup/mysql4-data-upgrade-1.4.0.0.7-1.4.0.0.8.php @@ -6,6 +6,7 @@ * @package Mage_Customer * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2020-2024 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -77,9 +78,9 @@ 'prefix' => [ 'is_user_defined' => 0, 'is_system' => 0, - 'is_visible' => $addressHelper->getConfig('prefix_show', $store) == '' ? 0 : 1, + 'is_visible' => 0, 'sort_order' => 30, - 'is_required' => $addressHelper->getConfig('prefix_show', $store) == 'req' ? 1 : 0 + 'is_required' => 0, ], 'firstname' => [ 'is_user_defined' => 0, @@ -95,9 +96,9 @@ 'middlename' => [ 'is_user_defined' => 0, 'is_system' => 0, - 'is_visible' => $addressHelper->getConfig('middlename_show', $store) == '' ? 0 : 1, + 'is_visible' => 1, 'sort_order' => 50, - 'is_required' => $addressHelper->getConfig('middlename_show', $store) == 'req' ? 1 : 0 + 'is_required' => 0, ], 'lastname' => [ 'is_user_defined' => 0, @@ -113,9 +114,9 @@ 'suffix' => [ 'is_user_defined' => 0, 'is_system' => 0, - 'is_visible' => $addressHelper->getConfig('suffix_show', $store) == '' ? 0 : 1, + 'is_visible' => 0, 'sort_order' => 70, - 'is_required' => $addressHelper->getConfig('suffix_show', $store) == 'req' ? 1 : 0 + 'is_required' => 0, ], 'email' => [ 'is_user_defined' => 0, @@ -131,9 +132,9 @@ 'dob' => [ 'is_user_defined' => 0, 'is_system' => 0, - 'is_visible' => $addressHelper->getConfig('dob_show', $store) == '' ? 0 : 1, + 'is_visible' => 0, 'sort_order' => 90, - 'is_required' => $addressHelper->getConfig('dob_show', $store) == 'req' ? 1 : 0, + 'is_required' => 0, 'validate_rules' => [ 'input_validation' => 'date' ], @@ -143,9 +144,9 @@ 'taxvat' => [ 'is_user_defined' => 0, 'is_system' => 0, - 'is_visible' => $addressHelper->getConfig('dob_show', $store) == '' ? 0 : 1, + 'is_visible' => 0, 'sort_order' => 100, - 'is_required' => $addressHelper->getConfig('dob_show', $store) == 'req' ? 1 : 0, + 'is_required' => 0, 'validate_rules' => [ 'max_text_length' => 255, ], @@ -154,9 +155,9 @@ 'gender' => [ 'is_user_defined' => 0, 'is_system' => 0, - 'is_visible' => $addressHelper->getConfig('gender_show', $store) == '' ? 0 : 1, + 'is_visible' => 0, 'sort_order' => 110, - 'is_required' => $addressHelper->getConfig('gender_show', $store) == 'req' ? 1 : 0, + 'is_required' => 0, 'validate_rules' => [], 'admin_checkout' => 1 ], @@ -195,9 +196,9 @@ 'prefix' => [ 'is_user_defined' => 0, 'is_system' => 0, - 'is_visible' => $addressHelper->getConfig('prefix_show', $store) == '' ? 0 : 1, + 'is_visible' => 0, 'sort_order' => 10, - 'is_required' => $addressHelper->getConfig('prefix_show', $store) == 'req' ? 1 : 0, + 'is_required' => 0, ], 'firstname' => [ 'is_user_defined' => 0, @@ -213,9 +214,9 @@ 'middlename' => [ 'is_user_defined' => 0, 'is_system' => 0, - 'is_visible' => $addressHelper->getConfig('middlename_show', $store) == '' ? 0 : 1, + 'is_visible' => 1, 'sort_order' => 30, - 'is_required' => $addressHelper->getConfig('middlename_show', $store) == 'req' ? 1 : 0, + 'is_required' => 0, ], 'lastname' => [ 'is_user_defined' => 0, @@ -231,9 +232,9 @@ 'suffix' => [ 'is_user_defined' => 0, 'is_system' => 0, - 'is_visible' => $addressHelper->getConfig('suffix_show', $store) == '' ? 0 : 1, + 'is_visible' => 0, 'sort_order' => 50, - 'is_required' => $addressHelper->getConfig('suffix_show', $store) == 'req' ? 1 : 0, + 'is_required' => 0, ], 'company' => [ 'is_user_defined' => 0, @@ -251,7 +252,7 @@ 'is_system' => 1, 'is_visible' => 1, 'sort_order' => 70, - 'multiline_count' => $addressHelper->getConfig('street_lines', $store), + 'multiline_count' => 2, 'is_required' => 1, 'validate_rules' => [ 'max_text_length' => 255, diff --git a/app/code/core/Mage/Customer/sql/customer_setup/mysql4-data-upgrade-1.4.0.0.8-1.4.0.0.9.php b/app/code/core/Mage/Customer/sql/customer_setup/mysql4-data-upgrade-1.4.0.0.8-1.4.0.0.9.php deleted file mode 100644 index 3bd9f1761..000000000 --- a/app/code/core/Mage/Customer/sql/customer_setup/mysql4-data-upgrade-1.4.0.0.8-1.4.0.0.9.php +++ /dev/null @@ -1,103 +0,0 @@ -getWebsites(false); -foreach ($websites as $website) { - $store = $website->getDefaultStore(); - if (!$store) { - continue; - } - - // customer attributes - $attributes = [ - 'prefix', - 'middlename', - 'suffix', - 'dob', - 'taxvat', - 'gender' - ]; - - foreach ($attributes as $attributeCode) { - /** @var Mage_Customer_Model_Attribute $attribute */ - $attribute = $eavConfig->getAttribute('customer', $attributeCode); - $configValue = $addressHelper->getConfig($attributeCode . '_show', $store); - $isVisible = $attribute->getData('is_visible'); - $isRequired = $attribute->getData('is_required'); - - if ($configValue == 'opt' || $configValue == '1') { - $scopeIsVisible = '1'; - $scopeIsRequired = '0'; - } elseif ($configValue == 'req') { - $scopeIsVisible = '1'; - $scopeIsRequired = '1'; - } else { - $scopeIsVisible = '0'; - $scopeIsRequired = '0'; - } - - if ($isVisible != $scopeIsVisible || $isRequired != $scopeIsRequired) { - $attribute->setWebsite($website); - $attribute->setScopeIsVisible($scopeIsVisible); - $attribute->setScopeIsRequired($scopeIsRequired); - $attribute->save(); - } - } - - // customer address attributes - $attributes = [ - 'prefix', - 'middlename', - 'suffix', - ]; - - foreach ($attributes as $attributeCode) { - $attribute = $eavConfig->getAttribute('customer_address', $attributeCode); - $configValue = $addressHelper->getConfig($attributeCode . '_show', $store); - $isVisible = $attribute->getData('is_visible'); - $isRequired = $attribute->getData('is_required'); - - if ($configValue == 'opt' || $configValue == '1') { - $scopeIsVisible = '1'; - $scopeIsRequired = '0'; - } elseif ($configValue == 'req') { - $scopeIsVisible = '1'; - $scopeIsRequired = '1'; - } else { - $scopeIsVisible = '0'; - $scopeIsRequired = '0'; - } - - if ($isVisible != $scopeIsVisible || $isRequired != $scopeIsRequired) { - $attribute->setWebsite($website); - $attribute->setScopeIsVisible($scopeIsVisible); - $attribute->setScopeIsRequired($scopeIsRequired); - $attribute->save(); - } - } - - $attribute = $eavConfig->getAttribute('customer_address', 'street'); - $value = $addressHelper->getConfig('street_lines', $store); - if ($attribute->getData('multiline_count') != $value) { - $attribute->setWebsite($website); - $attribute->setScopeMultilineCount($value); - $attribute->save(); - } -} diff --git a/app/code/core/Mage/Customer/sql/customer_setup/mysql4-install-1.4.0.0.0.php b/app/code/core/Mage/Customer/sql/customer_setup/mysql4-install-1.4.0.0.0.php index 28b8a880b..a1e52dd06 100644 --- a/app/code/core/Mage/Customer/sql/customer_setup/mysql4-install-1.4.0.0.0.php +++ b/app/code/core/Mage/Customer/sql/customer_setup/mysql4-install-1.4.0.0.0.php @@ -6,6 +6,7 @@ * @package Mage_Customer * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2020-2022 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -257,41 +258,6 @@ $setup = $installer->getConnection(); -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/prefix_show') - ->where('value!=?', '0'); -$showPrefix = (bool)Mage::helper('customer/address')->getConfig('prefix_show') - || $setup->fetchOne($select) > 0; - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/middlename_show') - ->where('value!=?', '0'); -$showMiddlename = (bool)Mage::helper('customer/address')->getConfig('middlename_show') - || $setup->fetchOne($select) > 0; - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/suffix_show') - ->where('value!=?', '0'); -$showSuffix = (bool)Mage::helper('customer/address')->getConfig('suffix_show') - || $setup->fetchOne($select) > 0; - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/dob_show') - ->where('value!=?', '0'); -$showDob = (bool)Mage::helper('customer/address')->getConfig('dob_show') - || $setup->fetchOne($select) > 0; - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/taxvat_show') - ->where('value!=?', '0'); -$showTaxVat = (bool)Mage::helper('customer/address')->getConfig('taxvat_show') - || $setup->fetchOne($select) > 0; - /** ***************************************************************************** * customer/account/create/ @@ -327,64 +293,30 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'email'), 'sort_order' => $elementSort++ ]); -if ($showDob) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'dob'), - 'sort_order' => $elementSort++ - ]); -} -if ($showTaxVat) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'taxvat'), - 'sort_order' => $elementSort++ - ]); -} /** ***************************************************************************** @@ -421,64 +353,30 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'email'), 'sort_order' => $elementSort++ ]); -if ($showDob) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'dob'), - 'sort_order' => $elementSort++ - ]); -} -if ($showTaxVat) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'taxvat'), - 'sort_order' => $elementSort++ - ]); -} /** ***************************************************************************** @@ -515,42 +413,24 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, diff --git a/app/code/core/Mage/Customer/sql/customer_setup/mysql4-upgrade-0.8.11-0.8.12.php b/app/code/core/Mage/Customer/sql/customer_setup/mysql4-upgrade-0.8.11-0.8.12.php index 70c82ccc1..a34c06a07 100644 --- a/app/code/core/Mage/Customer/sql/customer_setup/mysql4-upgrade-0.8.11-0.8.12.php +++ b/app/code/core/Mage/Customer/sql/customer_setup/mysql4-upgrade-0.8.11-0.8.12.php @@ -6,6 +6,7 @@ * @package Mage_Customer * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2020-2022 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ @@ -15,41 +16,6 @@ $setup = $installer->getConnection(); -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/prefix_show') - ->where('value!=?', '0'); -$showPrefix = (bool)Mage::helper('customer/address')->getConfig('prefix_show') - || $setup->fetchOne($select) > 0; - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/middlename_show') - ->where('value!=?', '0'); -$showMiddlename = (bool)Mage::helper('customer/address')->getConfig('middlename_show') - || $setup->fetchOne($select) > 0; - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/suffix_show') - ->where('value!=?', '0'); -$showSuffix = (bool)Mage::helper('customer/address')->getConfig('suffix_show') - || $setup->fetchOne($select) > 0; - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/dob_show') - ->where('value!=?', '0'); -$showDob = (bool)Mage::helper('customer/address')->getConfig('dob_show') - || $setup->fetchOne($select) > 0; - -$select = $setup->select() - ->from($installer->getTable('core/config_data'), 'COUNT(*)') - ->where('path=?', 'customer/address/taxvat_show') - ->where('value!=?', '0'); -$showTaxVat = (bool)Mage::helper('customer/address')->getConfig('taxvat_show') - || $setup->fetchOne($select) > 0; - /** ***************************************************************************** * customer/account/create/ @@ -85,64 +51,30 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'email'), 'sort_order' => $elementSort++ ]); -if ($showDob) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'dob'), - 'sort_order' => $elementSort++ - ]); -} -if ($showTaxVat) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'taxvat'), - 'sort_order' => $elementSort++ - ]); -} /** ***************************************************************************** @@ -179,64 +111,30 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'email'), 'sort_order' => $elementSort++ ]); -if ($showDob) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'dob'), - 'sort_order' => $elementSort++ - ]); -} -if ($showTaxVat) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'taxvat'), - 'sort_order' => $elementSort++ - ]); -} /** ***************************************************************************** @@ -273,42 +171,24 @@ ]); $elementSort = 0; -if ($showPrefix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'prefix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'firstname'), 'sort_order' => $elementSort++ ]); -if ($showMiddlename) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), - 'sort_order' => $elementSort++ - ]); -} +$setup->insert($installer->getTable('eav/form_element'), [ + 'type_id' => $formTypeId, + 'fieldset_id' => $fieldsetId, + 'attribute_id' => $installer->getAttributeId($entityTypeId, 'middlename'), + 'sort_order' => $elementSort++ +]); $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, 'attribute_id' => $installer->getAttributeId($entityTypeId, 'lastname'), 'sort_order' => $elementSort++ ]); -if ($showSuffix) { - $setup->insert($installer->getTable('eav/form_element'), [ - 'type_id' => $formTypeId, - 'fieldset_id' => $fieldsetId, - 'attribute_id' => $installer->getAttributeId($entityTypeId, 'suffix'), - 'sort_order' => $elementSort++ - ]); -} $setup->insert($installer->getTable('eav/form_element'), [ 'type_id' => $formTypeId, 'fieldset_id' => $fieldsetId, diff --git a/app/code/core/Mage/Customer/sql/maho_setup/maho-24.10.0.php b/app/code/core/Mage/Customer/sql/maho_setup/maho-24.10.0.php new file mode 100644 index 000000000..3470d6107 --- /dev/null +++ b/app/code/core/Mage/Customer/sql/maho_setup/maho-24.10.0.php @@ -0,0 +1,80 @@ +startSetup(); + +/** + * Add new columns to the customer_group table allowing each group to be assigned + * an attribute set for both the customer and customer_address entity types. + * + * If there are no attribute sets available, create a new one and set as default. + */ +$defs = [ + [ 'model' => 'customer/customer', 'column' => 'customer_attribute_set_id' ], + [ 'model' => 'customer/address', 'column' => 'customer_address_attribute_set_id' ], +]; + +foreach ($defs as $info) { + /** @var Mage_Eav_Model_Entity_Type $entityType */ + $entityType = Mage::getResourceModel($info['model'])->getEntityType(); + + /** $var Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection $collection */ + $collection = Mage::getResourceModel('eav/entity_attribute_set_collection') + ->setEntityTypeFilter($entityType->getId()); + + /** @var Mage_Eav_Model_Entity_Attribute_Set $defaultSet */ + $defaultSet = $collection->getItemById($entityType->getDefaultAttributeSetId()) + ?? $collection->getFirstItem(); + + if ($defaultSet->getId() === null) { + /** @var Mage_Eav_Model_Entity_Attribute_Set $defaultSet */ + $defaultSet = Mage::getModel('eav/entity_attribute_set') + ->setEntityTypeId($entityType->getId()) + ->setAttributeSetName('Default') + ->save(); + + /** @var Mage_Eav_Model_Entity_Attribute_Group $modelGroup */ + $modelGroup = Mage::getModel('eav/entity_attribute_group') + ->setAttributeGroupName('General') + ->setAttributeSetId($defaultSet->getId()) + ->setSortOrder(1) + ->setDefaultId(1) + ->save(); + + /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $attributes */ + $attributes = Mage::getResourceModel($entityType->getEntityAttributeCollection()) + ->setEntityTypeFilter($entityType->getId()) + ->load(); + + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + foreach ($attributes->getItems() as $attribute) { + $attribute->setAttributeGroupId($modelGroup->getId()) + ->setAttributeSetId($defaultSet->getId()) + ->save(); + } + } + + if ($entityType->getDefaultAttributeSetId() !== $defaultSet->getId()) { + $entityType->setDefaultAttributeSetId($defaultSet->getId())->save(); + } + + $installer->getConnection() + ->addColumn($installer->getTable('customer/customer_group'), $info['column'], [ + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => $defaultSet->getId(), + 'comment' => 'Customer Group Attribute Set ID', + ]); +} + +$installer->endSetup(); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php new file mode 100644 index 000000000..27fad8d28 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php @@ -0,0 +1,37 @@ +entityType = Mage::registry('entity_type'); + + $this->_blockGroup = 'eav'; + $this->_controller = 'adminhtml_attribute'; + + $this->_headerText = $this->__( + 'Manage %s Attributes', + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()) + ); + + $this->_addButtonLabel = Mage::helper('eav')->__('Add New Attribute'); + + parent::__construct(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php new file mode 100644 index 000000000..c4d1c85ce --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php @@ -0,0 +1,86 @@ +entityType = Mage::registry('entity_type'); + $this->entityAttribute = Mage::registry('entity_attribute'); + + $this->_objectId = 'attribute_id'; + $this->_blockGroup = 'eav'; + $this->_controller = 'adminhtml_attribute'; + + parent::__construct(); + + $this->_addButton('save_and_edit_button', [ + 'label' => $this->__('Save and Continue Edit'), + 'onclick' => 'saveAndContinueEdit()', + 'class' => 'save' + ], 100); + + $this->_updateButton('save', 'label', $this->__('Save Attribute')); + $this->_updateButton('save', 'onclick', 'saveAttribute()'); + + if ($this->entityAttribute->getIsUserDefined()) { + $this->_updateButton('delete', 'label', $this->__('Delete Attribute')); + } else { + $this->_removeButton('delete'); + } + } + + /** + * @return string + */ + #[\Override] + public function getHeaderText() + { + if ($this->entityAttribute->getId()) { + return $this->__( + 'Edit %s Attribute "%s"', + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()), + $this->entityAttribute->getFrontendLabel() + ); + } + return $this->__( + 'New %s Attribute', + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()), + ); + } + + /** + * @return string + */ + public function getValidationUrl() + { + return $this->getUrl('*/*/validate', ['_current' => true]); + } + + /** + * @return string + */ + #[\Override] + public function getSaveUrl() + { + return $this->getUrl('*/*/save', ['_current' => true, 'back' => null]); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Form.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Form.php new file mode 100644 index 000000000..8d2c5bdc0 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Form.php @@ -0,0 +1,29 @@ + 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']); + $form->setUseContainer(true); + $this->setForm($form); + return parent::_prepareForm(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php index 57eeb94d1..f8b475888 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php @@ -11,17 +11,18 @@ */ /** - * Product attribute add/edit form main tab + * EAV attribute add/edit form main tab * * @category Mage * @package Mage_Eav */ -abstract class Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract extends Mage_Adminhtml_Block_Widget_Form +abstract class Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract extends Mage_Adminhtml_Block_Widget_Form implements Mage_Adminhtml_Block_Widget_Tab_Interface { + /** @var ?Mage_Eav_Model_Entity_Attribute $_attribute */ protected $_attribute = null; /** - * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute + * @param Mage_Eav_Model_Entity_Attribute $attribute * @return $this */ public function setAttributeObject($attribute) @@ -31,17 +32,42 @@ public function setAttributeObject($attribute) } /** - * @return Mage_Catalog_Model_Resource_Eav_Attribute + * @return Mage_Eav_Model_Entity_Attribute */ public function getAttributeObject() { return $this->_attribute ?? Mage::registry('entity_attribute'); } + #[\Override] + public function getTabLabel() + { + return Mage::helper('eav')->__('Properties'); + } + + #[\Override] + public function getTabTitle() + { + return Mage::helper('eav')->__('Properties'); + } + + #[\Override] + public function canShowTab() + { + return true; + } + + #[\Override] + public function isHidden() + { + return false; + } + #[\Override] protected function _prepareForm() { $attributeObject = $this->getAttributeObject(); + $entityTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); $form = new Varien_Data_Form([ 'id' => 'edit_form', @@ -49,6 +75,8 @@ protected function _prepareForm() 'method' => 'post' ]); + $form->setDataObject($attributeObject); + $fieldset = $form->addFieldset( 'base_fieldset', ['legend' => Mage::helper('eav')->__('Attribute Properties')] @@ -61,8 +89,6 @@ protected function _prepareForm() $this->_addElementTypes($fieldset); - $yesno = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(); - $validateClass = sprintf( 'validate-code validate-length maximum-length-%d', Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH @@ -71,80 +97,82 @@ protected function _prepareForm() 'name' => 'attribute_code', 'label' => Mage::helper('eav')->__('Attribute Code'), 'title' => Mage::helper('eav')->__('Attribute Code'), - 'note' => Mage::helper('eav')->__('For internal use. Must be unique with no spaces. Maximum length of attribute code must be less then %s symbols', Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH), + 'note' => Mage::helper('eav')->__( + 'For internal use. Must be unique with no spaces. Maximum length of attribute code must be less then %s symbols', + Mage_Eav_Model_Entity_Attribute::ATTRIBUTE_CODE_MAX_LENGTH + ), 'class' => $validateClass, 'required' => true, ]); - $inputTypes = Mage::getModel('eav/adminhtml_system_config_source_inputtype')->toOptionArray(); - $fieldset->addField('frontend_input', 'select', [ - 'name' => 'frontend_input', - 'label' => Mage::helper('eav')->__('Catalog Input Type for Store Owner'), - 'title' => Mage::helper('eav')->__('Catalog Input Type for Store Owner'), - 'value' => 'text', - 'values' => $inputTypes + 'name' => 'frontend_input', + 'label' => Mage::helper('eav')->__('Input Type'), + 'title' => Mage::helper('eav')->__('Input Type'), + 'values' => Mage::helper('eav')->getInputTypes($entityTypeCode), + 'value' => 'text', + ]); + + $fieldset->addField('frontend_class', 'select', [ + 'name' => 'frontend_class', + 'label' => Mage::helper('eav')->__('Input Validation'), + 'title' => Mage::helper('eav')->__('Input Validation'), + 'values' => Mage::helper('eav')->getFrontendClasses($entityTypeCode), + ]); + + $fieldset->addField('is_required', 'boolean', [ + 'name' => 'is_required', + 'label' => Mage::helper('eav')->__('Values Required'), + 'title' => Mage::helper('eav')->__('Values Required'), + ]); + + $fieldset->addField('is_unique', 'boolean', [ + 'name' => 'is_unique', + 'label' => Mage::helper('eav')->__('Unique Value'), + 'title' => Mage::helper('eav')->__('Unique Value'), + 'note' => Mage::helper('eav')->__( + 'Not shared with other %s', + strtolower(Mage::helper('eav')->formatTypeCode($entityTypeCode)) + ) ]); $fieldset->addField('default_value_text', 'text', [ - 'name' => 'default_value_text', + 'name' => 'default_value_text', 'label' => Mage::helper('eav')->__('Default Value'), 'title' => Mage::helper('eav')->__('Default Value'), 'value' => $attributeObject->getDefaultValue(), ]); - $fieldset->addField('default_value_yesno', 'select', [ - 'name' => 'default_value_yesno', + $fieldset->addField('default_value_yesno', 'boolean', [ + 'name' => 'default_value_yesno', 'label' => Mage::helper('eav')->__('Default Value'), 'title' => Mage::helper('eav')->__('Default Value'), - 'values' => $yesno, 'value' => $attributeObject->getDefaultValue(), ]); - $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $fieldset->addField('default_value_date', 'date', [ 'name' => 'default_value_date', 'label' => Mage::helper('eav')->__('Default Value'), 'title' => Mage::helper('eav')->__('Default Value'), 'value' => $attributeObject->getDefaultValue(), - 'format' => $dateFormatIso + 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), ]); $fieldset->addField('default_value_textarea', 'textarea', [ - 'name' => 'default_value_textarea', + 'name' => 'default_value_textarea', 'label' => Mage::helper('eav')->__('Default Value'), 'title' => Mage::helper('eav')->__('Default Value'), 'value' => $attributeObject->getDefaultValue(), ]); - $fieldset->addField('is_unique', 'select', [ - 'name' => 'is_unique', - 'label' => Mage::helper('eav')->__('Unique Value'), - 'title' => Mage::helper('eav')->__('Unique Value (not shared with other products)'), - 'note' => Mage::helper('eav')->__('Not shared with other products'), - 'values' => $yesno, - ]); - - $fieldset->addField('is_required', 'select', [ - 'name' => 'is_required', - 'label' => Mage::helper('eav')->__('Values Required'), - 'title' => Mage::helper('eav')->__('Values Required'), - 'values' => $yesno, - ]); - - $fieldset->addField('frontend_class', 'select', [ - 'name' => 'frontend_class', - 'label' => Mage::helper('eav')->__('Input Validation for Store Owner'), - 'title' => Mage::helper('eav')->__('Input Validation for Store Owner'), - 'values' => Mage::helper('eav')->getFrontendClasses($attributeObject->getEntityType()->getEntityTypeCode()) - ]); - - if ($attributeObject->getId()) { - $form->getElement('attribute_code')->setDisabled(1); - $form->getElement('frontend_input')->setDisabled(1); - if (!$attributeObject->getIsUserDefined()) { - $form->getElement('is_unique')->setDisabled(1); - } + if ($attributeObject->getResource()->hasFormTable()) { + $fieldset->addField('used_in_forms', 'multiselect', [ + 'name' => 'used_in_forms', + 'label' => Mage::helper('adminhtml')->__('Use in Forms'), + 'title' => Mage::helper('adminhtml')->__('Use in Forms'), + 'values' => Mage::helper('eav')->getForms($entityTypeCode), + 'value' => $attributeObject->getUsedInForms(), + ]); } $this->setForm($form); @@ -152,53 +180,100 @@ protected function _prepareForm() return parent::_prepareForm(); } + protected function _getDependence(): Mage_Adminhtml_Block_Widget_Form_Element_Dependence + { + if (!$this->getChild('form_after')) { + /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $block */ + $block = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence'); + $block->addConfigOption('on_event', false) + ->addFieldDependence('frontend_class', 'frontend_input', ['text', 'customselect']); + $this->setChild('form_after', $block); + } + return $this->getChild('form_after'); + } + #[\Override] protected function _initFormValues() { Mage::dispatchEvent('adminhtml_block_eav_attribute_edit_form_init', ['form' => $this->getForm()]); - $this->getForm() - ->addValues($this->getAttributeObject()->getData()); + + $attributeObject = $this->getAttributeObject(); + $data = $attributeObject->getData(); + + // If website specified, unprefix relevant fields before adding to form + if ($attributeObject->getWebsite() && (int)$attributeObject->getWebsite()->getId()) { + foreach ($attributeObject->getResource()->getScopeFields($attributeObject) as $field) { + if (array_key_exists('scope_' . $field, $data)) { + $data[$field] = $data['scope_' . $field]; + unset($data['scope_' . $field]); + } + } + } + + $this->getForm()->addValues($data); return parent::_initFormValues(); } - /** - * This method is called before rendering HTML - * - * @return Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract - */ #[\Override] protected function _beforeToHtml() { - parent::_beforeToHtml(); $attributeObject = $this->getAttributeObject(); + + // If entity type has a scoped table, change renderer to allow "Use Default Value" checkbox + // This must be called before parent::_beforeToHtml() + if (!Mage::app()->isSingleStoreMode() && $attributeObject->getResource()->hasScopeTable()) { + Varien_Data_Form::setFieldsetElementRenderer( + $this->getLayout()->createBlock('eav/adminhtml_attribute_edit_renderer_fieldset_element') + ); + } + + // Calls $this->_prepareForm() and $this->_initFormValues(); + parent::_beforeToHtml(); + + $form = $this->getForm(); + + // Disable any fields in config global/eav_attributes/$entity_type/$field/locked_fields if ($attributeObject->getId()) { - $form = $this->getForm(); $disableAttributeFields = Mage::helper('eav') ->getAttributeLockedFields($attributeObject->getEntityType()->getEntityTypeCode()); - if (isset($disableAttributeFields[$attributeObject->getAttributeCode()])) { - foreach ($disableAttributeFields[$attributeObject->getAttributeCode()] as $field) { - if ($elm = $form->getElement($field)) { - $elm->setDisabled(1); - $elm->setReadonly(1); - } + $disabledFields = $disableAttributeFields[$attributeObject->getAttributeCode()] ?? []; + + // Add in default locked fields + $disabledFields[] = 'attribute_code'; + $disabledFields[] = 'frontend_input'; + if (!$attributeObject->getIsUserDefined()) { + $disabledFields[] = 'is_unique'; + } + + foreach ($disabledFields as $field) { + if ($elm = $form->getElement($field)) { + $elm->setDisabled(1); + $elm->setReadonly(1); } } } - return $this; - } - /** - * Processing block html after rendering - * Adding js block to the end of this block - * - * @param string $html - * @return string - */ - #[\Override] - protected function _afterToHtml($html) - { - $jsScripts = $this->getLayout() - ->createBlock('eav/adminhtml_attribute_edit_js')->toHtml(); - return $html . $jsScripts; + // Set scope value and disable global fields if website selected + if ($attributeObject->getResource()->hasScopeTable()) { + $websiteId = $attributeObject->getWebsite() ? (int)$attributeObject->getWebsite()->getId() : 0; + $scopeFields = $attributeObject->getResource()->getScopeFields($attributeObject); + + /** @var Varien_Data_Form_Element_Fieldset $fieldset */ + $fieldset = $this->getForm()->getElement('base_fieldset'); + foreach ($fieldset->getElements() as $elm) { + $field = $elm->getId(); + if (str_starts_with($field, 'default_value')) { + $field = 'default_value'; + } + if (in_array($field, $scopeFields)) { + $elm->setScope(Mage_Eav_Model_Entity_Attribute::SCOPE_WEBSITE); + } else { + $elm->setScope(Mage_Eav_Model_Entity_Attribute::SCOPE_GLOBAL); + $elm->setDisabled($elm->getDisabled() || $websiteId); + } + } + } + + return $this; } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php index 301f3942f..da0f7a582 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php @@ -11,51 +11,78 @@ */ /** - * Attribute add/edit form options tab + * EAV Attribute add/edit form options tab * * @category Mage * @package Mage_Eav */ -abstract class Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract extends Mage_Adminhtml_Block_Widget +abstract class Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract extends Mage_Adminhtml_Block_Widget implements Mage_Adminhtml_Block_Widget_Tab_Interface { + /** @var ?Mage_Eav_Model_Entity_Attribute $_attribute */ + protected $_attribute = null; + public function __construct() { parent::__construct(); $this->setTemplate('eav/attribute/options.phtml'); } + /** + * @param Mage_Eav_Model_Entity_Attribute $attribute + * @return $this + */ + public function setAttributeObject($attribute) + { + $this->_attribute = $attribute; + return $this; + } + + /** + * @return Mage_Eav_Model_Entity_Attribute_Abstract + */ + public function getAttributeObject() + { + return $this->_attribute ?? Mage::registry('entity_attribute'); + } + + #[\Override] + public function getTabLabel() + { + return Mage::helper('eav')->__('Manage Label / Options'); + } + + #[\Override] + public function getTabTitle() + { + return Mage::helper('eav')->__('Manage Label / Options'); + } + + #[\Override] + public function canShowTab() + { + return true; + } + #[\Override] - protected function _prepareLayout() + public function isHidden() { - $this->setChild( - 'delete_button', - $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData([ - 'label' => Mage::helper('eav')->__('Delete'), - 'class' => 'delete delete-option' - ]) - ); - - $this->setChild( - 'add_button', - $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData([ - 'label' => Mage::helper('eav')->__('Add Option'), - 'class' => 'add', - 'id' => 'add_new_option_button' - ]) - ); - return parent::_prepareLayout(); + return false; } /** - * Retrieve HTML of delete button + * Retrieve HTML of delete button, returns new instance for each call so IDs are unique * * @return string */ public function getDeleteButtonHtml() { - return $this->getChildHtml('delete_button'); + /** @var Mage_Adminhtml_Block_Widget_Button $block */ + $block = $this->getLayout()->createBlock('adminhtml/widget_button'); + $block->setData([ + 'label' => Mage::helper('eav')->__('Delete'), + 'class' => 'delete delete-option' + ]); + return $block->toHtml(); } /** @@ -65,6 +92,16 @@ public function getDeleteButtonHtml() */ public function getAddNewButtonHtml() { + if (!$this->getChild('add_button')) { + /** @var Mage_Adminhtml_Block_Widget_Button $block */ + $block = $this->getLayout()->createBlock('adminhtml/widget_button'); + $block->setData([ + 'label' => Mage::helper('eav')->__('Add Option'), + 'class' => 'add', + 'id' => 'add_new_option_button' + ]); + $this->setChild('add_button', $block); + } return $this->getChildHtml('add_button'); } @@ -93,59 +130,55 @@ public function getStores() */ public function getOptionValues() { - $attributeType = $this->getAttributeObject()->getFrontendInput(); - $defaultValues = $this->getAttributeObject()->getDefaultValue(); - if ($attributeType === 'select' || $attributeType === 'multiselect') { - $defaultValues = explode(',', (string)$defaultValues); - } else { - $defaultValues = []; + $values = $this->getData('option_values'); + if (!is_null($values)) { + return $values; } + $values = []; - switch ($attributeType) { - case 'select': - $inputType = 'radio'; - break; - case 'multiselect': - $inputType = 'checkbox'; - break; - default: - $inputType = ''; - break; - } + $attributeObject = $this->getAttributeObject(); + $entityTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); + $inputType = $attributeObject->getFrontendInput(); + + // Get global/eav_inputtypes/$inputType/options_panel config.xml node + $optionsInfo = Mage::helper('eav')->getInputTypeOptionsPanelInfo($entityTypeCode)[$inputType] ?? []; + + if (!empty($optionsInfo)) { + $defaultValues = explode(',', (string)$attributeObject->getDefaultValue()); - $values = $this->getData('option_values'); - if (is_null($values)) { - $values = []; $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection') - ->setAttributeFilter($this->getAttributeObject()->getId()) + ->setAttributeFilter($attributeObject->getId()) ->setPositionOrder('desc', true) ->load(); - $helper = Mage::helper('core'); /** @var Mage_Eav_Model_Entity_Attribute_Option $option */ foreach ($optionCollection as $option) { - $value = []; + $value = new Varien_Object(); if (in_array($option->getId(), $defaultValues)) { $value['checked'] = 'checked="checked"'; } else { $value['checked'] = ''; } - $value['intype'] = $inputType; + $value['intype'] = $optionsInfo['intype']; $value['id'] = $option->getId(); $value['sort_order'] = $option->getSortOrder(); foreach ($this->getStores() as $store) { $storeValues = $this->getStoreOptionValues($store->getId()); - $value['store' . $store->getId()] = isset($storeValues[$option->getId()]) - ? $helper->escapeHtml($storeValues[$option->getId()]) : ''; + if (isset($storeValues[$option->getId()])) { + $value['store' . $store->getId()] = Mage::helper('core')->escapeHtml($storeValues[$option->getId()]); + } else { + $value['store' . $store->getId()] = ''; + } } if ($this->isConfigurableSwatchesEnabled()) { $value['swatch'] = $option->getSwatchValue(); } - $values[] = new Varien_Object($value); + $values[] = $value; } - $this->setData('option_values', $values); } + + $this->setData('option_values', $values); return $values; } @@ -195,16 +228,6 @@ public function getStoreOptionValues($storeId) return $values; } - /** - * Retrieve attribute object from registry - * - * @return Mage_Eav_Model_Entity_Attribute_Abstract - */ - public function getAttributeObject() - { - return Mage::registry('entity_attribute'); - } - /** * Check if configurable swatches module is enabled and attribute is swatch type */ diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Renderer/Fieldset/Element.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Renderer/Fieldset/Element.php new file mode 100644 index 000000000..ebaef2334 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Renderer/Fieldset/Element.php @@ -0,0 +1,81 @@ +setTemplate('eav/attribute/edit/renderer/fieldset/element.phtml'); + } + + /** + * Check "Use default" checkbox display availability + */ + public function canDisplayUseDefault(): bool + { + $attributeObject = $this->getElement()->getForm()->getDataObject(); + if ($attributeObject->getWebsite() && (int)$attributeObject->getWebsite()->getId()) { + return $this->getElement()->getScope() === Mage_Eav_Model_Entity_Attribute::SCOPE_WEBSITE; + } + return false; + } + + /** + * Check default value usage fact + */ + public function usedDefault(): bool + { + $field = $this->getElement()->getId(); + if (str_starts_with($field, 'default_value')) { + $field = 'default_value'; + } + $attributeObject = $this->getElement()->getForm()->getDataObject(); + return is_null($attributeObject->getData('scope_' . $field)); + } + + /** + * Disable field in default value using case + */ + public function checkFieldDisable(): self + { + if ($this->canDisplayUseDefault() && $this->usedDefault()) { + $this->getElement()->setDisabled(true); + } + return $this; + } + + /** + * Retrieve label of attribute scope + * + * GLOBAL | WEBSITE + */ + public function getScopeLabel(): string + { + $html = ''; + if (Mage::app()->isSingleStoreMode()) { + return $html; + } + if ($this->getElement()->getScope() === Mage_Eav_Model_Entity_Attribute::SCOPE_GLOBAL) { + $html .= Mage::helper('adminhtml')->__('[GLOBAL]'); + } elseif ($this->getElement()->getScope() === Mage_Eav_Model_Entity_Attribute::SCOPE_WEBSITE) { + $html .= Mage::helper('adminhtml')->__('[WEBSITE]'); + } + return $html; + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Main.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Main.php new file mode 100644 index 000000000..fb0c364a7 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Main.php @@ -0,0 +1,44 @@ +getAttributeObject(); + $attributeTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); + + /** @var Varien_Data_Form $form */ + $form = $this->getForm(); + + /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $block */ + $block = $this->_getDependence(); + + Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_edit_prepare_form", [ + 'form' => $form, + 'attribute' => $attributeObject, + 'dependence' => $block, + ]); + + $this->setChild('form_after', $block); + + return $this; + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Options.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Options.php new file mode 100644 index 000000000..119086c83 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Options.php @@ -0,0 +1,18 @@ +entityType = Mage::registry('entity_type'); + $this->entityAttribute = Mage::registry('entity_attribute'); + + parent::__construct(); + + $this->setId('eav_attribute_tabs'); + $this->setDestElementId('edit_form'); + $this->setTitle(Mage::helper('eav')->__('Attribute Information')); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php new file mode 100644 index 000000000..a61ae35b4 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php @@ -0,0 +1,35 @@ +getHiddenAttributes($this->entityType->getEntityTypeCode()); + + /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection */ + $collection = Mage::getResourceModel($this->entityType->getEntityAttributeCollection()); + $collection->setEntityTypeFilter($this->entityType->getEntityTypeId()) + ->setNotCodeFilter($hiddenAttributes) + ->addVisibleFilter(); + + $this->setCollection($collection); + return parent::_prepareCollection(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid/Abstract.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid/Abstract.php index 81829b849..f4ea3bb1e 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid/Abstract.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid/Abstract.php @@ -11,19 +11,24 @@ */ /** - * Product attributes grid + * Adminhtml generic EAV attribute grid abstract class * * @category Mage - * @package Mage_Adminhtml + * @package Mage_Eav */ abstract class Mage_Eav_Block_Adminhtml_Attribute_Grid_Abstract extends Mage_Adminhtml_Block_Widget_Grid { + protected Mage_Eav_Model_Entity_Type $entityType; + public function __construct() { - parent::__construct(); - $this->setId('attributeGrid'); + $this->entityType = Mage::registry('entity_type'); + + $this->setId('attributeGrid_' . $this->entityType->getEntityTypeCode()); $this->setDefaultSort('frontend_label'); $this->setDefaultDir('ASC'); + + parent::__construct(); } /** @@ -63,8 +68,8 @@ protected function _prepareColumns() 'type' => 'options', 'align' => 'center', 'options' => [ - '0' => Mage::helper('eav')->__('Yes'), // intended reverted use - '1' => Mage::helper('eav')->__('No'), // intended reverted use + '0' => Mage::helper('eav')->__('Yes'), // intended reversed use + '1' => Mage::helper('eav')->__('No'), // intended reversed use ], ]); @@ -74,7 +79,7 @@ protected function _prepareColumns() /** * Return url of given row * - * @param Mage_Catalog_Model_Resource_Eav_Attribute $row + * @param Mage_Eav_Model_Entity_Attribute $row * @return string */ #[\Override] diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php new file mode 100644 index 000000000..5c5ae0e9b --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php @@ -0,0 +1,39 @@ +entityType = Mage::registry('entity_type'); + + $this->_blockGroup = 'eav'; + $this->_controller = 'adminhtml_attribute_set'; + + $this->_headerText = $this->__( + 'Manage %s Attribute Sets', + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()) + ); + + $this->_addButtonLabel = Mage::helper('eav')->__('Add New Set'); + parent::__construct(); + } + + #[\Override] + public function getCreateUrl() + { + return $this->getUrl('*/*/add'); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Add.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Add.php new file mode 100644 index 000000000..468d1fc17 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Add.php @@ -0,0 +1,93 @@ +entityType = Mage::registry('entity_type'); + $this->setTemplate('eav/attribute/set/add.phtml'); + parent::__construct(); + } + + #[\Override] + protected function _prepareLayout() + { + $this->setChild( + 'save_button', + $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData([ + 'label' => Mage::helper('eav')->__('Save Attribute Set'), + 'onclick' => 'if (addSet.submit()) disableElements(\'save\');', + 'class' => 'save' + ]) + ); + $this->setChild( + 'back_button', + $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData([ + 'label' => Mage::helper('eav')->__('Back'), + 'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/')), + 'class' => 'back' + ]) + ); + return parent::_prepareLayout(); + } + + /** + * @return string + */ + protected function _getHeader() + { + return Mage::helper('eav')->__( + 'Add New %s Attribute Set', + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()) + ); + } + + /** + * @return string + */ + protected function getSaveButtonHtml() + { + return $this->getChildHtml('save_button'); + } + + /** + * @return string + */ + protected function getBackButtonHtml() + { + return $this->getChildHtml('back_button'); + } + + /** + * @return string + */ + protected function getFormHtml() + { + return $this->getChildHtml('set_form'); + } + + /** + * @return string + */ + protected function getFormId() + { + return $this->getChild('set_form')->getForm()->getId(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit.php new file mode 100644 index 000000000..ae0fa60b4 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit.php @@ -0,0 +1,411 @@ +entityType = Mage::registry('entity_type'); + $this->attributeSet = Mage::registry('current_attribute_set'); + $this->setTemplate('eav/attribute/set/edit.phtml'); + parent::__construct(); + } + + /** + * Prepare Global Layout + * + * @return $this + */ + #[\Override] + protected function _prepareLayout() + { + $this->setChild( + 'delete_group_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ + 'label' => Mage::helper('eav')->__('Delete Selected Group'), + 'onclick' => 'editSet.submit();', + 'class' => 'delete' + ]) + ); + + $this->setChild( + 'add_group_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ + 'label' => Mage::helper('eav')->__('Add New'), + 'onclick' => 'editSet.addGroup();', + 'class' => 'add' + ]) + ); + + $this->setChild( + 'back_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ + 'label' => Mage::helper('eav')->__('Back'), + 'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/')), + 'class' => 'back' + ]) + ); + + $this->setChild( + 'reset_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ + 'label' => Mage::helper('eav')->__('Reset'), + 'onclick' => 'window.location.reload()' + ]) + ); + + $this->setChild( + 'save_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ + 'label' => Mage::helper('eav')->__('Save Attribute Set'), + 'onclick' => 'editSet.save();', + 'class' => 'save' + ]) + ); + + $this->setChild( + 'delete_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ + 'label' => Mage::helper('eav')->__('Delete Attribute Set'), + 'onclick' => Mage::helper('core/js')->getDeleteConfirmJs( + $this->getUrlSecure('*/*/delete', ['id' => $this->_getSetId()]), + Mage::helper('eav')->__('Are you sure you want to delete this attribute set?') + ), + 'class' => 'delete' + ]) + ); + + $this->setChild( + 'rename_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ + 'label' => Mage::helper('eav')->__('New Set Name'), + 'onclick' => 'editSet.rename()' + ]) + ); + + return parent::_prepareLayout(); + } + + /** + * Retrieve Attribute Set Group Tree HTML + * + * @return string + */ + public function getGroupTreeHtml() + { + return $this->getChildHtml('group_tree'); + } + + /** + * Retrieve Attribute Set Edit Form HTML + * + * @return string + */ + public function getSetFormHtml() + { + return $this->getChildHtml('set_form'); + } + + /** + * Retrieve Block Header Text + * + * @return string + */ + protected function _getHeader() + { + return Mage::helper('eav')->__( + "Manage %s Attribute Set '%s'", + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()), + $this->_getAttributeSet()->getAttributeSetName() + ); + } + + /** + * Retrieve Attribute Set Save URL + * + * @return string + */ + public function getMoveUrl() + { + return $this->getUrl('*/*/save', ['id' => $this->_getSetId()]); + } + + /** + * Retrieve Attribute Set Group Save URL + * + * @return string + */ + public function getGroupUrl() + { + return $this->getUrl('*/*/save', ['id' => $this->_getSetId()]); + } + + /** + * Load all attributes including info about all sets they belong to + */ + protected function getEntityAttributeCollection(): Mage_Eav_Model_Resource_Entity_Attribute_Collection + { + // Get global/eav_attributes/$entityType/$attributeCode/hidden config.xml nodes + $hiddenAttributes = Mage::helper('eav')->getHiddenAttributes($this->entityType->getEntityTypeCode()); + + /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection */ + $collection = Mage::getResourceModel($this->entityType->getEntityAttributeCollection()); + $collection->setEntityTypeFilter($this->entityType->getEntityTypeId()) + ->setOrder('attribute_code', 'asc') + ->setNotCodeFilter($hiddenAttributes) + ->addVisibleFilter() + ->addSetInfo(true) + ->load(); + + return $collection; + } + + /** + * Retrieve Attribute Set Group Tree + */ + protected function getGroupTree(): array + { + $items = []; + $setId = $this->_getSetId(); + + /** @var Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection $groups */ + $groups = Mage::getModel('eav/entity_attribute_group') + ->getResourceCollection() + ->setAttributeSetFilter($setId) + ->setSortOrder() + ->load(); + + /** @var Mage_Eav_Model_Entity_Attribute_Group $group */ + foreach ($groups as $group) { + $item = []; + $item['text'] = $group->getAttributeGroupName(); + $item['id'] = $group->getAttributeGroupId(); + $item['cls'] = 'folder'; + $item['allowDrop'] = true; + $item['allowDrag'] = true; + $item['children'] = []; + + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + foreach ($this->getEntityAttributeCollection()->getItems() as $attribute) { + $attributeGroupId = $attribute['attribute_set_info'][$setId]['group_id'] ?? null; + if ($attributeGroupId === $group->getId()) { + $item['children'][] = [ + 'text' => $attribute->getAttributeCode(), + 'id' => $attribute->getAttributeId(), + 'cls' => (!$attribute->getIsUserDefined()) ? 'system-leaf' : 'leaf', + 'allowDrop' => false, + 'allowDrag' => true, + 'leaf' => true, + 'is_user_defined' => $attribute->getIsUserDefined(), + 'entity_id' => $attribute->getEntityAttributeId(), + 'sort' => $attribute['attribute_set_info'][$setId]['sort'], + ]; + } + } + + // Sort attributes by sort key + array_multisort(array_column($item['children'], 'sort'), $item['children']); + + $items[] = $item; + } + + return $items; + } + + /** + * Retrieve Unused in Attribute Set Attribute Tree + */ + protected function getAttributeTree(): array + { + $items = []; + $setId = $this->_getSetId(); + + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + foreach ($this->getEntityAttributeCollection()->getItems() as $sort => $attribute) { + if (!isset($attribute['attribute_set_info'][$setId])) { + $items[] = [ + 'text' => $attribute->getAttributeCode(), + 'id' => $attribute->getAttributeId(), + 'cls' => 'leaf', + 'allowDrop' => false, + 'allowDrag' => true, + 'leaf' => true, + 'is_user_defined' => $attribute->getIsUserDefined(), + 'entity_id' => $attribute->getEntityId(), + 'sort' => $sort, + ]; + } + } + + if (count($items) === 0) { + $items[] = [ + 'text' => Mage::helper('eav')->__('Empty'), + 'id' => 'empty', + 'cls' => 'folder', + 'allowDrop' => false, + 'allowDrag' => false, + ]; + } + + return $items; + } + + /** + * Retrieve Attribute Set Group Tree as JSON format + * + * @return string + */ + public function getGroupTreeJson() + { + return Mage::helper('core')->jsonEncode($this->getGroupTree()); + } + + /** + * Retrieve Unused in Attribute Set Attribute Tree as JSON + * + * @return string + */ + public function getAttributeTreeJson() + { + return Mage::helper('core')->jsonEncode($this->getAttributeTree()); + } + + /** + * Retrieve Back Button HTML + * + * @return string + */ + public function getBackButtonHtml() + { + return $this->getChildHtml('back_button'); + } + + /** + * Retrieve Reset Button HTML + * + * @return string + */ + public function getResetButtonHtml() + { + return $this->getChildHtml('reset_button'); + } + + /** + * Retrieve Save Button HTML + * + * @return string + */ + public function getSaveButtonHtml() + { + return $this->getChildHtml('save_button'); + } + + /** + * Retrieve Delete Button HTML + * + * @return string + */ + public function getDeleteButtonHtml() + { + if ($this->getIsCurrentSetDefault()) { + return ''; + } + return $this->getChildHtml('delete_button'); + } + + /** + * Retrieve Delete Group Button HTML + * + * @return string + */ + public function getDeleteGroupButton() + { + return $this->getChildHtml('delete_group_button'); + } + + /** + * Retrieve Add New Group Button HTML + * + * @return string + */ + public function getAddGroupButton() + { + return $this->getChildHtml('add_group_button'); + } + + /** + * Retrieve Rename Button HTML + * + * @return string + */ + public function getRenameButton() + { + return $this->getChildHtml('rename_button'); + } + + /** + * Retrieve current Attribute Set object + * + * @return Mage_Eav_Model_Entity_Attribute_Set + */ + protected function _getAttributeSet() + { + return $this->attributeSet; + } + + /** + * Retrieve current attribute set Id + * + * @return int + */ + protected function _getSetId() + { + return $this->_getAttributeSet()->getId(); + } + + /** + * Check Current Attribute Set is a default + * + * @return bool + */ + public function getIsCurrentSetDefault() + { + $isDefault = $this->getData('is_current_set_default'); + if (is_null($isDefault)) { + $defaultSetId = $this->entityType->getDefaultAttributeSetId(); + $isDefault = $this->_getSetId() == $defaultSetId; + $this->setData('is_current_set_default', $isDefault); + } + return $isDefault; + } + + /** + * Prepare HTML + * + * @return string + */ + #[\Override] + protected function _toHtml() + { + $entityTypeCode = $this->entityType->getEntityTypeCode(); + Mage::dispatchEvent("adminhtml_{$entityTypeCode}_attribute_set_main_html_before", ['block' => $this]); + return parent::_toHtml(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Formset.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Formset.php new file mode 100644 index 000000000..fa192a167 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Formset.php @@ -0,0 +1,72 @@ +entityType = Mage::registry('entity_type'); + parent::__construct(); + } + + #[\Override] + protected function _prepareForm() + { + $data = Mage::getModel('eav/entity_attribute_set') + ->load($this->getRequest()->getParam('id')); + + $form = new Varien_Data_Form(); + + $fieldset = $form->addFieldset('set_name', ['legend' => Mage::helper('eav')->__('Edit Set Name')]); + $fieldset->addField('attribute_set_name', 'text', [ + 'label' => Mage::helper('eav')->__('Name'), + 'name' => 'attribute_set_name', + 'required' => true, + 'class' => 'required-entry validate-no-html-tags', + 'value' => $data->getAttributeSetName() + ]); + + if (!$this->getRequest()->getParam('id', false)) { + $fieldset->addField('gotoEdit', 'hidden', [ + 'name' => 'gotoEdit', + 'value' => '1' + ]); + + $sets = $this->entityType->getAttributeSetCollection() + ->setOrder('attribute_set_name', 'asc') + ->load() + ->toOptionArray(); + + $fieldset->addField('skeleton_set', 'select', [ + 'label' => Mage::helper('eav')->__('Based On'), + 'name' => 'skeleton_set', + 'required' => true, + 'class' => 'required-entry', + 'values' => $sets, + ]); + } + + $form->setMethod('post'); + $form->setUseContainer(true); + $form->setId('set_prop_form'); + $form->setAction($this->getUrl('*/*/save')); + $form->setOnsubmit('return false;'); + $this->setForm($form); + return $this; + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Tree/Group.php similarity index 55% rename from app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php rename to app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Tree/Group.php index 9830d7c65..b190d9ed9 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Tree/Group.php @@ -5,21 +5,19 @@ * @category Mage * @package Mage_Eav * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) - * @copyright Copyright (c) 2022-2023 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * Eav Attribute Block with additional js scripts in template - * * @category Mage * @package Mage_Eav */ -class Mage_Eav_Block_Adminhtml_Attribute_Edit_Js extends Mage_Adminhtml_Block_Template +class Mage_Eav_Block_Adminhtml_Attribute_Set_Edit_Tree_Group extends Mage_Adminhtml_Block_Template { public function __construct() { + $this->setTemplate('eav/attribute/set/edit/tree/group.phtml'); parent::__construct(); - $this->setTemplate('eav/attribute/edit/js.phtml'); } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php new file mode 100644 index 000000000..4a6c58be6 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php @@ -0,0 +1,60 @@ +entityType = Mage::registry('entity_type'); + + $this->setId('attributeSetGrid_' . $this->entityType->getEntityTypeCode()); + $this->setDefaultSort('set_name'); + $this->setDefaultDir('ASC'); + $this->setSaveParametersInSession(true); + + parent::__construct(); + } + + #[\Override] + protected function _prepareCollection() + { + /** @var Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection $collection */ + $collection = $this->entityType->getAttributeSetCollection(); + + $this->setCollection($collection); + + return parent::_prepareCollection(); + } + + #[\Override] + protected function _prepareColumns() + { + $this->addColumn('set_name', [ + 'header' => Mage::helper('eav')->__('Set Name'), + 'align' => 'left', + 'index' => 'attribute_set_name', + ]); + + return $this; + } + + #[\Override] + public function getRowUrl($row) + { + return $this->getUrl('*/*/edit', ['id' => $row->getAttributeSetId()]); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form.php b/app/code/core/Mage/Eav/Block/Widget/Form.php new file mode 100644 index 000000000..32de670b8 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form.php @@ -0,0 +1,199 @@ +setTemplate('eav/widget/form.phtml'); + } + + public function setDefaultLabel(string $label): self + { + $this->defaultLabel = $label; + return $this; + } + + public function setGroupMode(string $mode): self + { + $this->groupMode = $mode; + return $this; + } + + public function setFieldsetType(string $type): self + { + $this->fieldsetType = $type; + return $this; + } + + public function setForm(Mage_Eav_Model_Form $form): self + { + $this->form = $form; + return $this; + } + + public function mergeFormAttributes(Mage_Eav_Model_Form $form): self + { + $this->mergedForms[] = $form; + $this->attributes = null; + return $this; + } + + public function excludeFormAttributes(Mage_Eav_Model_Form $form): self + { + $this->excludedForms[] = $form; + $this->attributes = null; + return $this; + } + + public function getAttributes(): array + { + if ($this->attributes !== null) { + return $this->attributes; + } + + $this->attributes = $this->form->getAttributes(); + + foreach ($this->mergedForms as $form) { + foreach ($form->getAttributes() as $code => $attribute) { + if (!isset($this->attributes[$code])) { + $this->attributes[$code] = $attribute; + $this->attributeObjects[$code] = $form->getEntity(); + } + } + } + + foreach ($this->excludedForms as $form) { + foreach (array_keys($form->getAttributes()) as $code) { + unset($this->attributes[$code]); + } + } + + return $this->attributes; + } + + public function getGroupedAttributes(): array + { + $groups = []; + foreach ($this->getAttributes() as $code => $attribute) { + $group = $attribute->getAttributeGroupName() ?? 'General'; + $groups[$group] ??= []; + $groups[$group][$code] = $attribute; + } + return $groups; + } + + public function hasAttribute(string $code): bool + { + $attributes = $this->getAttributes(); + return isset($attributes[$code]); + } + + protected function getFieldsetRenderer(): Mage_Core_Block_Template|false + { + return $this->getLayout()->createBlock('eav/widget_form_element_fieldset'); + } + + protected function getFieldsetElementRenderer(Mage_Eav_Model_Attribute $attribute): Mage_Eav_Block_Widget_Form_Element_Abstract|false + { + if ($attribute->getAttributeCode() === 'country_id') { + return $this->getLayout()->createBlock('eav/widget_form_element_country'); + } + if ($attribute->getAttributeCode() === 'region' && $this->hasAttribute('region_id')) { + return $this->getLayout()->createBlock('eav/widget_form_element_region'); + } + if ($attribute->getAttributeCode() === 'region_id' && $this->hasAttribute('region')) { + return false; + } + if ($attribute->getAttributeCode() === 'postcode') { + return $this->getLayout()->createBlock('eav/widget_form_element_postcode'); + } + return $this->getLayout()->createBlock('eav/widget_form_element_' . $attribute->getFrontendInput()); + } + + protected function showRequired(): bool + { + foreach ($this->getAttributes() as $attribute) { + if ($attribute->getIsRequired()) { + return true; + } + } + return false; + } + + #[\Override] + protected function _beforeToHtml() + { + $groups = $this->getGroupedAttributes(); + + if ($this->groupMode === self::GROUP_MODE_FLAT) { + $groups = [ + array_key_first($groups) => array_merge(...array_values($groups)) + ]; + } + + foreach ($groups as $label => $attributes) { + $fieldset = $this->getFieldsetRenderer(); + $fieldset->setType($this->fieldsetType); + $fieldset->setLabel($label); + $fieldset->setTranslationHelper($this->getTranslationHelper()); + + if ($label === array_key_first($groups)) { + $fieldset->setLabel($this->defaultLabel ?? $label); + $fieldset->setIsRequired($this->showRequired()); + } + $this->append($fieldset); + + foreach ($attributes as $code => $attribute) { + if ($element = $this->getFieldsetElementRenderer($attribute)) { + $element->setData('attribute', $attribute); + $element->setObject($this->attributeObjects[$code] ?? $this->form->getEntity()); + $element->setTranslationHelper($this->getTranslationHelper()); + $element->setFieldIdFormat($this->getFieldIdFormat()); + $element->setFieldNameFormat($this->getFieldNameFormat()); + + if ($element->isEnabled()) { + $fieldset->append($element); + } + } + } + } + return parent::_beforeToHtml(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Abstract.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Abstract.php new file mode 100644 index 000000000..134c8bab5 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Abstract.php @@ -0,0 +1,96 @@ +getAttribute()->getIsVisible(); + } + + public function isRequired(): bool + { + return (bool)$this->getAttribute()->getIsRequired(); + } + + public function getValue(): mixed + { + return $this->getObject()->getData($this->getAttribute()->getAttributeCode()); + } + + public function getClass(): string + { + return $this->getAttribute()->getFrontend()->getClass(); + } + + public function getLabel(): string + { + return $this->__($this->getAttribute()->getStoreLabel()); + } + + public function getLabelClass(): string + { + return $this->isRequired() ? 'required' : ''; + } + + public function getFieldIdFormat(): string + { + if (empty($this->getData('field_id_format'))) { + $this->setData('field_id_format', '%s'); + } + return $this->getData('field_id_format'); + } + + public function setFieldId(string $value): self + { + $this->fieldId = $value; + return $this; + } + + public function getFieldId(?string $attributeCode = null): string + { + $fieldId = $attributeCode ?? $this->fieldId ?? $this->getAttribute()->getAttributeCode(); + return sprintf($this->getFieldIdFormat(), $fieldId); + } + + public function getFieldNameFormat(): string + { + if (empty($this->getData('field_name_format'))) { + $this->setData('field_name_format', '%s'); + } + return $this->getData('field_name_format'); + } + + public function setFieldName(string $value): self + { + $this->fieldName = $value; + return $this; + } + + public function getFieldName(?string $attributeCode = null): string + { + $fieldName = $attributeCode ?? $this->fieldName ?? $this->getAttribute()->getAttributeCode(); + return sprintf($this->getFieldNameFormat(), $fieldName); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Boolean.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Boolean.php new file mode 100644 index 000000000..53ebdf984 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Boolean.php @@ -0,0 +1,33 @@ +setTemplate('eav/widget/form/element/boolean.phtml'); + } + + public function getOptions(): array + { + $options = [ + ['value' => '', 'label' => $this->__('')], + ['value' => '1', 'label' => $this->__('Yes')], + ['value' => '0', 'label' => $this->__('No')] + ]; + + return $options; + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Country.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Country.php new file mode 100644 index 000000000..49a21037e --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Country.php @@ -0,0 +1,45 @@ +setFieldId('country'); + $this->setTemplate('eav/widget/form/element/country.phtml'); + } + + public function getCountryId(): string + { + if ($countryId = $this->getObject()->getCountryId()) { + return $countryId; + } + return Mage::helper('core')->getDefaultCountry(); + } + + public function getCountryHtmlSelect(): string + { + $block = $this->getLayout()->createBlock('directory/data'); + $block->setTranslationHelper($this->getTranslationHelper()); + + return $block->getCountryHtmlSelect( + $this->getCountryId(), + $this->getFieldName(), + $this->getFieldId(), + $this->getLabel() + ); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Customselect.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Customselect.php new file mode 100644 index 000000000..ba38974bb --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Customselect.php @@ -0,0 +1,41 @@ +setTemplate('eav/widget/form/element/customselect.phtml'); + } + + public function getOptions(): array + { + return $this->getAttribute()->getSource()->getAllOptions(false); + } + + public function getDatalistIdFormat(): string + { + if (!$this->hasData('datalist_id_format')) { + $this->setData('datalist_id_format', '%s__datalist'); + } + return $this->getData('datalist_id_format'); + } + + public function getDatalistId(?string $attributeCode = null): string + { + $fieldName = $attributeCode ?? $this->fieldName ?? $this->getAttribute()->getAttributeCode(); + return sprintf($this->getDatalistIdFormat(), $fieldName); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Date.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Date.php new file mode 100644 index 000000000..64dc02b18 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Date.php @@ -0,0 +1,130 @@ +setTemplate('eav/widget/form/element/date.phtml'); + } + + /** + * @param string $date + * @return $this + */ + public function setDate($date) + { + if ($date) { + try { + $dateTime = new DateTime($date); + $this->setTime($dateTime); + } catch (Exception $e) { + Mage::logException($e); + } + } + + $this->setData('date', $date); + + return $this; + } + + /** + * @return bool + */ + public function hasTime() + { + return $this->getTime() instanceof DateTime; + } + + /** + * @return string + */ + public function getDay() + { + return $this->hasTime() ? $this->getTime()->format('d') : ''; + } + + /** + * @return string + */ + public function getMonth() + { + return $this->hasTime() ? $this->getTime()->format('m') : ''; + } + + /** + * @return string + */ + public function getYear() + { + return $this->hasTime() ? $this->getTime()->format('Y') : ''; + } + + /** + * Returns format which will be applied for date in javascript + * + * @return string + */ + public function getDateFormat() + { + return Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); + } + + /** + * Add date input html + * + * @param string $code + * @param string $html + */ + public function setDateInput($code, $html) + { + $this->_dateInputs[$code] = $html . "\n"; + } + + /** + * Sort date inputs by dateformat order of current locale + * + * @return string + */ + public function getSortedDateInputs() + { + $strtr = [ + '%b' => '%1$s', + '%B' => '%1$s', + '%m' => '%1$s', + '%d' => '%2$s', + '%e' => '%2$s', + '%Y' => '%3$s', + '%y' => '%3$s' + ]; + + $dateFormat = preg_replace('/[^\%\w]/', '\\1', $this->getDateFormat()); + + return sprintf( + strtr($dateFormat, $strtr), + $this->_dateInputs['m'], + $this->_dateInputs['d'], + $this->_dateInputs['y'] + ); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Fieldset.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Fieldset.php new file mode 100644 index 000000000..fba0c1216 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Fieldset.php @@ -0,0 +1,59 @@ +setTemplate('eav/widget/form/element/fieldset.phtml'); + } + + public function getLabel(): string + { + return $this->__($this->getData('label')); + } + + public function setType(string $type): self + { + $this->type = $type; + return $this; + } + + public function getWrapperTags(): array + { + switch ($this->type) { + case Mage_Eav_Block_Widget_Form::FIELDSET_TYPE_DIV: + return [ + ['
', '
'], + ['
', '
'], + ]; + case Mage_Eav_Block_Widget_Form::FIELDSET_TYPE_LI_WIDE: + return [ + ['
    ', '
'], + ['
  • ', '
  • '], + ]; + case Mage_Eav_Block_Widget_Form::FIELDSET_TYPE_LI: + default: + return [ + ['
      ', '
    '], + ['
  • ', '
  • '], + ]; + } + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Hidden.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Hidden.php new file mode 100644 index 000000000..ae9a9fd6b --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Hidden.php @@ -0,0 +1,22 @@ +setTemplate('eav/widget/form/element/hidden.phtml'); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiline.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiline.php new file mode 100644 index 000000000..cf703348d --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiline.php @@ -0,0 +1,51 @@ +setTemplate('eav/widget/form/element/multiline.phtml'); + } + + public function getFields(): array + { + $attribute = $this->getAttribute(); + $code = $attribute->getAttributeCode(); + $values = explode("\n", $this->getObject()->getData($code)); + + $fields = []; + for ($i = 1; $i <= $attribute->getMultilineCount(); $i++) { + $field = new Varien_Object(); + $field->setFieldId($this->getFieldId($code) . "_$i"); + $field->setFieldName($this->getFieldName($code) . '[]'); + $field->setValue($values[$i - 1] ?? null); + + if ($i === 1) { + $field->setIsRequired($this->isRequired()); + $field->setClass($attribute->getFrontend()->getClass()); + $field->setLabel($this->__($attribute->getStoreLabel())); + $field->setLabelClass($this->isRequired()); + } else { + $field->setIsRequired(false); + $field->setClass(trim(str_replace('required-entry', '', $attribute->getFrontend()->getClass()))); + $field->setLabel($this->__($attribute->getStoreLabel() . ' %s', $i)); + $field->setLabelClass(''); + } + $fields[$i] = $field; + } + return $fields; + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiselect.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiselect.php new file mode 100644 index 000000000..9128106d6 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiselect.php @@ -0,0 +1,32 @@ +setTemplate('eav/widget/form/element/multiselect.phtml'); + } + + public function getFieldParams(): string + { + return 'multiple'; + } + + public function getOptions(): array + { + return $this->getAttribute()->getSource()->getAllOptions(false); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Postcode.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Postcode.php new file mode 100644 index 000000000..231215856 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Postcode.php @@ -0,0 +1,23 @@ +setFieldId('zip'); + $this->setTemplate('eav/widget/form/element/postcode.phtml'); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Region.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Region.php new file mode 100644 index 000000000..be4c535a5 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Region.php @@ -0,0 +1,27 @@ +setTemplate('eav/widget/form/element/region.phtml'); + } + + public function getRegionId(): int + { + return $this->getObject()->getRegionId(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Select.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Select.php new file mode 100644 index 000000000..67469ba56 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Select.php @@ -0,0 +1,27 @@ +setTemplate('eav/widget/form/element/select.phtml'); + } + + public function getOptions(): array + { + return $this->getAttribute()->getSource()->getAllOptions(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Text.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Text.php new file mode 100644 index 000000000..4cdd692a0 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Text.php @@ -0,0 +1,22 @@ +setTemplate('eav/widget/form/element/text.phtml'); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Textarea.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Textarea.php new file mode 100644 index 000000000..6465a4783 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Textarea.php @@ -0,0 +1,22 @@ +setTemplate('eav/widget/form/element/textarea.phtml'); + } +} diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php new file mode 100644 index 000000000..59f2ed52c --- /dev/null +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -0,0 +1,342 @@ +entityType = Mage::getSingleton('eav/config')->getEntityType($this->entityTypeCode); + Mage::register('entity_type', $this->entityType, true); + + $this->_setForcedFormKeyActions('delete'); + return parent::preDispatch(); + } + + #[\Override] + public function addActionLayoutHandles() + { + parent::addActionLayoutHandles(); + $this->getLayout()->getUpdate() + ->removeHandle(strtolower($this->getFullActionName())) + ->addHandle(strtolower('adminhtml_eav_attribute_' . $this->getRequest()->getActionName())) + ->addHandle(strtolower($this->getFullActionName())); + return $this; + } + + protected function _initAction() + { + return $this->loadLayout(); + } + + public function indexAction() + { + $this->_initAction() + ->renderLayout(); + } + + public function newAction() + { + $this->_forward('edit'); + } + + public function editAction() + { + $id = $this->getRequest()->getParam('attribute_id'); + + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + $attribute = Mage::getModel($this->entityType->getAttributeModel()); + + if ($id) { + if ($websiteId = $this->getRequest()->getParam('website')) { + $attribute->setWebsite($websiteId); + } + $attribute->load($id); + + if (!$attribute->getId()) { + Mage::getSingleton('adminhtml/session')->addError( + $this->__('This attribute no longer exists') + ); + $this->_redirect('*/*/'); + return; + } + + // Entity type check + if ($attribute->getEntityTypeId() != $this->entityType->getEntityTypeId()) { + Mage::getSingleton('adminhtml/session')->addError( + $this->__('This attribute cannot be edited.') + ); + $this->_redirect('*/*/'); + return; + } + } else { + $attribute->setEntityTypeId($this->entityType->getEntityTypeId()); + } + + // Restore entered data if an error was thrown during save + $data = Mage::getSingleton('adminhtml/session')->getAttributeData(true); + + if (!empty($data)) { + // If website specified, prefix relevant fields in saved data + if ($attribute->getWebsite() && (int)$attribute->getWebsite()->getId()) { + foreach ($attribute->getResource()->getScopeFields($attribute) as $field) { + if (array_key_exists($field, $data)) { + $data['scope_' . $field] = $data[$field]; + unset($data[$field]); + } + } + } + $attribute->addData($data); + } + + Mage::register('entity_attribute', $attribute); + + $this->_initAction(); + + if ($id) { + $this->_title($attribute->getName()); + $this->_addBreadcrumb( + $this->__('Edit Attribute'), + $this->__('Edit Attribute') + ); + } else { + $this->_title($this->__('New Attribute')); + $this->_addBreadcrumb( + $this->__('New Attribute'), + $this->__('New Attribute') + ); + } + + // Add website switcher if editing existing attribute and we have a scope table + if (!Mage::app()->isSingleStoreMode()) { + if ($id && $attribute->getResource()->hasScopeTable()) { + $this->getLayout()->getBlock('left')->insert( + $this->getLayout()->createBlock('adminhtml/website_switcher') + ->setDefaultWebsiteName($this->__('Default Values')) + ); + } + } + + $this->renderLayout(); + } + + public function validateAction() + { + $attributeId = $this->getRequest()->getParam('attribute_id'); + $attributeCode = $this->getRequest()->getParam('attribute_code'); + + $response = new Varien_Object(); + $response->setError(false); + + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + $attribute = Mage::getModel($this->entityType->getAttributeModel()); + $attribute->loadByCode($this->entityType->getEntityTypeId(), $attributeCode); + + if ($attribute->getId() && !$attributeId) { + Mage::getSingleton('adminhtml/session')->addError( + $this->__('Attribute with the same code already exists') + ); + $this->_initLayoutMessages('adminhtml/session'); + $response->setError(true); + $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); + } + + $this->getResponse()->setBody($response->toJson()); + } + + /** + * Filter post data + * + * @param array $data + * @return array + */ + protected function _filterPostData($data) + { + if ($data) { + $data['frontend_label'] = (array) $data['frontend_label']; + foreach ($data['frontend_label'] as & $value) { + if ($value) { + $value = Mage::helper('eav')->stripTags($value); + } + } + if (!empty($data['option']) && !empty($data['option']['value']) && is_array($data['option']['value'])) { + foreach ($data['option']['value'] as $key => $values) { + foreach ($values as $storeId => $storeLabel) { + $data['option']['value'][$key][$storeId] = Mage::helper('eav')->stripTags($storeLabel); + } + } + } + } + return $data; + } + + public function saveAction() + { + $id = $this->getRequest()->getParam('attribute_id'); + $data = $this->_filterPostData($this->getRequest()->getPost()); + if (!$data) { + $this->_redirect('*/*/'); + return; + } + + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + $attribute = Mage::getModel($this->entityType->getAttributeModel()); + + /** @var Mage_Admin_Model_Session $session */ + $session = Mage::getSingleton('adminhtml/session'); + + /** @var Mage_Eav_Helper_Data $helper */ + $helper = Mage::helper('eav'); + + // Validate frontend_input + if (isset($data['frontend_input'])) { + $allowedTypes = array_column($helper->getInputTypes($this->entityTypeCode), 'value'); + if (!in_array($data['frontend_input'], $allowedTypes)) { + $session->addError( + $this->__('Input type "%s" not found in the input types list.', $data['frontend_input']) + ); + $this->_redirect('*/*/edit', ['attribute_id' => $id, '_current' => true]); + return; + } + } + + if ($id) { + if ($websiteId = $this->getRequest()->getParam('website')) { + $attribute->setWebsite($websiteId); + } + $attribute->load($id); + $inputType = $attribute->getFrontendInput(); + + if (!$attribute->getId()) { + $session->addError( + $this->__('This Attribute no longer exists') + ); + $this->_redirect('*/*/'); + return; + } + + // Entity type check + if ($attribute->getEntityTypeId() != $this->entityType->getEntityTypeId()) { + $session->addError( + $this->__('This attribute cannot be updated.') + ); + $session->setAttributeData($data); + $this->_redirect('*/*/'); + return; + } + } else { + $inputType = $data['frontend_input']; + $data['entity_type_id'] = $this->entityType->getEntityTypeId(); + $data['is_user_defined'] = 1; + } + + $defaultValueField = $helper->getAttributeDefaultValueField($this->entityTypeCode, $inputType); + if ($defaultValueField) { + $data['default_value'] = $data[$defaultValueField]; + } + + if ($attribute->getWebsite() && (int)$attribute->getWebsite()->getId()) { + // Check "Use Default Value" checkboxes values + if ($useDefaults = $this->getRequest()->getPost('use_default')) { + foreach ($useDefaults as $field) { + $data[$field] = null; + } + if (in_array($defaultValueField, $useDefaults)) { + $data['default_value'] = null; + } + } + // Prefix relevant fields in POST data + foreach ($attribute->getResource()->getScopeFields($attribute) as $field) { + if (array_key_exists($field, $data)) { + $data['scope_' . $field] = $data[$field]; + unset($data[$field]); + } + } + } else { + // Check for no forms selected and set to empty array + if ($attribute->getResource()->hasFormTable()) { + if (!isset($data['used_in_forms'])) { + $data['used_in_forms'] = []; + } + } + } + + $attribute->addData($data); + + Mage::dispatchEvent( + "adminhtml_{$this->entityTypeCode}_attribute_edit_prepare_save", + ['object' => $attribute, 'request' => $this->getRequest()] + ); + + try { + $attribute->save(); + $session->addSuccess( + $this->__('The attribute has been saved.') + ); + + // Clear translation cache because attribute labels are stored in translation + Mage::app()->cleanCache([Mage_Core_Model_Translate::CACHE_TAG]); + + $session->setAttributeData(false); + if ($this->getRequest()->getParam('back')) { + $this->_redirect('*/*/edit', ['attribute_id' => $attribute->getId(),'_current' => true]); + } else { + $this->_redirect('*/*/', []); + } + } catch (Exception $e) { + $session->addError($e->getMessage()); + $session->setAttributeData($data); + $this->_redirect('*/*/edit', ['attribute_id' => $id, '_current' => true]); + } + } + + public function deleteAction() + { + $id = $this->getRequest()->getParam('attribute_id'); + if (!$id) { + Mage::getSingleton('adminhtml/session')->addError( + $this->__('Unable to find an attribute to delete.') + ); + $this->_redirect('*/*/'); + return; + } + + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + $attribute = Mage::getModel($this->entityType->getAttributeModel()); + + // Entity type check + $attribute->load($id); + if ($attribute->getEntityTypeId() != $this->entityType->getEntityTypeId() || !$attribute->getIsUserDefined()) { + Mage::getSingleton('adminhtml/session')->addError( + $this->__('This attribute cannot be deleted.') + ); + $this->_redirect('*/*/'); + return; + } + + try { + $attribute->delete(); + Mage::getSingleton('adminhtml/session')->addSuccess( + $this->__('The attribute has been deleted.') + ); + $this->_redirect('*/*/'); + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->_redirect('*/*/edit', ['attribute_id' => $this->getRequest()->getParam('attribute_id')]); + } + } +} diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php new file mode 100644 index 000000000..9851b6106 --- /dev/null +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php @@ -0,0 +1,184 @@ +entityType = Mage::getSingleton('eav/config')->getEntityType($this->entityTypeCode); + Mage::register('entity_type', $this->entityType, true); + + $this->_setForcedFormKeyActions('delete'); + return parent::preDispatch(); + } + + #[\Override] + public function addActionLayoutHandles() + { + parent::addActionLayoutHandles(); + $this->getLayout()->getUpdate() + ->removeHandle(strtolower($this->getFullActionName())) + ->addHandle(strtolower('adminhtml_eav_set_' . $this->getRequest()->getActionName())) + ->addHandle(strtolower($this->getFullActionName())); + return $this; + } + + protected function _initAction() + { + return $this->loadLayout(); + } + + public function indexAction() + { + $this->_initAction() + ->renderLayout(); + } + + public function setGridAction() + { + $this->_initAction() + ->renderLayout(); + } + + public function addAction() + { + $this->_initAction() + ->_title($this->__('New Set')) + ->renderLayout(); + } + + public function editAction() + { + /** @var Mage_Eav_Model_Entity_Attribute_Set $attributeSet */ + $attributeSet = Mage::getModel('eav/entity_attribute_set') + ->load($this->getRequest()->getParam('id')); + + if (!$attributeSet->getId()) { + $this->_redirect('*/*/index'); + return; + } + + Mage::register('current_attribute_set', $attributeSet); + + $this->_initAction() + ->_title($attributeSet->getAttributeSetName()) + ->renderLayout(); + } + + public function createFromSkeletonSetAction() + { + /** @var Mage_Eav_Model_Entity_Attribute_Set $attributeSet */ + $attributeSet = Mage::getModel('eav/entity_attribute_set'); + + /** @var Mage_Admin_Model_Session $session */ + $session = Mage::getSingleton('adminhtml/session'); + + /** @var Mage_Eav_Helper_Data $helper */ + $helper = Mage::helper('eav'); + + try { + $data = $this->getRequest()->getPost(); + + $attributeSet->setEntityTypeId($this->entityType->getEntityTypeId()) + ->setAttributeSetName($helper->stripTags($data['attribute_set_name'])); + + $attributeSet->validate(); + + $attributeSet->save() + ->initFromSkeleton($data['skeleton_set']) + ->save(); + + $this->_redirect('*/*/edit', ['id' => $attributeSet->getId()]); + } catch (Exception $e) { + $session->addError($e->getMessage()); + $this->_redirect('*/*/edit', ['id' => $attributeSet->getId()]); + } + } + + public function saveAction() + { + if ($this->getRequest()->getPost('skeleton_set')) { + $this->_forward('createFromSkeletonSet'); + return; + } + + /** @var Mage_Eav_Model_Entity_Attribute_Set $attributeSet */ + $attributeSet = Mage::getModel('eav/entity_attribute_set') + ->load($this->getRequest()->getParam('id')); + + /** @var Mage_Admin_Model_Session $session */ + $session = Mage::getSingleton('adminhtml/session'); + + /** @var Mage_Eav_Helper_Data $helper */ + $helper = Mage::helper('eav'); + + $hasError = false; + try { + if (!$attributeSet->getId()) { + Mage::throwException(Mage::helper('eav')->__('This attribute set no longer exists.')); + } + $data = Mage::helper('core')->jsonDecode($this->getRequest()->getPost('data')); + $data['attribute_set_name'] = $helper->stripTags($data['attribute_set_name']); + + $attributeSet->organizeData($data)->validate(); + $attributeSet->save(); + + $this->_getSession()->addSuccess(Mage::helper('eav')->__('The attribute set has been saved.')); + } catch (Mage_Core_Exception $e) { + $this->_getSession()->addError($e->getMessage()); + $hasError = true; + } catch (Exception $e) { + $this->_getSession()->addException( + $e, + Mage::helper('eav')->__('An error occurred while saving the attribute set.') + ); + $hasError = true; + } + + if ($hasError) { + $this->_initLayoutMessages('adminhtml/session'); + $response = [ + 'error' => 1, + 'message' => $this->getLayout()->getMessagesBlock()->getGroupedHtml(), + ]; + } else { + $response = [ + 'error' => 0, + 'url' => $this->getUrl('*/*/'), + ]; + } + $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); + } + + public function deleteAction() + { + /** @var Mage_Eav_Model_Entity_Attribute_Set $attributeSet */ + $attributeSet = Mage::getModel('eav/entity_attribute_set') + ->load($this->getRequest()->getParam('id')); + + try { + $attributeSet->delete(); + + $this->_getSession()->addSuccess($this->__('The attribute set has been removed.')); + $this->getResponse()->setRedirect($this->getUrl('*/*/')); + } catch (Exception $e) { + $this->_getSession()->addError($this->__('An error occurred while deleting this set.')); + $this->_redirectReferer(); + } + } +} diff --git a/app/code/core/Mage/Eav/Helper/Data.php b/app/code/core/Mage/Eav/Helper/Data.php index 3d9cdbc8a..4eb06ccc6 100644 --- a/app/code/core/Mage/Eav/Helper/Data.php +++ b/app/code/core/Mage/Eav/Helper/Data.php @@ -6,131 +6,367 @@ * @package Mage_Eav * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2022-2023 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * Eav data helper - * - * @category Mage - * @package Mage_Eav + * Helper functions to read EAV data from config.xml and observers */ class Mage_Eav_Helper_Data extends Mage_Core_Helper_Abstract { + protected $_moduleName = 'Mage_Eav'; + /** - * XML path to input types validator data in config + * Cache objects grouped by entity type to avoid multiple config.xml reads and event dispatches */ - public const XML_PATH_VALIDATOR_DATA_INPUT_TYPES = 'general/validator_data/input_types'; + protected array $cacheAttributeDisplayInfo = []; + protected array $cacheFrontendClasses = []; + protected array $cacheInputTypes = []; + protected array $cacheForms = []; - protected $_moduleName = 'Mage_Eav'; + /** @deprecated */ + protected $_attributesLockedFields = []; + /** @deprecated */ + protected $_entityTypeFrontendClasses = []; - protected $_attributesLockedFields = []; + /** + * XML paths for various EAV config grouped by entity types + */ + public const XML_PATH_ATTRIBUTES = 'global/eav_attributes'; + public const XML_PATH_FRONTEND_CLASSES = 'global/eav_frontendclasses'; + public const XML_PATH_INPUT_TYPES = 'global/eav_inputtypes'; + public const XML_PATH_FORMS = 'global/eav_forms'; - protected $_entityTypeFrontendClasses = []; + /** @deprecated */ + public const XML_PATH_VALIDATOR_DATA_INPUT_TYPES = 'general/validator_data/input_types'; /** - * Return default frontend classes value labal array + * Return default input validation classes option array * + * @deprecated Instead use Mage::helper('eav')->getFrontendClasses('default') + * @see Mage_Eav_Helper_Data::getFrontendClasses() * @return array */ protected function _getDefaultFrontendClasses() { - return [ - [ - 'value' => '', - 'label' => Mage::helper('eav')->__('None') - ], - [ - 'value' => 'validate-number', - 'label' => Mage::helper('eav')->__('Decimal Number') - ], - [ - 'value' => 'validate-digits', - 'label' => Mage::helper('eav')->__('Integer Number') - ], - [ - 'value' => 'validate-email', - 'label' => Mage::helper('eav')->__('Email') - ], - [ - 'value' => 'validate-url', - 'label' => Mage::helper('eav')->__('URL') - ], - [ - 'value' => 'validate-alpha', - 'label' => Mage::helper('eav')->__('Letters') - ], - [ - 'value' => 'validate-alphanum', - 'label' => Mage::helper('eav')->__('Letters (a-z, A-Z) or Numbers (0-9)') - ] - ]; - } - - /** - * Return merged default and entity type frontend classes value label array + return $this->getFrontendClasses('default'); + } + + /** + * Return merged default and entity type input validation classes option array * * @param string $entityTypeCode * @return array */ public function getFrontendClasses($entityTypeCode) { - $_defaultClasses = $this->_getDefaultFrontendClasses(); - if (isset($this->_entityTypeFrontendClasses[$entityTypeCode])) { - return array_merge( - $_defaultClasses, - $this->_entityTypeFrontendClasses[$entityTypeCode] - ); + if (!isset($this->cacheFrontendClasses[$entityTypeCode])) { + $options = []; + $config = Mage::app()->getConfig()->getNode(self::XML_PATH_FRONTEND_CLASSES . '/default'); + if ($entityTypeCode !== 'default') { + $config->extend(Mage::app()->getConfig()->getNode(self::XML_PATH_FRONTEND_CLASSES . "/$entityTypeCode"), true); + } + foreach ($config->children() as $key => $child) { + $option = $child->asCanonicalArray(); + if (empty($option['value']) || empty($option['label'])) { + continue; + } + $module = $child->getAttribute('module') ?? 'eav'; + $option['label'] = Mage::helper($module)->__($option['label']); + $options[$key] = $option; + } + + $response = new Varien_Object(['options' => $options]); + Mage::dispatchEvent("adminhtml_{$entityTypeCode}_attribute_frontendclasses", ['response' => $response]); + $this->cacheFrontendClasses[$entityTypeCode] = $response->getOptions(); + + // Update old property for backwards compatibility + $this->_entityTypeFrontendClasses[$entityTypeCode] = array_values($response->getOptions()); + } + return $this->cacheFrontendClasses[$entityTypeCode]; + } + + /** + * Return attribute adminhtml display info per entity type as defined in config.xml or set by observers + * + * Not all attributes will be defined, only those with locked_fields or hidden values + * See nodes in various config.xml files for examples + */ + public function getAttributeDisplayInfo(string $entityTypeCode): array + { + if (empty($entityTypeCode)) { + return []; } - $_entityTypeClasses = Mage::app()->getConfig() - ->getNode('global/eav_frontendclasses/' . $entityTypeCode); - if ($_entityTypeClasses) { - foreach ($_entityTypeClasses->children() as $item) { - $this->_entityTypeFrontendClasses[$entityTypeCode][] = [ - 'value' => (string)$item->value, - 'label' => (string)$item->label - ]; + if (!isset($this->cacheAttributeDisplayInfo[$entityTypeCode])) { + $attributes = []; + if ($config = Mage::app()->getConfig()->getNode(self::XML_PATH_ATTRIBUTES . "/$entityTypeCode")) { + foreach ($config->children() as $key => $child) { + $attribute = $child->asCanonicalArray(); + if (empty($attribute['code'])) { + continue; + } + if (isset($child->hidden)) { + $attribute['hidden'] = $child->is('hidden'); + } + if (isset($child->locked_fields)) { + $attribute['locked_fields'] = array_keys($child->locked_fields->asArray()); + } + $attributes[$key] = $attribute; + } + } + $response = new Varien_Object(['attributes' => $attributes]); + Mage::dispatchEvent("adminhtml_{$entityTypeCode}_attribute_displayinfo", ['response' => $response]); + $this->cacheAttributeDisplayInfo[$entityTypeCode] = $response->getAttributes(); + } + return $this->cacheAttributeDisplayInfo[$entityTypeCode]; + } + + /** + * Return attributes for entity type that should be hidden from grids + */ + public function getHiddenAttributes(string $entityTypeCode): array + { + $hiddenAttributes = []; + foreach ($this->getAttributeDisplayInfo($entityTypeCode) as $code => $attribute) { + if (!empty($attribute['hidden'])) { + $hiddenAttributes[] = $code; } - return array_merge( - $_defaultClasses, - $this->_entityTypeFrontendClasses[$entityTypeCode] - ); } - return $_defaultClasses; + return $hiddenAttributes; } /** - * Retrieve attributes locked fields to edit + * Return locked fields per entity type when editing attribute * * @param string $entityTypeCode * @return array */ public function getAttributeLockedFields($entityTypeCode) { - if (!$entityTypeCode) { - return []; - } - if (isset($this->_attributesLockedFields[$entityTypeCode])) { - return $this->_attributesLockedFields[$entityTypeCode]; - } - $_data = Mage::app()->getConfig()->getNode('global/eav_attributes/' . $entityTypeCode); - if ($_data) { - foreach ($_data->children() as $attribute) { - $this->_attributesLockedFields[$entityTypeCode][(string)$attribute->code] = - array_keys($attribute->locked_fields->asArray()); + $lockedFields = []; + foreach ($this->getAttributeDisplayInfo($entityTypeCode) as $code => $attribute) { + if (!empty($attribute['locked_fields'])) { + $lockedFields[$code] = $attribute['locked_fields']; } - return $this->_attributesLockedFields[$entityTypeCode]; } - return []; + // Update old property for backwards compatibility + $this->_attributesLockedFields[$entityTypeCode] = $lockedFields; + return $lockedFields; } /** - * Get input types validator data + * Get input types validator data for all entity types * + * @deprecated Instead use Mage::helper('eav')->getInputTypes() + * @see Mage_Eav_Helper_Data::getInputTypes() * @return array */ public function getInputTypesValidatorData() { - return Mage::getStoreConfig(self::XML_PATH_VALIDATOR_DATA_INPUT_TYPES); + $validatorData = []; + $config = Mage::app()->getConfig()->getNode(self::XML_PATH_INPUT_TYPES); + foreach (array_keys($config->asCanonicalArray()) as $entityTypeCode) { + $inputTypes = $this->getInputTypes($entityTypeCode); + foreach ($inputTypes as $type) { + $validatorData[$type['value']] = $type['value']; + } + } + return $validatorData; + } + + /** + * Return input types per entity type as defined in config.xml or set by observers + * + * Types can define the following fields: + * - label: (string, required) label to display on the attribute edit form + * - value: (string, required) value for the `eav_attribute.frontend_input` column + * - backend_type: (string) value for the `eav_attribute.backend_type` column + * - backend_model: (string) value for the `eav_attribute.backend_model` column + * - frontend_model: (string) value for the `eav_attribute.frontend_model` column + * - source_model: (string) value for the `eav_attribute.source_model` column + * - default_value_field: (string) optional default value input type on the attribute edit form, examples: + * - 'default_value_text' + * - 'default_value_textarea' + * - 'default_value_date' + * - 'default_value_yesno' + * - hide_fields: (array) fields to hide on the attribute edit form, examples: + * - 'is_required': the "Values Required" input + * - 'frontend_class': the "Input Validation" input + * - '_default_value': the various "Default Value" inputs + * - '_front_fieldset': the entire "Frontend Properties" fieldset + * - '_scope': the saving scope dropdown + * - disabled_types: (array) product types to remove from the "Apply To" dropdown, examples: + * - 'simple' + * - 'bundle' + * - 'configurable' + * - 'grouped' + * - 'virtual' + * - options_panel: (object) configuration options for the "Manage Options" panel + * - 'intype': (string) the HTML input type to use for "Is Default" boxes, can be 'radio' or 'checkbox' + * + * See nodes in various config.xml files for examples + */ + public function getInputTypes(string $entityTypeCode): array + { + if (!isset($this->cacheInputTypes[$entityTypeCode])) { + $inputTypes = []; + $config = Mage::app()->getConfig()->getNode(self::XML_PATH_INPUT_TYPES . '/default'); + if ($entityTypeCode !== 'default') { + $config->extend(Mage::app()->getConfig()->getNode(self::XML_PATH_INPUT_TYPES . "/$entityTypeCode"), true); + } + foreach ($config->children() as $key => $child) { + $type = $child->asCanonicalArray(); + if (empty($type['value']) || empty($type['label'])) { + continue; + } + $module = $child->getAttribute('module') ?? 'eav'; + $type['label'] = Mage::helper($module)->__($type['label']); + + if (isset($child->hide_fields)) { + $type['hide_fields'] = array_keys($child->hide_fields->asArray()); + } + if (isset($child->disabled_types)) { + $type['disabled_types'] = array_keys($child->disabled_types->asArray()); + } + $inputTypes[$key] = $type; + } + $events = ["adminhtml_{$entityTypeCode}_attribute_types"]; + if ($entityTypeCode === 'catalog_product') { + // Dispatch legacy event for backwards compatibility + array_unshift($events, 'adminhtml_product_attribute_types'); + } + foreach ($events as $event) { + $response = new Varien_Object(['types' => $inputTypes]); + Mage::dispatchEvent($event, ['response' => $response]); + $inputTypes = $response->getTypes(); + } + foreach ($inputTypes as $type) { + $this->cacheInputTypes[$entityTypeCode][$type['value']] = $type; + } + } + return $this->cacheInputTypes[$entityTypeCode]; + } + + /** + * Return default attribute backend type by frontend input type + */ + public function getAttributeBackendType(string $entityTypeCode, string $inputType): ?string + { + return $this->getInputTypes($entityTypeCode)[$inputType]['backend_type'] ?? null; + } + + /** + * Return default attribute backend model by frontend input type + */ + public function getAttributeBackendModel(string $entityTypeCode, string $inputType): ?string + { + return $this->getInputTypes($entityTypeCode)[$inputType]['backend_model'] ?? null; + } + + /** + * Return default attribute frontend model by frontend input type + */ + public function getAttributeFrontendModel(string $entityTypeCode, string $inputType): ?string + { + return $this->getInputTypes($entityTypeCode)[$inputType]['frontend_model'] ?? null; + } + + /** + * Return default attribute source model by frontend input type + */ + public function getAttributeSourceModel(string $entityTypeCode, string $inputType): ?string + { + return $this->getInputTypes($entityTypeCode)[$inputType]['source_model'] ?? null; + } + + /** + * Return default value field by frontend input type + */ + public function getAttributeDefaultValueField(string $entityTypeCode, string $inputType): ?string + { + return $this->getInputTypes($entityTypeCode)[$inputType]['default_value_field'] ?? null; + } + + /** + * Return hidden fields per input type when editing attribute for entity type + */ + public function getInputTypeHiddenFields(string $entityTypeCode): array + { + $hiddenFields = []; + foreach ($this->getInputTypes($entityTypeCode) as $key => $type) { + if (isset($type['hide_fields'])) { + $hiddenFields[$key] = $type['hide_fields']; + } + } + return $hiddenFields; + } + + /** + * Return disable fields per input type when editing attribute for entity type + */ + public function getInputTypeDisabledApplyToOptions(string $entityTypeCode): array + { + $disabledTypes = []; + foreach ($this->getInputTypes($entityTypeCode) as $key => $type) { + if (isset($type['disabled_types'])) { + $disabledTypes[$key] = $type['disabled_types']; + } + } + return $disabledTypes; + } + + /** + * Return options panel info per input type when editing attribute for entity type + */ + public function getInputTypeOptionsPanelInfo(string $entityTypeCode): array + { + $optionsPanel = []; + foreach ($this->getInputTypes($entityTypeCode) as $key => $type) { + if (isset($type['options_panel'])) { + $optionsPanel[$key] = $type['options_panel']; + } + } + return $optionsPanel; + } + + /** + * Return forms defined per entity type as defined in config.xml or set by observers + */ + public function getForms(string $entityTypeCode): array + { + if (empty($entityTypeCode)) { + return []; + } + if (!isset($this->cacheForms[$entityTypeCode])) { + $forms = []; + if ($config = Mage::app()->getConfig()->getNode(self::XML_PATH_FORMS . "/$entityTypeCode")) { + foreach ($config->children() as $key => $child) { + $form = $child->asCanonicalArray(); + if (empty($form['value']) || empty($form['label'])) { + continue; + } + $module = $child->getAttribute('module') ?? 'eav'; + $form['label'] = Mage::helper($module)->__($form['label']); + $forms[$key] = $form; + } + } + $response = new Varien_Object(['forms' => $forms]); + Mage::dispatchEvent("adminhtml_{$entityTypeCode}_attribute_forms", ['response' => $response]); + $this->cacheForms[$entityTypeCode] = $response->getForms(); + } + return $this->cacheForms[$entityTypeCode]; + } + + /** + * Return entity code formatted for humans + */ + public function formatTypeCode(string $entityTypeCode): string + { + return match ($entityTypeCode) { + Mage_Catalog_Model_Product::ENTITY => 'Product', + Mage_Catalog_Model_Category::ENTITY => 'Category', + default => ucwords(str_replace('_', ' ', $entityTypeCode)), + }; } } diff --git a/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype.php b/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype.php index e09083b62..9cac721b2 100644 --- a/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype.php +++ b/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype.php @@ -6,12 +6,15 @@ * @package Mage_Eav * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2020-2023 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * @category Mage - * @package Mage_Eav + * Product attribute source input types + * + * @deprecated Instead use Mage::helper('eav')->getInputTypes() + * @see Mage_Eav_Helper_Data::getInputTypes() */ class Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype { @@ -20,13 +23,6 @@ class Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype */ public function toOptionArray() { - return [ - ['value' => 'text', 'label' => Mage::helper('eav')->__('Text Field')], - ['value' => 'textarea', 'label' => Mage::helper('eav')->__('Text Area')], - ['value' => 'date', 'label' => Mage::helper('eav')->__('Date')], - ['value' => 'boolean', 'label' => Mage::helper('eav')->__('Yes/No')], - ['value' => 'multiselect', 'label' => Mage::helper('eav')->__('Multiple Select')], - ['value' => 'select', 'label' => Mage::helper('eav')->__('Dropdown')] - ]; + return Mage::helper('eav')->getInputTypes('default'); } } diff --git a/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype/Validator.php b/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype/Validator.php index 455e7b096..153e07b1b 100644 --- a/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype/Validator.php +++ b/app/code/core/Mage/Eav/Model/Adminhtml/System/Config/Source/Inputtype/Validator.php @@ -13,8 +13,8 @@ /** * Validator for check input type value * - * @category Mage - * @package Mage_Eav + * @deprecated Instead use Mage::helper('eav')->getInputTypes() + * @see Mage_Eav_Helper_Data::getInputTypes() */ class Mage_Eav_Model_Adminhtml_System_Config_Source_Inputtype_Validator extends Zend_Validate_InArray { diff --git a/app/code/core/Mage/Eav/Model/Attribute.php b/app/code/core/Mage/Eav/Model/Attribute.php index 8d919bc39..cea9d61ce 100644 --- a/app/code/core/Mage/Eav/Model/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Attribute.php @@ -132,6 +132,17 @@ protected function _getScopeValue($key) return $this->getData($scopeKey) ?? $this->getData($key); } + /** + * Return scope value by key + * + * @param string $key + * @return mixed + */ + public function getScopeValue($key) + { + return $this->_getScopeValue($key); + } + /** * Return is attribute value required * diff --git a/app/code/core/Mage/Eav/Model/Attribute/Data/Customselect.php b/app/code/core/Mage/Eav/Model/Attribute/Data/Customselect.php new file mode 100644 index 000000000..d4e78701d --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Attribute/Data/Customselect.php @@ -0,0 +1,19 @@ +getAttributeCode() == 'store_id') { return 'eav/entity_attribute_source_store'; @@ -137,49 +142,61 @@ public function loadEntityAttributeIdBySet() #[\Override] protected function _beforeSave() { + /** @var Mage_Eav_Helper_Data $helper */ + $helper = Mage::helper('eav'); + /** - * Check for maximum attribute_code length + * Validate attribute_code */ - if (isset($this->_data['attribute_code']) && - !Zend_Validate::is( - $this->_data['attribute_code'], - 'StringLength', - ['max' => self::ATTRIBUTE_CODE_MAX_LENGTH] - ) - ) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Maximum length of attribute code must be less then %s symbols', self::ATTRIBUTE_CODE_MAX_LENGTH)); + $code = $this->getAttributeCode(); + if (empty($code)) { + throw Mage::exception('Mage_Eav', $helper->__('Attribute code cannot be empty')); } - - $defaultValue = $this->getDefaultValue(); - $hasDefaultValue = ((string)$defaultValue != ''); - - if ($this->getBackendType() == 'decimal' && $hasDefaultValue) { - $locale = Mage::app()->getLocale()->getLocaleCode(); - if (!Zend_Locale_Format::isNumber($defaultValue, ['locale' => $locale])) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value')); - } - - try { - $filter = new Zend_Filter_LocalizedToNormalized( - ['locale' => Mage::app()->getLocale()->getLocaleCode()] - ); - $this->setDefaultValue($filter->filter($defaultValue)); - } catch (Exception $e) { - throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value')); - } + if (!preg_match('/^[a-z][a-z_0-9]*$/', $code)) { + throw Mage::exception('Mage_Eav', $helper->__('Attribute code must contain only letters (a-z), numbers (0-9) or underscore(_), first character should be a letter')); + } + if (strlen($code) < self::ATTRIBUTE_CODE_MIN_LENGTH || strlen($code) > self::ATTRIBUTE_CODE_MAX_LENGTH) { + throw Mage::exception('Mage_Eav', $helper->__('Attribute code must be between %d and %d characters', self::ATTRIBUTE_CODE_MIN_LENGTH, self::ATTRIBUTE_CODE_MAX_LENGTH)); } - if ($this->getBackendType() == 'datetime') { - if (!$this->getBackendModel()) { - $this->setBackendModel('eav/entity_attribute_backend_datetime'); - } + /** + * Set default values from input type + */ + $entityTypeCode = $this->getEntityType()->getEntityTypeCode(); + $inputType = $this->getFrontendInput(); + if (!$this->getBackendType()) { + $this->setBackendType($helper->getAttributeBackendType($entityTypeCode, $inputType)); + } + if (!$this->getBackendModel()) { + $this->setBackendModel($helper->getAttributeBackendModel($entityTypeCode, $inputType)); + } + if (!$this->getFrontendModel()) { + $this->setFrontendModel($helper->getAttributeFrontendModel($entityTypeCode, $inputType)); + } + if (!$this->getSourceModel()) { + $this->setSourceModel($helper->getAttributeSourceModel($entityTypeCode, $inputType)); + } - if (!$this->getFrontendModel()) { - $this->setFrontendModel('eav/entity_attribute_frontend_datetime'); + /** + * Validate default_value + */ + $defaultValue = $this->getDefaultValue(); + if (!empty($defaultValue)) { + if ($this->getBackendType() === 'decimal') { + $locale = Mage::app()->getLocale()->getLocaleCode(); + if (!Zend_Locale_Format::isNumber($defaultValue, ['locale' => $locale])) { + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value')); + } + try { + $filter = new Zend_Filter_LocalizedToNormalized( + ['locale' => Mage::app()->getLocale()->getLocaleCode()] + ); + $this->setDefaultValue($filter->filter($defaultValue)); + } catch (Exception $e) { + throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid default decimal value')); + } } - - // save default date value as timestamp - if ($hasDefaultValue) { + if ($this->getBackendType() == 'datetime') { $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); try { $defaultValue = Mage::app()->getLocale()->date($defaultValue, $format, null, false)->toValue(); @@ -190,12 +207,6 @@ protected function _beforeSave() } } - if ($this->getBackendType() == 'gallery') { - if (!$this->getBackendModel()) { - $this->setBackendModel('eav/entity_attribute_backend_media'); - } - } - return parent::_beforeSave(); } @@ -210,94 +221,42 @@ protected function _afterSave() } /** - * Detect backend storage type using frontend input type + * Return backend storage type by frontend input type * - * @return string backend_type field value - * @param string $type frontend_input field value + * @deprecated Instead use Mage::helper('eav')->getAttributeBackendTypeByInputType() + * @see Mage_Eav_Helper_Data::getAttributeBackendTypeByInputType() + * @param string $inputType + * @return string|null */ - public function getBackendTypeByInput($type) + public function getBackendTypeByInput($inputType) { - $field = null; - switch ($type) { - case 'text': - case 'gallery': - case 'media_image': - $field = 'varchar'; - break; - - case 'image': - case 'textarea': - case 'multiselect': - $field = 'text'; - break; - - case 'date': - $field = 'datetime'; - break; - - case 'select': - case 'boolean': - $field = 'int'; - break; - - case 'price': - $field = 'decimal'; - break; - } - - return $field; + $entityTypeCode = $this->getEntityType()->getEntityTypeCode(); + return Mage::helper('eav')->getAttributeBackendType($entityTypeCode, $inputType); } /** - * Detect default value using frontend input type + * Return default value field by frontend input type * - * @return string default_value field value - * @param string $type frontend_input field name + * @deprecated Instead use Mage::helper('eav')->getDefaultValueFieldByInputType() + * @see Mage_Eav_Helper_Data::getDefaultValueFieldByInputType() + * @param string $inputType + * @return string|null */ - public function getDefaultValueByInput($type) + public function getDefaultValueByInput($inputType) { - $field = ''; - switch ($type) { - case 'select': - case 'gallery': - case 'media_image': - break; - case 'multiselect': - $field = null; - break; - - case 'text': - case 'price': - case 'image': - case 'weight': - $field = 'default_value_text'; - break; - - case 'textarea': - $field = 'default_value_textarea'; - break; - - case 'date': - $field = 'default_value_date'; - break; - - case 'boolean': - $field = 'default_value_yesno'; - break; - } - - return $field; + $entityTypeCode = $this->getEntityType()->getEntityTypeCode(); + return Mage::helper('eav')->getAttributeDefaultValueField($entityTypeCode, $inputType); } /** - * Retrieve attribute codes by frontend type + * Return attribute codes by frontend input type * - * @param string $type + * @param string $inputType * @return array */ - public function getAttributeCodesByFrontendType($type) + public function getAttributeCodesByFrontendType($inputType) { - return $this->getResource()->getAttributeCodesByFrontendType($type); + return $this->getResource()->getAttributeCodesByFrontendType($inputType); } /** diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php index c839455f0..c74bda7e4 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php @@ -516,8 +516,11 @@ protected function _getDefaultFrontendModel() /** * @return string */ - protected function _getDefaultSourceModel() + public function _getDefaultSourceModel() { + if ($this->getFrontendInput() === 'customselect') { + return 'eav/entity_attribute_source_table'; + } return $this->getEntity()->getDefaultAttributeSourceModel(); } diff --git a/app/code/core/Mage/Eav/Model/Form.php b/app/code/core/Mage/Eav/Model/Form.php index 738c0504a..f91666ee1 100644 --- a/app/code/core/Mage/Eav/Model/Form.php +++ b/app/code/core/Mage/Eav/Model/Form.php @@ -225,6 +225,21 @@ public function getEntity() return $this->_entity; } + /** + * Return array of form attributes as groups + * TODO remove + */ + public function getGroupedAttributes() + { + $groups = []; + foreach ($this->getAttributes() as $code => $attribute) { + $group = $attribute->getAttributeGroupName() ?? 'General'; + $groups[$group] ??= []; + $groups[$group][$code] = $attribute; + } + return $groups; + } + /** * Return array of form attributes * diff --git a/app/code/core/Mage/Eav/Model/Resource/Attribute.php b/app/code/core/Mage/Eav/Model/Resource/Attribute.php index b27608e30..511986c50 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Attribute.php @@ -64,9 +64,7 @@ protected function _getLoadSelect($field, $value, $object) $adapter = $this->_getReadAdapter(); $columns = []; $scopeTable = $this->_getEavWebsiteTable(); - $describe = $adapter->describeTable($scopeTable); - unset($describe['attribute_id']); - foreach (array_keys($describe) as $columnName) { + foreach ($this->getScopeFields($object) as $columnName) { $columns['scope_' . $columnName] = $columnName; } $conditionSql = $adapter->quoteInto( @@ -121,7 +119,6 @@ protected function _afterSave(Mage_Core_Model_Abstract $object) $websiteId = (int)$object->getWebsite()->getId(); if ($websiteId) { $table = $this->_getEavWebsiteTable(); - $describe = $this->_getReadAdapter()->describeTable($table); $data = []; if (!$object->getScopeWebsiteId() || $object->getScopeWebsiteId() != $websiteId) { $data = $this->getScopeValues($object); @@ -129,11 +126,9 @@ protected function _afterSave(Mage_Core_Model_Abstract $object) $data['attribute_id'] = (int)$object->getId(); $data['website_id'] = (int)$websiteId; - unset($describe['attribute_id']); - unset($describe['website_id']); $updateColumns = []; - foreach (array_keys($describe) as $columnName) { + foreach ($this->getScopeFields($object) as $columnName) { $data[$columnName] = $object->getData('scope_' . $columnName); $updateColumns[] = $columnName; } @@ -144,6 +139,39 @@ protected function _afterSave(Mage_Core_Model_Abstract $object) return parent::_afterSave($object); } + /** + * Check if we have a scope table for attribute + * + * @return bool + */ + #[\Override] + public function hasScopeTable() + { + return !is_null($this->_getEavWebsiteTable()); + } + + /** + * Return scoped fields for attribute + * + * @return array + */ + #[\Override] + public function getScopeFields(Mage_Eav_Model_Attribute $object) + { + if (!$this->hasScopeTable()) { + return []; + } + + $adapter = $this->_getReadAdapter(); + $scopeTable = $this->_getEavWebsiteTable(); + $describe = $adapter->describeTable($scopeTable); + + unset($describe['attribute_id']); + unset($describe['website_id']); + + return array_keys($describe); + } + /** * Return scope values for attribute and website * @@ -170,6 +198,17 @@ public function getScopeValues(Mage_Eav_Model_Attribute $object) return $result; } + /** + * Check if we have a forms table for attribute + * + * @return bool + */ + #[\Override] + public function hasFormTable() + { + return !is_null($this->_getFormAttributeTable()); + } + /** * Return forms in which the attribute * diff --git a/app/code/core/Mage/Eav/Model/Resource/Attribute/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Attribute/Collection.php index 4c87b419a..1e3926ccf 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Attribute/Collection.php +++ b/app/code/core/Mage/Eav/Model/Resource/Attribute/Collection.php @@ -195,6 +195,7 @@ public function setEntityTypeFilter($type) * * @return $this */ + #[\Override] public function addVisibleFilter() { return $this->addFieldToFilter('is_visible', 1); diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php index c793ab4fd..9eafd3d17 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php @@ -23,7 +23,7 @@ class Mage_Eav_Model_Resource_Entity_Attribute extends Mage_Core_Model_Resource_ * * @var array */ - protected static $_entityAttributes = []; + protected static $_entityAttributes = []; #[\Override] protected function _construct() @@ -134,7 +134,8 @@ public function deleteEntity(Mage_Core_Model_Abstract $object) /** * Validate attribute data before save - * @param Mage_Catalog_Model_Resource_Eav_Attribute $object + * + * @param Mage_Eav_Model_Entity_Attribute $object */ #[\Override] protected function _beforeSave(Mage_Core_Model_Abstract $object) @@ -153,6 +154,11 @@ protected function _beforeSave(Mage_Core_Model_Abstract $object) */ if ($object->usesSource() && !$object->getData('source_model')) { $object->setSourceModel($object->_getDefaultSourceModel()); + if (!$object->getId()) { + if ($object->getFrontendInput() == 'select' || $object->getFrontendInput() == 'multiselect') { + $object->setSourceModel('eav/entity_attribute_source_table'); + } + } } return parent::_beforeSave($object); @@ -314,7 +320,7 @@ protected function _saveOption(Mage_Core_Model_Abstract $object) if (in_array($optionId, $object->getDefault())) { if ($object->getFrontendInput() == 'multiselect') { $attributeDefaultValue[] = $intOptionId; - } elseif ($object->getFrontendInput() == 'select') { + } elseif (in_array($object->getFrontendInput(), ['select', 'customselect'])) { $attributeDefaultValue = [$intOptionId]; } } @@ -542,4 +548,34 @@ public function getValidAttributeIds($attributeIds) return $adapter->fetchCol($select); } + + /** + * Check if we have a scope table for attribute + * + * @return bool + */ + public function hasScopeTable() + { + return false; + } + + /** + * Return scoped fields for attribute + * + * @return array + */ + public function getScopeFields(Mage_Eav_Model_Attribute $object) + { + return []; + } + + /** + * Check if we have a forms table for attribute + * + * @return bool + */ + public function hasFormTable() + { + return false; + } } diff --git a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Collection.php index 7602116d1..15dc4fc00 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Collection.php +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute/Collection.php @@ -244,6 +244,16 @@ public function addAttributeGrouping() return $this; } + /** + * Specify filter by "is_visible" field + * + * @return $this + */ + public function addVisibleFilter() + { + return $this; + } + /** * Specify "is_unique" filter as true * @@ -316,7 +326,7 @@ public function addSetInfo($flag = true) } /** - * Ad information about attribute sets to collection result data + * Add information about attribute sets to collection result data * * @return $this */ @@ -366,7 +376,7 @@ protected function _addSetInfo() } /** - * Ad information about attribute sets to collection result data + * Add information about attribute sets to collection result data * * @return Mage_Core_Model_Resource_Db_Collection_Abstract */ @@ -407,6 +417,24 @@ public function setCodeFilter($code) return $this->addFieldToFilter('attribute_code', ['in' => $code]); } + /** + * Specify collection attribute codes not in filter + * + * @param string | array $code + * @return $this + */ + public function setNotCodeFilter($code) + { + if (empty($code)) { + return $this; + } + if (!is_array($code)) { + $code = [$code]; + } + + return $this->addFieldToFilter('attribute_code', ['nin' => $code]); + } + /** * Add store label to attribute by specified store id * diff --git a/app/code/core/Mage/Eav/Model/Resource/Form/Attribute/Collection.php b/app/code/core/Mage/Eav/Model/Resource/Form/Attribute/Collection.php index 9881b7d0b..2446d914b 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Form/Attribute/Collection.php +++ b/app/code/core/Mage/Eav/Model/Resource/Form/Attribute/Collection.php @@ -146,6 +146,36 @@ public function setSortOrder($direction = self::SORT_ORDER_ASC) return $this->setOrder('ca.sort_order', $direction); } + public function joinAttributeGroup() + { + if (!$this->getFlag('attribute_group_joined')) { + $this->setFlag('attribute_group_joined', true); + + $this->getSelect() + ->joinInner( + ['eea' => $this->getTable('eav/entity_attribute')], + 'main_table.attribute_id = eea.attribute_id', + [] + ) + ->joinLeft( + ['eag' => $this->getTable('eav/attribute_group')], + 'eea.attribute_group_id = eag.attribute_group_id', + ['eag.attribute_group_name'] + ); + } + return $this; + } + + public function filterAttributeSet($attributeSetId) + { + $this->joinAttributeGroup(); + $this->getSelect() + ->where('eea.attribute_set_id = ?', $attributeSetId) + ->order(['eag.sort_order', 'eea.sort_order']); + + return $this; + } + /** * Add joins to select */ diff --git a/app/code/core/Mage/Eav/etc/config.xml b/app/code/core/Mage/Eav/etc/config.xml index 3379d7667..2fd65f361 100644 --- a/app/code/core/Mage/Eav/etc/config.xml +++ b/app/code/core/Mage/Eav/etc/config.xml @@ -7,6 +7,7 @@ * @package Mage_Eav * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2022-2024 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -87,6 +88,11 @@ + + + Mage_Eav_Block + + @@ -96,10 +102,95 @@ + + + + + + validate-number + + + + validate-digits + + + + validate-email + + + + validate-url + + + + validate-alpha + + + + validate-alphanum + + - - + + + + + + text + varchar + default_value_text + + + + + date + datetime + eav/entity_attribute_backend_datetime + eav/entity_attribute_frontend_datetime + default_value_date + + + + boolean + int + eav/entity_attribute_source_boolean + default_value_yesno + + + + multiselect + text + eav/entity_attribute_backend_array + checkbox + + + + + customselect + varchar + eav/entity_attribute_source_table + radio + + + @@ -112,6 +203,13 @@ + + + + eav.xml + + + @@ -133,18 +231,4 @@ - - - - - text - - date - boolean - multiselect - - - - - diff --git a/app/design/adminhtml/default/default/layout/admin.xml b/app/design/adminhtml/default/default/layout/admin.xml index 50681d702..015fe3085 100644 --- a/app/design/adminhtml/default/default/layout/admin.xml +++ b/app/design/adminhtml/default/default/layout/admin.xml @@ -7,6 +7,7 @@ * @package default_default * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2022-2023 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> @@ -91,6 +92,10 @@ + + + + diff --git a/app/design/adminhtml/default/default/layout/catalog.xml b/app/design/adminhtml/default/default/layout/catalog.xml index 80b45ffac..3e2560965 100644 --- a/app/design/adminhtml/default/default/layout/catalog.xml +++ b/app/design/adminhtml/default/default/layout/catalog.xml @@ -261,9 +261,21 @@ Layout handle for configurable products + + + + + + + - + + mainadminhtml/catalog_product_attribute_edit_tab_main + labelsadminhtml/catalog_product_attribute_edit_tab_options + @@ -273,6 +285,45 @@ Layout handle for configurable products + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + + diff --git a/app/design/adminhtml/default/default/layout/eav.xml b/app/design/adminhtml/default/default/layout/eav.xml new file mode 100644 index 000000000..33ca5a318 --- /dev/null +++ b/app/design/adminhtml/default/default/layout/eav.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + maineav/adminhtml_attribute_edit_tab_main + labelseav/adminhtml_attribute_edit_tab_options + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + + + + + diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/js.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/js.phtml index ca1fce562..b91c9c9b7 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/js.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/attribute/js.phtml @@ -9,316 +9,63 @@ * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ + +/** @var Mage_Adminhtml_Block_Template $this */ +$entityTypeCode = 'catalog_product'; ?> - diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/new/created.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/new/created.phtml index 284047177..77e30b307 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/new/created.phtml +++ b/app/design/adminhtml/default/default/template/catalog/product/attribute/new/created.phtml @@ -9,6 +9,8 @@ * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ + +/** @var Mage_Adminhtml_Block_Catalog_Product_Attribute_New_Product_Created $this */ ?> diff --git a/app/design/adminhtml/default/default/template/eav/attribute/options.phtml b/app/design/adminhtml/default/default/template/eav/attribute/options.phtml index 18f70e8e8..116019b55 100644 --- a/app/design/adminhtml/default/default/template/eav/attribute/options.phtml +++ b/app/design/adminhtml/default/default/template/eav/attribute/options.phtml @@ -9,16 +9,11 @@ * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ + +/** @var Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract $this **/ +$entityTypeCode = Mage::registry('entity_type')->getEntityTypeCode(); +$disabledAttr = $this->getReadOnly() ? 'disabled' : ''; ?> - -
      • @@ -26,240 +21,90 @@
    -

    __('Manage Titles (Size, Color, etc.)') ?>

    -
    +
    - getStores() as $_store): ?> - + getStores() as $store): ?> + - getLabelValues() ?> - getStores() as $_store): ?> + getLabelValues() ?> + getStores() as $store): ?>
    escapeHtml($_store->getName()) ?>escapeHtml($store->getName()) ?>
    - getReadOnly()):?> disabled="disabled"/> + />
    -
    +
    -
    -
    + +
    -

    __('Manage Options (values of your attribute)') ?>

    +

    __('Manage Options (values of your attribute)') ?>

    - - - isConfigurableSwatchesEnabled()): ?> - - - getStores() as $_store): ?> - - - - - - - - isConfigurableSwatchesEnabled()): ?> - +
    escapeHtml($this->__('Swatch')) ?>escapeHtml($_store->getName()) ?>__('Position') ?>escapeHtml($this->__('Is Default')) ?> - getReadOnly()):?> - getAddNewButtonHtml() ?> - -
    - - - X -
    + + isConfigurableSwatchesEnabled()): ?> + + + getStores() as $store): ?> + + + + + - - - - - + +
    escapeHtml($this->__('Swatch')) ?>escapeHtml($store->getName()) ?>__('Position') ?>escapeHtml($this->__('Is Default')) ?> + getReadOnly()):?> + getAddNewButtonHtml() ?> - getStores() as $_store): ?> - getReadOnly()):?> disabled="disabled"/>getReadOnly()):?> disabled="disabled"/>getReadOnly()):?> disabled="disabled"/> - - getReadOnly()):?> - getDeleteButtonHtml() ?> - -
    - diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/add.phtml b/app/design/adminhtml/default/default/template/eav/attribute/set/add.phtml similarity index 90% rename from app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/add.phtml rename to app/design/adminhtml/default/default/template/eav/attribute/set/add.phtml index f393fb659..8b5787013 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/toolbar/add.phtml +++ b/app/design/adminhtml/default/default/template/eav/attribute/set/add.phtml @@ -5,10 +5,11 @@ * @category design * @package default_default * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) - * @copyright Copyright (c) 2022 The OpenMage Contributors (https://openmage.org) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ + +/** @var Mage_Eav_Block_Adminhtml_Attribute_Set_Add $this */ ?>
    diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml b/app/design/adminhtml/default/default/template/eav/attribute/set/edit.phtml similarity index 92% rename from app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml rename to app/design/adminhtml/default/default/template/eav/attribute/set/edit.phtml index d9087aa17..87dd36ead 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml +++ b/app/design/adminhtml/default/default/template/eav/attribute/set/edit.phtml @@ -10,7 +10,7 @@ * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ -/** @var Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main $this */ +/** @var Mage_Eav_Block_Adminhtml_Attribute_Set_Edit $this */ ?>
    @@ -35,7 +35,7 @@
    - +

    __('Groups') ?>

    __('Groups') ?>

    @@ -43,7 +43,7 @@ getIsReadOnly()): ?>

    getAddGroupButton() ?> getDeleteGroupButton() ?>

    -

    __('Double click on a group to rename it') ?>

    +

    __('Double click on a group to rename it') ?>

    getSetsFilterHtml() ?> @@ -54,7 +54,7 @@ - +

    __('Unassigned Attributes') ?>

    __('Unassigned Attributes') ?>

    @@ -98,7 +98,7 @@ this.ge = new Ext.tree.TreeEditor(tree, { allowBlank:false, - blankText:'jsQuoteEscape(Mage::helper('catalog')->__('A name is required')) ?>', + blankText:'jsQuoteEscape($this->__('A name is required')) ?>', selectOnFocus:true, cls:'folder' }); @@ -236,12 +236,12 @@ } if( editSet.SystemNodesExists(editSet.currentNode) ) { - alert('jsQuoteEscape(Mage::helper('catalog')->__('This group contains system attributes. Please move system attributes to another group and try again.')) ?>'); + alert('jsQuoteEscape($this->__('This group contains system attributes. Please move system attributes to another group and try again.')) ?>'); return; } if (editSet.ConfigurableNodeExists(editSet.currentNode)) { - alert('jsQuoteEscape(Mage::helper('catalog')->__('This group contains attributes, used in configurable products. Please move these attributes to another group and try again.')) ?>'); + alert('jsQuoteEscape($this->__('This group contains attributes, used in configurable products. Please move these attributes to another group and try again.')) ?>'); return; } @@ -290,7 +290,7 @@ }, addGroup : function() { - var group_name = prompt("jsQuoteEscape(Mage::helper('catalog')->__('Please enter a new group name')) ?>",""); + var group_name = prompt("jsQuoteEscape($this->__('Please enter a new group name')) ?>",""); group_name = group_name.strip(); if( group_name == '' ) { this.addGroup(); @@ -337,7 +337,7 @@ } for (var i=0; i < TreePanels.root.childNodes.length; i++) { if (TreePanels.root.childNodes[i].text.toLowerCase() == name.toLowerCase() && TreePanels.root.childNodes[i].id != exceptNodeId) { - errorText = "jsQuoteEscape(Mage::helper('catalog')->__('Attribute group with the \"/name/\" name already exists')) ?>"; + errorText = "jsQuoteEscape($this->__('Attribute group with the \"/name/\" name already exists')) ?>"; alert(errorText.replace("/name/",name)); return false; } @@ -374,7 +374,7 @@ }, failure : function(o) { - alert('jsQuoteEscape(Mage::helper('catalog')->__('Unable to complete this request.')) ?>'); + alert('jsQuoteEscape($this->__('Unable to complete this request.')) ?>'); }, groupBeforeMove : function(tree, nodeThis, oldParent, newParent) { @@ -389,11 +389,11 @@ rightBeforeAppend : function(tree, nodeThis, node, newParent) { if (node.attributes.is_user_defined == 0) { - alert('jsQuoteEscape(Mage::helper('catalog')->__('You cannot remove system attribute from this set.')) ?>'); + alert('jsQuoteEscape($this->__('You cannot remove system attribute from this set.')) ?>'); return false; } else if (node.attributes.is_configurable == 1) { - alert('jsQuoteEscape(Mage::helper('catalog')->__('This attribute is used in configurable products. You cannot remove it from the attribute set.')) ?>'); + alert('jsQuoteEscape($this->__('This attribute is used in configurable products. You cannot remove it from the attribute set.')) ?>'); return false; } else { @@ -408,11 +408,11 @@ } if (node.attributes.is_user_defined == 0) { - alert('jsQuoteEscape(Mage::helper('catalog')->__('You cannot remove system attribute from this set.')) ?>'); + alert('jsQuoteEscape($this->__('You cannot remove system attribute from this set.')) ?>'); return false; } else if (node.attributes.is_configurable == 1) { - alert('jsQuoteEscape(Mage::helper('catalog')->__('This attribute is used in configurable products. You cannot remove it from the attribute set.')) ?>'); + alert('jsQuoteEscape($this->__('This attribute is used in configurable products. You cannot remove it from the attribute set.')) ?>'); return false; } else { @@ -436,7 +436,7 @@ rightRemove : function(tree, nodeThis, node) { if( nodeThis.firstChild == null && node.id != 'empty' ) { var newNode = new Ext.tree.TreeNode({ - text : 'jsQuoteEscape(Mage::helper('catalog')->__('Empty')) ?>', + text : 'jsQuoteEscape($this->__('Empty')) ?>', id : 'empty', cls : 'folder', is_user_defined : 1, diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml b/app/design/adminhtml/default/default/template/eav/attribute/set/edit/tree/group.phtml similarity index 75% rename from app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml rename to app/design/adminhtml/default/default/template/eav/attribute/set/edit/tree/group.phtml index c806c8dbd..a894a7c88 100644 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml +++ b/app/design/adminhtml/default/default/template/eav/attribute/set/edit/tree/group.phtml @@ -6,7 +6,10 @@ * @package default_default * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2022-2023 The OpenMage Contributors (https://openmage.org) + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ + +/** @var Mage_Eav_Block_Adminhtml_Attribute_Set_Edit_Tree_Group $this */ ?>
    diff --git a/app/design/adminhtml/default/default/template/website/switcher.phtml b/app/design/adminhtml/default/default/template/website/switcher.phtml new file mode 100644 index 000000000..30c668133 --- /dev/null +++ b/app/design/adminhtml/default/default/template/website/switcher.phtml @@ -0,0 +1,45 @@ + +getWebsites()): ?> +

    + +

    + + diff --git a/app/design/frontend/base/default/template/checkout/onepage/billing.phtml b/app/design/frontend/base/default/template/checkout/onepage/billing.phtml index 2610d5a40..565917c2b 100644 --- a/app/design/frontend/base/default/template/checkout/onepage/billing.phtml +++ b/app/design/frontend/base/default/template/checkout/onepage/billing.phtml @@ -13,7 +13,6 @@ ?>
    -

    __('* Required Fields') ?>

      customerHasAddresses()): ?>
    • @@ -24,123 +23,13 @@
    • customerHasAddresses()): ?> style="display:none;"> -
      - -
        -
      • getLayout()->createBlock('customer/widget_name')->setObject($this->getAddress()->getFirstname() ? $this->getAddress() : $this->getQuote()->getCustomer())->setForceUseCustomerRequiredAttributes(!$this->isCustomerLoggedIn())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?>
      • -
      • -
        - -
        - -
        -
        - isCustomerLoggedIn()): ?> -
        - -
        - -
        -
        - -
      • - helper('customer/address')->getAttributeValidationClass('street'); ?> -
      • - -
        - -
        -
      • - - helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?> -
      • - -
        - -
        -
      • - - helper('customer/address')->isVatAttributeVisible()) : ?> -
      • - -
        - -
        -
      • - -
      • -
        - -
        - -
        -
        -
        - -
        - - - -
        -
        -
      • -
      • -
        - -
        - -
        -
        -
        - -
        - getCountryHtmlSelect('billing') ?> -
        -
        -
      • -
      • -
        - -
        - -
        -
        -
        - -
        - -
        -
        -
      • - isCustomerLoggedIn()): ?> - getLayout()->createBlock('customer/widget_dob') ?> - getLayout()->createBlock('customer/widget_gender') ?> - isEnabled() || $_gender->isEnabled()): ?> -
      • - isEnabled()): ?> -
        - setDate($this->getQuote()->getCustomerDob())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?> -
        - - isEnabled()): ?> -
        - setGender($this->getQuote()->getCustomerGender())->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]')->toHtml() ?> -
        - -
      • - + getChildHtml('form_checkout_address_create') ?> - isTaxvatEnabled()):?> -
      • getTaxvatHtml() ?>
      • - +
        +
          + isCustomerLoggedIn()): ?>
        • @@ -165,14 +54,16 @@
        • getChildHtml('remember.me') ?> - - isCustomerLoggedIn() && $this->customerHasAddresses()):?> -
        • - getAddress()->getSaveInAddressBook()):?> checked="checked" class="checkbox" /> -
        • - -
        • - + + + isCustomerLoggedIn() && $this->customerHasAddresses()):?> +
        • + getAddress()->getSaveInAddressBook()):?> checked="checked" class="checkbox" /> +
        • + +
        • + + getChildHtml('form.additional.info') ?>
        diff --git a/app/design/frontend/base/default/template/customer/address/edit.phtml b/app/design/frontend/base/default/template/customer/address/edit.phtml index 9d39515de..d1a70cce0 100644 --- a/app/design/frontend/base/default/template/customer/address/edit.phtml +++ b/app/design/frontend/base/default/template/customer/address/edit.phtml @@ -23,98 +23,15 @@
      getMessagesBlock()->toHtml() ?> - -
      + getBlockHtml('formkey') ?> -

      __('Contact Information') ?>

      -
        -
      • - getNameBlockHtml() ?> -
      • -
      • - -
        - -
        -
      • -
      • -
        - -
        - -
        -
        -
        - -
        - -
        -
        -
      • -
      -
      + + getChildHtml('form_customer_address_edit') ?> +
      -

      __('Address') ?>

        - helper('customer/address')->getAttributeValidationClass('street'); ?> -
      • - -
        - -
        -
      • - - helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?> -
      • -
        - -
        -
      • - - helper('customer/address')->isVatAttributeVisible()) : ?> -
      • - -
        - -
        -
      • - -
      • -
        - -
        - -
        -
        -
        - -
        - - - -
        -
        -
      • -
      • -
        - -
        - -
        -
        -
        - -
        - getCountryHtmlSelect() ?> -
        -
        -
      • canSetAsDefaultBilling()) echo ' class="control"' ?>> isDefaultBilling()): ?> __('Default Billing Address') ?> @@ -136,14 +53,12 @@
      -

      __('* Required Fields') ?>

      - +
    • diff --git a/app/design/frontend/base/default/template/customer/form/address.phtml b/app/design/frontend/base/default/template/customer/form/address.phtml deleted file mode 100644 index 0761635cb..000000000 --- a/app/design/frontend/base/default/template/customer/form/address.phtml +++ /dev/null @@ -1,124 +0,0 @@ - - - -
      -

      getAddressId()): ?>__('Edit Address Entry') ?>__('New Address Entry') ?>

      -
      -getMessagesBlock()->toHtml() ?> -
      -
      - - -

      __('Personal Information') ?>

      -
        -
      • - getLayout()->createBlock('customer/widget_name')->setObject($data)->toHtml() ?> -
      • -
      • - -
        - -
        -
      • -
      -
      -
      -

      __('Address') ?>

      -
        - helper('customer/address')->getAttributeValidationClass('street'); ?> -
      • - -
        - -
        -
      • - - helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?> -
      • -
        - -
        -
      • - -
      • -
        - -
        - -
        -
        -
        - -
        - - - -
        -
        -
      • -
      • -
        - -
        - -
        -
        -
        - -
        - -
        -
        -
      • -
      • -
        - -
        - -
        -
        -
        - -
        - -
        -
        -
      • - $type): ?> - isPrimary($type['address_type_id'])) echo ' class="control"' ?>> - isPrimary($type['address_type_id'])): ?> - __("This is My Default %s Address", ucfirst($type['name'])) ?> - - - - - -
      -
      -
      -

      __('* Required Fields') ?>

      - - -
      -
      - diff --git a/app/design/frontend/base/default/template/customer/form/edit.phtml b/app/design/frontend/base/default/template/customer/form/edit.phtml index 1b35fca6d..d13d561bd 100644 --- a/app/design/frontend/base/default/template/customer/form/edit.phtml +++ b/app/design/frontend/base/default/template/customer/form/edit.phtml @@ -14,36 +14,18 @@

      __('Edit Account Information') ?>

    getMessagesBlock()->toHtml() ?> -
    + + getBlockHtml('formkey') ?> + + getChildHtml('form_customer_account_edit') ?> +
    - getBlockHtml('formkey') ?> -

    __('Account Information') ?>

    +

    __('Password Information') ?>

      -
    • - getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?> -
    • -
    • - -
      - -
      -
    • - getLayout()->createBlock('customer/widget_dob') ?> - isEnabled()): ?> -
    • setDate($this->getCustomer()->getDob())->toHtml() ?>
    • - - getLayout()->createBlock('customer/widget_taxvat') ?> - isEnabled()): ?> -
    • setTaxvat($this->getCustomer()->getTaxvat())->toHtml() ?>
    • - - getLayout()->createBlock('customer/widget_gender') ?> - isEnabled()): ?> -
    • setGender($this->getCustomer()->getGender())->toHtml() ?>
    • -
    • - +
      @@ -51,15 +33,10 @@
    • getCustomer()->getChangePassword()==1): ?> checked="checked" class="checkbox" />
    • -
    -
    -
    + HTML); +?> + getSortedDateInputs() ?> + + + +
    + diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/fieldset.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/fieldset.phtml new file mode 100644 index 000000000..b04b739db --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/fieldset.phtml @@ -0,0 +1,27 @@ + +getWrapperTags() ?> +
    +

    __($this->getLabel()) ?>

    +getIsRequired()): ?> +

    __('* Required Fields') ?>

    + + +getChild() as $child): ?> + + toHtml() ?> + + + +
    diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/hidden.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/hidden.phtml new file mode 100644 index 000000000..a4c3522e7 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/hidden.phtml @@ -0,0 +1,17 @@ + + +
    + getFieldParams() ?> /> +
    diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/multiline.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/multiline.phtml new file mode 100644 index 000000000..3e8779cd4 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/multiline.phtml @@ -0,0 +1,21 @@ + +getFields() as $field): ?> +
    + +
    + getFieldParams() ?> /> +
    +
    + diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/multiselect.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/multiselect.phtml new file mode 100644 index 000000000..64f8198aa --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/multiselect.phtml @@ -0,0 +1,22 @@ + +getValue()) ?> + +
    + +
    diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/postcode.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/postcode.phtml new file mode 100644 index 000000000..9a760f7f4 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/postcode.phtml @@ -0,0 +1,17 @@ + + +
    + getFieldParams() ?> /> +
    diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/region.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/region.phtml new file mode 100644 index 000000000..fcc2bc83f --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/region.phtml @@ -0,0 +1,20 @@ + + +
    + + getFieldParams() ?> /> +
    diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/select.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/select.phtml new file mode 100644 index 000000000..224431794 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/select.phtml @@ -0,0 +1,22 @@ + +getValue() ?> + +
    + +
    diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/text.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/text.phtml new file mode 100644 index 000000000..ad652249c --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/text.phtml @@ -0,0 +1,17 @@ + + +
    + getFieldParams() ?> /> +
    diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/textarea.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/textarea.phtml new file mode 100644 index 000000000..5d2fcdfab --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/textarea.phtml @@ -0,0 +1,17 @@ + + +
    + +
    diff --git a/app/design/frontend/rwd/default/template/customer/address/edit.phtml b/app/design/frontend/rwd/default/template/customer/address/edit.phtml deleted file mode 100644 index 7fc6d655e..000000000 --- a/app/design/frontend/rwd/default/template/customer/address/edit.phtml +++ /dev/null @@ -1,148 +0,0 @@ - - -getTitle()): ?> -
    -

    getTitle() ?>

    -
    - -getMessagesBlock()->toHtml() ?> -
    -
    - getBlockHtml('formkey') ?> - - -

    __('Contact Information') ?>

    -

    __('* Required Fields') ?>

    -
      -
    • - getNameBlockHtml() ?> -
    • -
    • - -
      - -
      -
    • -
    • -
      - -
      - -
      -
      -
      - -
      - -
      -
      -
    • -
    -
    -
    -

    __('Address') ?>

    -
      - helper('customer/address')->getAttributeValidationClass('street'); ?> -
    • - -
      - -
      -
    • - - helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?> -
    • - -
      - -
      -
    • - - helper('customer/address')->isVatAttributeVisible()) : ?> -
    • - -
      - -
      -
    • - -
    • -
      - -
      - -
      -
      -
      - -
      - - - -
      -
      -
    • -
    • -
      - -
      - -
      -
      -
      - -
      - getCountryHtmlSelect() ?> -
      -
      -
    • - canSetAsDefaultBilling()) echo ' class="control"' ?>> - isDefaultBilling()): ?> - __('Default Billing Address') ?> - canSetAsDefaultBilling()): ?> - - - - - - canSetAsDefaultShipping()) echo ' class="control"' ?>> - isDefaultShipping()): ?> - __('Default Shipping Address') ?> - canSetAsDefaultShipping()): ?> - - - - - -
    -
    -
    - - -
    -
    - diff --git a/app/design/frontend/rwd/default/template/customer/form/address.phtml b/app/design/frontend/rwd/default/template/customer/form/address.phtml deleted file mode 100644 index d3149e7d4..000000000 --- a/app/design/frontend/rwd/default/template/customer/form/address.phtml +++ /dev/null @@ -1,125 +0,0 @@ - - - -
    -

    getAddressId()): ?>__('Edit Address Entry') ?>__('New Address Entry') ?>

    -
    -getMessagesBlock()->toHtml() ?> -
    -
    - - -

    __('Personal Information') ?>

    -

    __('* Required Fields') ?>

    -
      -
    • - getLayout()->createBlock('customer/widget_name')->setObject($data)->toHtml() ?> -
    • -
    • - -
      - -
      -
    • -
    -
    -
    -

    __('Address') ?>

    -
      - helper('customer/address')->getAttributeValidationClass('street'); ?> -
    • - -
      - -
      -
    • - - helper('customer/address')->getStreetLines(); $_i <= $_n; $_i++): ?> -
    • - -
      - -
      -
    • - -
    • -
      - -
      - -
      -
      -
      - -
      - - - -
      -
      -
    • -
    • -
      - -
      - -
      -
      -
      - -
      - -
      -
      -
    • -
    • -
      - -
      - -
      -
      -
      - -
      - -
      -
      -
    • - $type): ?> - isPrimary($type['address_type_id'])) echo ' class="control"' ?>> - isPrimary($type['address_type_id'])): ?> - __("This is My Default %s Address", ucfirst($type['name'])) ?> - - - - - -
    -
    -
    - - -
    -
    - diff --git a/app/design/frontend/rwd/default/template/customer/form/edit.phtml b/app/design/frontend/rwd/default/template/customer/form/edit.phtml deleted file mode 100644 index 231250dca..000000000 --- a/app/design/frontend/rwd/default/template/customer/form/edit.phtml +++ /dev/null @@ -1,100 +0,0 @@ - -
    -

    __('Edit Account Information') ?>

    -
    -getMessagesBlock()->toHtml() ?> -
    -
    - getBlockHtml('formkey') ?> -

    __('Account Information') ?>

    -

    __('* Required Fields') ?>

    -
      -
    • - getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?> -
    • -
    • - -
      - -
      -
    • - getLayout()->createBlock('customer/widget_dob') ?> - isEnabled()): ?> -
    • setDate($this->getCustomer()->getDob())->toHtml() ?>
    • - - getLayout()->createBlock('customer/widget_taxvat') ?> - isEnabled()): ?> -
    • setTaxvat($this->getCustomer()->getTaxvat())->toHtml() ?>
    • - - getLayout()->createBlock('customer/widget_gender') ?> - isEnabled()): ?> -
    • setGender($this->getCustomer()->getGender())->toHtml() ?>
    • - -
    • - -
      - - - -
      -
    • -
    • - getCustomer()->getChangePassword()==1): ?> checked="checked" class="checkbox" /> -
    • -
    -
    - -
    - - -
    -
    - diff --git a/app/locale/en_US/Mage_Adminhtml.csv b/app/locale/en_US/Mage_Adminhtml.csv index 6d1de7ef2..bb1d64e43 100644 --- a/app/locale/en_US/Mage_Adminhtml.csv +++ b/app/locale/en_US/Mage_Adminhtml.csv @@ -572,9 +572,15 @@ "Manage Attribute Sets","Manage Attribute Sets" "Manage Attributes","Manage Attributes" "Manage Categories","Manage Categories" +"Manage Category Attributes","Manage Category Attributes" +"Manage Category Attribute Sets","Manage Category Attribute Sets" "Manage Content","Manage Content" "Manage Currency Rates","Manage Currency Rates" "Manage Customers","Manage Customers" +"Manage Customer Attributes","Manage Customer Attributes" +"Manage Customer Address Attributes","Manage Customer Address Attributes" +"Manage Customer Address Attribute Sets","Manage Customer Address Attribute Sets" +"Manage Customer Attribute Sets","Manage Customer Attribute Sets", "Manage Options (values of your attribute)","Manage Options (values of your attribute)" "Manage Ratings","Manage Ratings" "Manage Stores","Manage Stores" diff --git a/app/locale/en_US/Mage_Catalog.csv b/app/locale/en_US/Mage_Catalog.csv index e459cb26d..d53e46d36 100644 --- a/app/locale/en_US/Mage_Catalog.csv +++ b/app/locale/en_US/Mage_Catalog.csv @@ -133,8 +133,6 @@ "Cache Lifetime (Seconds)","Cache Lifetime (Seconds)" "Cache refresh needed.","Cache refresh needed." "Can be Divided into Multiple Boxes for Shipping","Can be Divided into Multiple Boxes for Shipping" -"Can be used only with catalog input type Dropdown","Can be used only with catalog input type Dropdown" -"Can be used only with catalog input type Dropdown, Multiple Select and Price","Can be used only with catalog input type Dropdown, Multiple Select and Price" "Can't create image.","Can't create image." "Cancel","Cancel" "Cannot create image.","Cannot create image." @@ -396,6 +394,7 @@ "Manage Label / Options","Manage Label / Options" "Manage Options (values of your attribute)","Manage Options (values of your attribute)" "Manage Product Attributes","Manage Product Attributes" +"Manage Product Attribute Sets","Manage Product Attribute Sets" "Manage Product Sets","Manage Product Sets" "Manage Products","Manage Products" "Manage Stock","Manage Stock" diff --git a/app/locale/en_US/Mage_Core.csv b/app/locale/en_US/Mage_Core.csv index 8b81e3258..0fc10c381 100644 --- a/app/locale/en_US/Mage_Core.csv +++ b/app/locale/en_US/Mage_Core.csv @@ -167,7 +167,6 @@ "If the current frame position does not cover utmost pages, will render link to current position plus/minus this value.","If the current frame position does not cover utmost pages, will render link to current position plus/minus this value." "Image Reprocess Quality","Image Reprocess Quality" "Incorrect credit card expiration date.","Incorrect credit card expiration date." -"Input type ""%value%"" not found in the input types list.","Input type ""%value%"" not found in the input types list." "Invalid MIME type.","Invalid MIME type." "Invalid URL '%value%'.","Invalid URL '%value%'." "Invalid URL scheme.","Invalid URL scheme." diff --git a/app/locale/en_US/Mage_Customer.csv b/app/locale/en_US/Mage_Customer.csv index b6973e836..269964603 100644 --- a/app/locale/en_US/Mage_Customer.csv +++ b/app/locale/en_US/Mage_Customer.csv @@ -31,7 +31,6 @@ "All Store Views","All Store Views" "All countries","All countries" "Already registered?","Already registered?" -"Always optional.","Always optional." "Amount","Amount" "An error occurred while deleting the address.","An error occurred while deleting the address." "An error occurred while retrieving the option value: %s.","An error occurred while retrieving the option value: %s." @@ -213,7 +212,6 @@ "Last Name","Last Name" "Last URL","Last URL" "Leave empty for default (15 minutes).","Leave empty for default (15 minutes)." -"Leave empty for default (2). Valid range: 1-4","Leave empty for default (2). Valid range: 1-4" "Lifetime Sales","Lifetime Sales" "Log In","Log In" "Log Out","Log Out" @@ -242,7 +240,6 @@ "My Dashboard","My Dashboard" "My Orders","My Orders" "Name","Name" -"Name and Address Options","Name and Address Options" "Never","Never" "New Account Email Template","New Account Email Template" "New Address","New Address" @@ -272,7 +269,6 @@ "Not Sent","Not Sent" "Not confirmed, can login","Not confirmed, can login" "Not confirmed, cannot login","Not confirmed, cannot login" -"Number of Lines in a Street Address ","Number of Lines in a Street Address " "Offline","Offline" "Online","Online" "Online Customers","Online Customers" @@ -312,7 +308,6 @@ "Please select a website which contains store view","Please select a website which contains store view" "Please select region, state or province","Please select region, state or province" "Please, check your email for confirmation key.","Please, check your email for confirmation key." -"Prefix Dropdown Options","Prefix Dropdown Options" "Price","Price" "Product","Product" "Product ID","Product ID" @@ -362,7 +357,6 @@ "Save and Continue Edit","Save and Continue Edit" "Saved %d record(s)","Saved %d record(s)" "Select State/Province...","Select State/Province..." -"Semicolon (;) separated values.
    Put semicolon in the beginning for empty first option.
    Leave empty for open text field.","Semicolon (;) separated values.
    Put semicolon in the beginning for empty first option.
    Leave empty for open text field." "Send Auto-Generated Password","Send Auto-Generated Password" "Send From","Send From" "Send Welcome Email","Send Welcome Email" @@ -380,12 +374,6 @@ "Shopping Cart","Shopping Cart" "Shopping Cart - %d item(s)","Shopping Cart - %d item(s)" "Shopping Cart of %1$s - %2$d item(s)","Shopping Cart of %1$s - %2$d item(s)" -"Show Date of Birth","Show Date of Birth" -"Show Gender","Show Gender" -"Show Middle Name (initial)","Show Middle Name (initial)" -"Show Prefix","Show Prefix" -"Show Suffix","Show Suffix" -"Show Tax/VAT Number","Show Tax/VAT Number" "Show VAT Number on Frontend","Show VAT Number on Frontend" "Sign Up for Newsletter","Sign Up for Newsletter" "Skipping import row, required field ""%s"" is not defined.","Skipping import row, required field ""%s"" is not defined." @@ -400,7 +388,6 @@ "Submit","Submit" "Subscribe to Newsletter","Subscribe to Newsletter" "Subscribed to Newsletter?","Subscribed to Newsletter?" -"Suffix Dropdown Options","Suffix Dropdown Options" "Tag Name","Tag Name" "Tax Calculation Based On","Tax Calculation Based On" "Tax Class","Tax Class" @@ -431,8 +418,6 @@ "The password cannot be empty.","The password cannot be empty." "The password must have at least %d characters. Leading or trailing spaces will be ignored.","The password must have at least %d characters. Leading or trailing spaces will be ignored." "The password must have at least 6 characters. Leading or trailing spaces will be ignored.","The password must have at least 6 characters. Leading or trailing spaces will be ignored." -"The suffix that goes after name (Jr., Sr., etc.)","The suffix that goes after name (Jr., Sr., etc.)" -"The title that goes before name (Mr., Mrs., etc.)","The title that goes before name (Mr., Mrs., etc.)" "There are no items in customer's wishlist at the moment","There are no items in customer's wishlist at the moment" "There are no items in customer's shopping cart at the moment","There are no items in customer's shopping cart at the moment" "There is already an account with this email address. If you are sure that it is your email address, click here to get your password and access your account.","There is already an account with this email address. If you are sure that it is your email address, click here to get your password and access your account." diff --git a/app/locale/en_US/Mage_Eav.csv b/app/locale/en_US/Mage_Eav.csv index 13201b521..85e35000c 100644 --- a/app/locale/en_US/Mage_Eav.csv +++ b/app/locale/en_US/Mage_Eav.csv @@ -46,6 +46,8 @@ "Attribute with the same code","Attribute with the same code" "Can't create table: %s","Can't create table: %s" "Catalog Input Type for Store Owner","Catalog Input Type for Store Owner" +"Input type "%s" not found in the input types list.","Input type "%s" not found in the input types list." +"Input Type for Store Owner","Input Type for Store Owner" "Current module EAV entity is undefined","Current module EAV entity is undefined" "Current module pathname is undefined","Current module pathname is undefined" "Data integrity: No header row found for attribute","Data integrity: No header row found for attribute" @@ -101,7 +103,7 @@ "No","No" "No options found in config node %s","No options found in config node %s" "None","None" -"Not shared with other products","Not shared with other products" +"Not shared with other %s","Not shared with other %s" "Problem loading the collection, aborting. Error: %s","Problem loading the collection, aborting. Error: %s" "Problem saving the collection, aborting. Error: %s","Problem saving the collection, aborting. Error: %s" "Required","Required" @@ -116,7 +118,6 @@ "This attribute is used in configurable products","This attribute is used in configurable products" "URL","URL" "Unique Value","Unique Value" -"Unique Value (not shared with other products)","Unique Value (not shared with other products)" "Unknown parameter","Unknown parameter" "Values Required","Values Required" "Wrong attribute group ID","Wrong attribute group ID" @@ -125,3 +126,12 @@ "Wrong type definition for %s","Wrong type definition for %s" "Yes","Yes" "Yes/No","Yes/No" +"Edit Attribute","Edit Attribute" +"The attribute has been deleted.","The attribute has been deleted." +"The attribute has been saved.","The attribute has been saved." +"Manage %s Attributes","Manage %s Attributes" +"Manage %s Attribute Sets","Manage %s Attribute Sets" +"Edit %s Attribute ""%s""","Edit %s Attribute ""%s""" +"New %s Attribute","New %s Attribute" +"All %s of this set will be deleted! Are you sure you want to delete this attribute set?","All %s of this set will be deleted! Are you sure you want to delete this attribute set?" +"All items of this set will be deleted! Are you sure you want to delete this attribute set?","All items of this set will be deleted! Are you sure you want to delete this attribute set?" diff --git a/lib/Varien/Data/Form/Element/Boolean.php b/lib/Varien/Data/Form/Element/Boolean.php new file mode 100644 index 000000000..4a696d841 --- /dev/null +++ b/lib/Varien/Data/Form/Element/Boolean.php @@ -0,0 +1,37 @@ +setValues([ + [ + 'label' => Mage::helper('core')->__('Yes'), + 'value' => 1, + ], + [ + 'label' => Mage::helper('core')->__('No'), + 'value' => 0, + ], + ]); + } +} diff --git a/lib/Varien/Data/Form/Element/Customselect.php b/lib/Varien/Data/Form/Element/Customselect.php new file mode 100644 index 000000000..eda677499 --- /dev/null +++ b/lib/Varien/Data/Form/Element/Customselect.php @@ -0,0 +1,112 @@ +setType('text'); + $this->setExtType('combobox'); + } + + /** + * @return string + */ + #[\Override] + public function getElementHtml() + { + $this->addClass('customselect'); + $html = parent::getElementHtml(); + + $class = 'input-text'; + + $customValue = $this->_escape($this->getCustomValue()); + if ($customValue === '') { + $class .= ' no-display'; + } + + $disabled = ''; + if (in_array('disabled', $this->getHtmlAttributes()) && !empty($this->_data['disabled'])) { + $disabled = 'disabled="disabled"'; + } + + $html .= << + + HTML; + + return $html; + } + + /** + * Return the custom value if used, or an empty string + */ + protected function getCustomValue(): string + { + if ($this->getData('custom_value') === null) { + $value = $this->getValue(); + if ($filter = $this->getValueFilter()) { + $value = $filter->filter($value); + } + if (in_array($value, array_column($this->getData('values'), 'label'))) { + $value = ''; + } + $this->setData('custom_value', (string)$value); + } + return $this->getData('custom_value'); + } + + /** + * Return array of options, including an "Other" option + */ + protected function getValues(): ?array + { + $values = $this->getData('values'); + if (!empty($values)) { + foreach ($values as &$value) { + if (is_array($value)) { + $value['value'] = $value['label']; + } else { + $value = ['value' => (string)$value, 'label' => (string)$value]; + } + } + $values[] = ['value' => $this->getCustomValue(), 'label' => Mage::helper('core')->__('Other')]; + } + return $values; + } +} diff --git a/lib/Varien/Data/Form/Element/Number.php b/lib/Varien/Data/Form/Element/Number.php new file mode 100644 index 000000000..cf4df1a01 --- /dev/null +++ b/lib/Varien/Data/Form/Element/Number.php @@ -0,0 +1,47 @@ +setType('number'); + } + + /** + * @return string + */ + #[\Override] + public function getHtml() + { + $this->addClass('input-text'); + return parent::getHtml(); + } + + /** + * @return array + */ + #[\Override] + public function getHtmlAttributes() + { + return ['type', 'title', 'class', 'style', 'onclick', 'onchange', 'onkeyup', 'disabled', 'readonly', 'min', 'max', 'step', 'tabindex']; + } +} diff --git a/lib/Varien/Data/Form/Element/Select.php b/lib/Varien/Data/Form/Element/Select.php index efd573a1b..c851ca9d2 100644 --- a/lib/Varien/Data/Form/Element/Select.php +++ b/lib/Varien/Data/Form/Element/Select.php @@ -90,7 +90,7 @@ protected function _optionToHtml($option, $selected) $html = '' . "\n"; diff --git a/public/js/mage/adminhtml/eav/attribute.js b/public/js/mage/adminhtml/eav/attribute.js new file mode 100644 index 000000000..71caebc5d --- /dev/null +++ b/public/js/mage/adminhtml/eav/attribute.js @@ -0,0 +1,110 @@ +/** + * Maho + * + * @category Mage + * @package Mage_Adminhtml + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) + * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +/** + * + */ +class EavAttributeEditForm { + + constructor(formId, inputTypeDefs, config = {}) { + this.inputTypeDefs = inputTypeDefs; + this.config = config; + this.formEl = document.getElementById(formId); + if (!this.formEl) { + throw new Error(`Form with ID ${formId} not found in DOM`); + } + this.bindEventListeners(); + this.updateForm(); + } + + bindEventListeners() { + this.formEl.addEventListener('change', this.updateForm.bind(this), { capture: true }); + } + + setRowVisibility(id, isVisible) { + const el = document.getElementById(id); + if (el) { + const tr = el.closest('tr'); + if (isVisible) { + tr.classList.remove('no-display'); + } else { + tr.blur(); + tr.classList.add('no-display'); + } + } + } + + setFieldsetVisibility(id, isVisible) { + const el = document.getElementById(id); + if (el) { + if (isVisible) { + el.classList.remove('no-display'); + el.previousElementSibling.classList.remove('no-display'); + } else { + el.classList.add('no-display'); + el.previousElementSibling.classList.add('no-display'); + } + } + } + + getInputTypeValue() { + const el = document.getElementById('frontend_input'); + return el ? el.value : ''; + } + + updateForm() { + // Before update form callback + if (typeof this.config.callbacks?.beforeUpdateForm === 'function') { + this.config.callbacks.beforeUpdateForm(); + } + + // Reset visibility of all rows and fieldsets + this.formEl.querySelectorAll('tr.no-display').forEach((el) => { + el.classList.remove('no-display'); + }); + this.formEl.querySelectorAll('.fieldset.no-display').forEach((el) => { + el.classList.remove('no-display'); + el.previousElementSibling.classList.remove('no-display'); + }); + + // Manually trigger dependence block conditions + this.formEl.querySelectorAll('input, select, textarea').forEach((el) => { + el.dispatchEvent(new FormElementDependenceEvent()); + }); + + const inputType = this.getInputTypeValue(); + + // Hide fields defined in config.xml eav_inputtypes nodes + const hiddenFields = this.inputTypeDefs[inputType]?.hide_fields ?? []; + for (let field of hiddenFields) { + if (field === '_front_fieldset') { + this.setFieldsetVisibility('front_fieldset', false); + } else if (field === '_scope') { + this.setRowVisibility('is_global', false); + } else { + // TODO, check if is fieldset + this.setRowVisibility(field, false); + } + } + + // Show default value field defined in config.xml eav_inputtypes nodes + let defaultValueField = this.inputTypeDefs[inputType]?.default_value_field; + if (hiddenFields.includes('_default_value')) { + defaultValueField = ''; + } + for (let field of ['text', 'textarea', 'date', 'yesno']) { + this.setRowVisibility(`default_value_${field}`, `default_value_${field}` === defaultValueField); + } + + // After update form callback + if (typeof this.config.callbacks?.afterUpdateForm === 'function') { + this.config.callbacks.afterUpdateForm(); + } + } +} diff --git a/public/js/mage/adminhtml/eav/options.js b/public/js/mage/adminhtml/eav/options.js new file mode 100644 index 000000000..4d7aa648d --- /dev/null +++ b/public/js/mage/adminhtml/eav/options.js @@ -0,0 +1,180 @@ +/** + * Maho + * + * @category Mage + * @package Mage_Adminhtml + * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) + * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + */ + +/** + * + */ +class EavAttributeOptionsForm { + + itemCount = 0; + totalItems = 0; + + constructor(panelId, inputTypeOptionsInfo, template, config = {}) { + this.config = config; + this.inputTypeOptionsInfo = inputTypeOptionsInfo; + this.panelEl = document.getElementById(panelId); + if (!this.panelEl) { + throw new Error(`Panel with ID ${panelId} not found in DOM`); + } + // PrototypeJS Template Instance + this.template = new Template(template, /(^|.|\r|\n)({{(\w+)}})/); + + this.updateOptionsPanel(); + this.bindEventListeners(); + } + + bindEventListeners() { + const addNewOptionBtn = document.getElementById('add_new_option_button'); + if (addNewOptionBtn) { + addNewOptionBtn.addEventListener('click', () => this.add()); + } + const frontendInputEl = document.getElementById('frontend_input'); + if (frontendInputEl) { + frontendInputEl.addEventListener('change', () => this.updateOptionsPanel()); + } + } + + bindRowEventListeners(row) { + const deleteOptionBtn = row.querySelector('.delete-option'); + if (deleteOptionBtn) { + deleteOptionBtn.addEventListener('click', this.remove.bind(this)); + } + const swatchInputEl = row.querySelector('.swatch-option input[type="color"]'); + if (swatchInputEl) { + swatchInputEl.addEventListener('click', this.swatch.bind(this)); + swatchInputEl.addEventListener('change', this.swatch.bind(this)); + } + const swatchDeleteBtn = row.querySelector('.swatch-option .swatch-delete'); + if (swatchDeleteBtn) { + swatchDeleteBtn.addEventListener('click', this.swatchRemove.bind(this)); + } + } + + getFormValue(id) { + const el = document.getElementById(id); + return el ? el.value : ''; + } + + add(option = {}) { + if (!this.panelEl) { + return; + } + const inputType = this.getFormValue('frontend_input'); + + const dummyEl = document.createElement('table'); + dummyEl.innerHTML = this.template.evaluate({ + id: `option_${this.itemCount}`, + intype: this.inputTypeOptionsInfo[inputType]?.type, + swatch_class: option.swatch ? '' : 'swatch-disabled', + ...option, + }); + + const row = dummyEl.querySelector('tr'); + const tbody = this.panelEl.querySelector('tbody'); + + tbody.insertBefore(row, tbody.childNodes[1]); + this.bindRowEventListeners(row); + + if (option.swatch) { + row.querySelectorAll('input[type="color"]').forEach((el) => { + el.value = option.swatch; + }); + } + + this.itemCount++; + this.totalItems++; + this.updateItemsCountField(); + } + + addMany(options) { + for (let option of options) { + this.add(option) + } + } + + remove(event) { + const trEl = event.target.closest('tr'); + if (!trEl) { + return; + } + trEl.querySelectorAll('.delete-flag').forEach((el) => { + el.value = 1; + }); + trEl.classList.add('no-display'); + + this.totalItems--; + this.updateItemsCountField(); + } + + swatch(event) { + const tdEl = event.target.closest('td'); + if (!tdEl) { + return; + } + tdEl.querySelectorAll('input[type="hidden"]').forEach((el) => { + el.disabled = false; + el.value = event.target.value; + }); + tdEl.classList.remove('swatch-disabled'); + } + + swatchRemove(event) { + const msg = Translator.translate('Are you sure to delete this fallback color?'); + if (!confirm(msg)) { + return; + } + const tdEl = event.target.closest('td'); + if (!tdEl) { + return; + } + tdEl.querySelectorAll('input[type="hidden"]').forEach((el) => { + el.disabled = false; + el.removeAttribute('value'); + }); + tdEl.querySelectorAll('input[type="color"]').forEach((el) => { + el.removeAttribute('value'); + }); + tdEl.classList.add('swatch-disabled'); + } + + updateItemsCountField() { + const el = document.getElementById('option-count-check'); + if (el) { + el.value = this.totalItems > 0 ? '1' : ''; + } + } + + updateOptionsPanel() { + if (!this.panelEl) { + return; + } + + // Get the config.xml node for this inputType + const inputType = this.getFormValue('frontend_input'); + const optionsInfo = this.inputTypeOptionsInfo[inputType]; + + // Show / hide options panel and switch "Use Default" inputs to radio / checkbox + if (optionsInfo) { + this.panelEl.classList.remove('no-display'); + this.panelEl.querySelectorAll('input[name="default[]"]').forEach((el) => el.type = optionsInfo.intype); + } else { + this.panelEl.classList.add('no-display'); + } + + // Add required options validation check + const optionsCountCheckEl = document.getElementById('option-count-check'); + if (optionsCountCheckEl) { + if (inputType === 'select' && this.getFormValue('is_required')) { + optionsCountCheckEl.classList.add('required-options-count'); + } else { + optionsCountCheckEl.classList.remove('required-options-count'); + } + } + } +} diff --git a/public/js/varien/form.js b/public/js/varien/form.js index ccdc828aa..8ced439d1 100644 --- a/public/js/varien/form.js +++ b/public/js/varien/form.js @@ -123,7 +123,7 @@ class RegionUpdater { update() { if (this.regions[this.countryEl.value]) { - let def = this.regionSelectEl.getAttribute('defaultValue'); + let def = this.regionSelectEl.dataset.defaultValue ?? this.regionSelectEl.getAttribute('defaultValue'); if (this.regionTextEl) { if (!def) { def = this.regionTextEl.value.toLowerCase(); @@ -281,4 +281,4 @@ class ZipUpdater { } } } -} \ No newline at end of file +} diff --git a/public/skin/adminhtml/default/default/boxes.css b/public/skin/adminhtml/default/default/boxes.css index c613803b6..54d128f4d 100644 --- a/public/skin/adminhtml/default/default/boxes.css +++ b/public/skin/adminhtml/default/default/boxes.css @@ -407,6 +407,7 @@ select.multiselect option { padding:3px 4px; border-bottom:1px solid #ddd; .fieldset-wide .form-list td.value p.note, .fieldset-wide .form-list td.value input.input-text, .fieldset-wide .form-list td.value textarea { width:98% !important; } +.fieldset-wide .form-list td.value select.customselect + input.input-text { width:163px !important; } /*.fieldset-wide .form-list td.value select { display:block; }*/ .fieldset-wide .form-list td.scope-label { white-space:nowrap; width:1px; } .fieldset-wide .form-list td.note { width:120px; } @@ -783,6 +784,7 @@ ul.item-options li { padding-left:.7em; } .entry-edit .order-address input.input-text, .entry-edit .order-address .textarea { width:95% !important; } .entry-edit .order-address .select { width:96.5%; } +.entry-edit .order-address .customselect + input.input-text { width: calc(95% - 166px) !important; } .entry-edit .order-address .validate-vat { text-align:right; padding:10px 0 0; width:96%; } .order-search-items .entry-edit .grid { height:610px; overflow:auto; } .order-search-items .entry-edit .grid table { width:99.9%; } diff --git a/public/skin/adminhtml/default/default/form.css b/public/skin/adminhtml/default/default/form.css index 9b71553d3..568b31de5 100644 --- a/public/skin/adminhtml/default/default/form.css +++ b/public/skin/adminhtml/default/default/form.css @@ -235,6 +235,9 @@ button { padding-left: 0 !important; } .form-list td.value input.input-text, .form-list td.value textarea, .form-list td.value select { width: 330px; } + .form-list td.value select.customselect, .form-list td.value select.customselect + input.input-text { + width: 163px; } + .form-list td.value p.note { color: #202856; font-size: 11px; @@ -244,24 +247,24 @@ button { padding: 12px 12px 14px; font-size: 18px; } -td:has(input.swatch-option) { +td.swatch-option { + position: relative; display: flex; gap: 2px; } - td:has(input.swatch-option) .swatch-delete { - cursor: pointer; + td.swatch-option .swatch-delete { + padding: 0; width: 14px; height: 14px; - display: flex; - justify-content: center; + line-height: 14px; font-size: 10px; background: #e63a3a; color: #fff; border-radius: 2px; } - td:has(input.swatch-option) .swatch-option { + td.swatch-option input[type=color] { width: 26px !important; height: 26px; } -td:has(input.swatch-disabled) { +td.swatch-option.swatch-disabled { background-image: url('data:image/svg+xml,placeholder'); background-repeat: no-repeat; outline: 1px solid #c8c8c8; @@ -273,9 +276,9 @@ td:has(input.swatch-disabled) { display: block; background-position: center center; border-radius: 2px; } - td:has(input.swatch-disabled) .swatch-option { + td.swatch-option.swatch-disabled input[type=color] { opacity: 0; } - td:has(input.swatch-disabled) .swatch-delete { + td.swatch-option.swatch-disabled .swatch-delete { display: none; } /*# sourceMappingURL=form.css.map */ diff --git a/public/skin/frontend/rwd/default/css/styles.css b/public/skin/frontend/rwd/default/css/styles.css index 0cee95f8a..bef95207a 100644 --- a/public/skin/frontend/rwd/default/css/styles.css +++ b/public/skin/frontend/rwd/default/css/styles.css @@ -2083,7 +2083,7 @@ body.customer-account .data-table .show-details .summary-collapse:hover:before { } .fieldset + .fieldset { - margin-top: 5px; + margin-top: 30px; } form .legend { @@ -2318,6 +2318,16 @@ p.required, .form-list .control { margin-bottom: 10px; } +.form-list .date-month, +.form-list .date-day { + width: 60px; + float: left; + margin-right: 10px; +} +.form-list .date-year { + width: 100px; + float: left; +} /* Turn the label of controls (radio/checkbox) into a button style that wraps the input */ .form-list .control, @@ -6946,9 +6956,6 @@ body:not(.opc-has-progressed-from-login) .opc.opc-firststep-login .section#opc-l /* ============================================ * * Customer * ============================================ */ -.customer-account-login .scaffold-form label:first-child { - width: 115px; -} .customer-account-login .col2-set .buttons-set { text-align: left; border-top: 0; @@ -7002,10 +7009,6 @@ body:not(.opc-has-progressed-from-login) .opc.opc-firststep-login .section#opc-l } } -.customer-account-create .scaffold-form label:first-child { - width: 140px; -} - .opc #opc-login p:not(.required) { font-style: italic; font-size: 0.813rem;