From 1ff7e68b133cf84f8c199eedaa3f4236bfd75a24 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 3 Aug 2022 07:37:59 -0700 Subject: [PATCH 001/113] Mage_Eav: Add generic grid code --- .../Mage/Eav/Block/Adminhtml/Attribute.php | 49 ++ .../Eav/Block/Adminhtml/Attribute/Edit.php | 81 ++++ .../Block/Adminhtml/Attribute/Edit/Form.php | 30 ++ .../Attribute/Edit/Main/Abstract.php | 8 +- .../Adminhtml/Attribute/Edit/Tab/Main.php | 112 +++++ .../Adminhtml/Attribute/Edit/Tab/Options.php | 23 + .../Block/Adminhtml/Attribute/Edit/Tabs.php | 51 ++ .../Eav/Block/Adminhtml/Attribute/Grid.php | 63 +++ .../Adminhtml/Attribute/Grid/Abstract.php | 6 +- .../Eav/Block/Adminhtml/Attribute/Set.php | 54 +++ .../Block/Adminhtml/Attribute/Set/Grid.php | 72 +++ .../Block/Adminhtml/Attribute/Set/Main.php | 415 ++++++++++++++++ .../Attribute/Set/Main/Formattribute.php | 65 +++ .../Attribute/Set/Main/Formgroup.php | 81 ++++ .../Adminhtml/Attribute/Set/Main/Formset.php | 86 ++++ .../Attribute/Set/Main/Tree/Attribute.php | 33 ++ .../Attribute/Set/Main/Tree/Group.php | 33 ++ .../Adminhtml/Attribute/Set/Toolbar/Add.php | 82 ++++ .../Adminhtml/Attribute/Abstract.php | 337 +++++++++++++ .../Eav/Controller/Adminhtml/Set/Abstract.php | 195 ++++++++ app/code/core/Mage/Eav/Helper/Data.php | 77 +++ .../core/Mage/Eav/Model/Entity/Attribute.php | 4 + .../Eav/Model/Resource/Entity/Attribute.php | 7 +- app/code/core/Mage/Eav/etc/config.xml | 5 + .../default/template/eav/attribute/js.phtml | 174 +++++++ .../template/eav/attribute/set/main.phtml | 450 ++++++++++++++++++ .../attribute/set/main/tree/attribute.phtml | 20 + .../eav/attribute/set/main/tree/group.phtml | 21 + .../eav/attribute/set/toolbar/add.phtml | 35 ++ app/locale/en_US/Mage_Eav.csv | 12 + 30 files changed, 2673 insertions(+), 8 deletions(-) create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Form.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Main.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Options.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tabs.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php create mode 100644 app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php create mode 100644 app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php create mode 100644 app/design/adminhtml/default/default/template/eav/attribute/js.phtml create mode 100644 app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml create mode 100644 app/design/adminhtml/default/default/template/eav/attribute/set/main/tree/attribute.phtml create mode 100644 app/design/adminhtml/default/default/template/eav/attribute/set/main/tree/group.phtml create mode 100644 app/design/adminhtml/default/default/template/eav/attribute/set/toolbar/add.phtml 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..ef4ad4eb6 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php @@ -0,0 +1,49 @@ + + */ + +class Mage_Eav_Block_Adminhtml_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Container +{ + public function __construct() + { + $this->_blockGroup = 'eav'; + $this->_controller = 'adminhtml_attribute'; + if ($entity_type = Mage::registry('entity_type')) { + $this->_headerText = Mage::helper('eav')->__('Manage %s Attributes', Mage::helper('eav')->formatTypeCode($entity_type)); + } else { + $this->_headerText = Mage::helper('eav')->__('Manage Attributes'); + } + $this->_addButtonLabel = Mage::helper('eav')->__('Add New Attribute'); + parent::__construct(); + } + + public function getHeaderCssClass() + { + return 'icon-head head-eav-attribute'; + } + +} 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..e56fe4674 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php @@ -0,0 +1,81 @@ +_objectId = 'attribute_id'; + $this->_blockGroup = 'eav'; + $this->_controller = 'adminhtml_attribute'; + + parent::__construct(); + + $this->_addButton( + 'save_and_edit_button', + array( + 'label' => Mage::helper('eav')->__('Save and Continue Edit'), + 'onclick' => 'saveAndContinueEdit()', + 'class' => 'save' + ), + 100 + ); + + $this->_updateButton('save', 'label', Mage::helper('eav')->__('Save Attribute')); + $this->_updateButton('save', 'onclick', 'saveAttribute()'); + + if (!Mage::registry('entity_attribute')->getIsUserDefined()) { + $this->_removeButton('delete'); + } else { + $this->_updateButton('delete', 'label', Mage::helper('eav')->__('Delete Attribute')); + } + } + + 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('eav')->__('Edit %s Attribute "%s"', Mage::helper('eav')->formatTypeCode(Mage::registry('entity_type')), $this->escapeHtml($frontendLabel)); + } + else { + return Mage::helper('eav')->__('New %s Attribute', Mage::helper('eav')->formatTypeCode(Mage::registry('entity_type'))); + } + } + + public function getValidationUrl() + { + return $this->getUrl('*/*/validate', array('_current'=>true)); + } + + public function getSaveUrl() + { + return $this->getUrl('*/*/save', array('_current'=>true, 'back'=>null)); + } + + public function getHeaderCssClass() + { + return 'icon-head head-eav-attribute'; + } + +} 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..7a37b2b7a --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Form.php @@ -0,0 +1,30 @@ + '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 a60acadc1..e01d26dde 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 @@ -21,7 +21,7 @@ abstract class Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract extends Mag 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,7 +31,7 @@ public function setAttributeObject($attribute) } /** - * @return Mage_Catalog_Model_Resource_Eav_Attribute + * @return Mage_Eav_Model_Entity_Attribute */ public function getAttributeObject() { @@ -85,8 +85,8 @@ protected function _prepareForm() $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'), + 'label' => Mage::helper('eav')->__('Input Type for Store Owner'), + 'title' => Mage::helper('eav')->__('Input Type for Store Owner'), 'value' => 'text', 'values' => $inputTypes ]); 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..430ae987c --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Main.php @@ -0,0 +1,112 @@ +getAttributeObject(); + $attributeTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); + /* @var $form Varien_Data_Form */ + $form = $this->getForm(); + /* @var $fieldset Varien_Data_Form_Element_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.') + ); + + $fieldset->getElements() + ->searchById('is_unique') + ->setData( + 'title', + Mage::helper('eav')->__('Unique Value (not shared with other %s)', strtolower(Mage::helper('eav')->formatTypeCode($attributeTypeCode))) + )->setData( + 'note', + Mage::helper('eav')->__('Not shared with other %s', strtolower(Mage::helper('eav')->formatTypeCode($attributeTypeCode))) + ); + + $frontendInputElm = $form->getElement('frontend_input'); + $additionalTypes = array(); + + $response = new Varien_Object(); + $response->setTypes(array()); + Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_types", array('response'=>$response)); + $_disabledTypes = array(); + $_hiddenFields = array(); + foreach ($response->getTypes() as $type) { + $additionalTypes[] = $type; + if (isset($type['hide_fields'])) { + $_hiddenFields[$type['value']] = $type['hide_fields']; + } + if (isset($type['disabled_types'])) { + $_disabledTypes[$type['value']] = $type['disabled_types']; + } + } + Mage::register('attribute_type_hidden_fields', $_hiddenFields); + Mage::register('attribute_type_disabled_types', $_disabledTypes); + + $frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes); + $frontendInputElm->setValues($frontendInputValues); + + $scopes = array( + Mage_Eav_Model_Entity_Attribute::SCOPE_STORE =>Mage::helper('eav')->__('Store View'), + Mage_Eav_Model_Entity_Attribute::SCOPE_WEBSITE =>Mage::helper('eav')->__('Website'), + Mage_Eav_Model_Entity_Attribute::SCOPE_GLOBAL =>Mage::helper('eav')->__('Global'), + ); + + if ($attributeObject->getAttributeCode() == 'status') { + unset($scopes[Mage_Eav_Model_Entity_Attribute::SCOPE_STORE]); + } + + $response = new Varien_Object(); + $response->setScopes($scopes); + $response->setAttribute($attributeObject); + Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_scopes", array('response'=>$response)); + + $fieldset->addField('is_global', 'select', array( + 'name' => 'is_global', + 'label' => Mage::helper('eav')->__('Scope'), + 'title' => Mage::helper('eav')->__('Scope'), + 'note' => Mage::helper('eav')->__('Declare attribute value saving scope'), + 'values'=> $response->getScopes(), + ), 'attribute_code'); + + Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_edit_prepare_form", array( + 'form' => $form, + 'attribute' => $attributeObject + )); + + 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..2c3d11f41 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Options.php @@ -0,0 +1,23 @@ +setId('eav_attribute_tabs'); + $this->setDestElementId('edit_form'); + $this->setTitle(Mage::helper('eav')->__('Attribute Information')); + } + + protected function _beforeToHtml() + { + $this->addTab('main', array( + 'label' => Mage::helper('eav')->__('Properties'), + 'title' => Mage::helper('eav')->__('Properties'), + 'content' => $this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tab_main')->toHtml(), + 'active' => true + )); + + $model = Mage::registry('entity_attribute'); + + $this->addTab('labels', array( + 'label' => Mage::helper('eav')->__('Manage Label / Options'), + 'title' => Mage::helper('eav')->__('Manage Label / Options'), + 'content' => $this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tab_options')->toHtml(), + )); + + return parent::_beforeToHtml(); + } + +} 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..dc2568137 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php @@ -0,0 +1,63 @@ +getEntityAttributeCollection()); + $collection->setEntityTypeFilter($entity_type->getEntityTypeId()); + $this->setCollection($collection); + } + return parent::_prepareCollection(); + } + + /** + * Prepare attributes grid columns + * + * @return $this + */ + protected function _prepareColumns() + { + parent::_prepareColumns(); + + $this->addColumn('is_global', array( + 'header'=>Mage::helper('eav')->__('Scope'), + 'sortable'=>true, + 'index'=>'is_global', + 'type' => 'options', + 'options' => array( + Mage_Eav_Model_Entity_Attribute::SCOPE_STORE =>Mage::helper('eav')->__('Store View'), + Mage_Eav_Model_Entity_Attribute::SCOPE_WEBSITE =>Mage::helper('eav')->__('Website'), + Mage_Eav_Model_Entity_Attribute::SCOPE_GLOBAL =>Mage::helper('eav')->__('Global'), + ), + 'align' => 'center', + )); + + return $this; + } +} 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 4497dcc16..176ba94fa 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,10 +11,10 @@ */ /** - * Product attributes grid + * Eav attributes grid * * @category Mage - * @package Mage_Adminhtml + * @package Mage_Eav */ abstract class Mage_Eav_Block_Adminhtml_Attribute_Grid_Abstract extends Mage_Adminhtml_Block_Widget_Grid { @@ -78,7 +78,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..b22883bb3 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php @@ -0,0 +1,54 @@ + + */ + +class Mage_Eav_Block_Adminhtml_Attribute_Set extends Mage_Adminhtml_Block_Widget_Grid_Container +{ + public function __construct() + { + $this->_blockGroup = 'eav'; + $this->_controller = 'adminhtml_attribute_set'; + if ($entity_type = Mage::registry('entity_type')) { + $this->_headerText = Mage::helper('eav')->__('Manage %s Attribute Sets', Mage::helper('eav')->formatTypeCode($entity_type)); + } else { + $this->_headerText = Mage::helper('eav')->__('Manage Attribute Sets'); + } + $this->_addButtonLabel = Mage::helper('eav')->__('Add New Set'); + parent::__construct(); + } + + public function getCreateUrl() + { + return $this->getUrl('*/*/add'); + } + + public function getHeaderCssClass() + { + return 'icon-head head-eav-attribute-sets'; + } + +} 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..4251d08ac --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php @@ -0,0 +1,72 @@ + + */ +class Mage_Eav_Block_Adminhtml_Attribute_Set_Grid extends Mage_Adminhtml_Block_Widget_Grid +{ + + public function __construct() + { + parent::__construct(); + $this->setId('setGrid'); + $this->setDefaultSort('set_name'); + $this->setDefaultDir('ASC'); + $this->setSaveParametersInSession(true); + } + + protected function _prepareCollection() + { + $collection = Mage::getResourceModel('eav/entity_attribute_set_collection') + ->setEntityTypeFilter(Mage::registry('entity_type')->getEntityTypeId()); + + $this->setCollection($collection); + return parent::_prepareCollection(); + } + + protected function _prepareColumns() + { + /*$this->addColumn('set_id', array( + 'header' => Mage::helper('eav')->__('ID'), + 'align' => 'right', + 'sortable' => true, + 'width' => '50px', + 'index' => 'attribute_set_id', + ));*/ + + $this->addColumn('set_name', array( + 'header' => Mage::helper('eav')->__('Set Name'), + 'align' => 'left', + 'sortable' => true, + 'index' => 'attribute_set_name', + )); + } + + public function getRowUrl($row) + { + return $this->getUrl('*/*/edit', array('id'=>$row->getAttributeSetId())); + } + +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php new file mode 100644 index 000000000..23ccec4bc --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php @@ -0,0 +1,415 @@ + + */ +class Mage_Eav_Block_Adminhtml_Attribute_Set_Main extends Mage_Adminhtml_Block_Template +{ + /** + * Initialize template + * + */ + protected function _construct() + { + $this->setTemplate('eav/attribute/set/main.phtml'); + } + + /** + * Prepare Global Layout + * + * @return $this + */ + protected function _prepareLayout() + { + $setId = $this->_getSetId(); + + $this->setChild('group_tree', + $this->getLayout()->createBlock('eav/adminhtml_attribute_set_main_tree_group') + ); + + $this->setChild('edit_set_form', + $this->getLayout()->createBlock('eav/adminhtml_attribute_set_main_formset') + ); + + $this->setChild('delete_group_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + 'label' => Mage::helper('eav')->__('Delete Selected Group'), + 'onclick' => 'editSet.submit();', + 'class' => 'delete' + ))); + + $this->setChild('add_group_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + 'label' => Mage::helper('eav')->__('Add New'), + 'onclick' => 'editSet.addGroup();', + 'class' => 'add' + ))); + + $this->setChild('back_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + 'label' => Mage::helper('eav')->__('Back'), + 'onclick' => 'setLocation(\''.$this->getUrl('*/*/').'\')', + 'class' => 'back' + ))); + + $this->setChild('reset_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + 'label' => Mage::helper('eav')->__('Reset'), + 'onclick' => 'window.location.reload()' + ))); + + $this->setChild('save_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + 'label' => Mage::helper('eav')->__('Save Attribute Set'), + 'onclick' => 'editSet.save();', + 'class' => 'save' + ))); + + if ($entity_type = Mage::registry('entity_type')) { + $deleteConfirmMessage = $this->jsQuoteEscape(Mage::helper('eav') + ->__('All %s of this set will be deleted! Are you sure you want to delete this attribute set?')); + } else { + $deleteConfirmMessage = $this->jsQuoteEscape(Mage::helper('eav') + ->__('All items of this set will be deleted! Are you sure you want to delete this attribute set?')); + } + $deleteUrl = $this->getUrlSecure('*/*/delete', array('id' => $setId)); + $this->setChild('delete_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + 'label' => Mage::helper('eav')->__('Delete Attribute Set'), + 'onclick' => 'deleteConfirm(\'' . $deleteConfirmMessage . '\', \'' . $deleteUrl . '\')', + 'class' => 'delete' + ))); + + $this->setChild('rename_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + '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('edit_set_form'); + } + + /** + * Retrieve Block Header Text + * + * @return string + */ + protected function _getHeader() + { + return Mage::helper('eav')->__("Edit Attribute Set '%s'", $this->_getAttributeSet()->getAttributeSetName()); + } + + /** + * Retrieve Attribute Set Save URL + * + * @return string + */ + public function getMoveUrl() + { + return $this->getUrl('*/*/save', array('id' => $this->_getSetId())); + } + + /** + * Retrieve Attribute Set Group Save URL + * + * @return string + */ + public function getGroupUrl() + { + return $this->getUrl('*/*/save', array('id' => $this->_getSetId())); + } + + /** + * Retrieve Attribute Set Group Tree as JSON format + * + * @return string + */ + public function getGroupTreeJson() + { + $items = array(); + $setId = $this->_getSetId(); + + /* @var $groups Mage_Eav_Model_Mysql4_Entity_Attribute_Group_Collection */ + $groups = Mage::getModel('eav/entity_attribute_group') + ->getResourceCollection() + ->setAttributeSetFilter($setId) + ->setSortOrder() + ->load(); + + /* @var $entity_type Mage_Eav_Model_Entity_Type */ + $entity_type = Mage::registry('entity_type'); + + /* @var $node Mage_Eav_Model_Entity_Attribute_Group */ + foreach ($groups as $node) { + $item = array(); + $item['text'] = $node->getAttributeGroupName(); + $item['id'] = $node->getAttributeGroupId(); + $item['cls'] = 'folder'; + $item['allowDrop'] = true; + $item['allowDrag'] = true; + + /** @var Mage_Eav_Model_Entity_Attribute $nodeChildren */ + $nodeChildren = Mage::getResourceModel($entity_type->getEntityAttributeCollection()); + $nodeChildren->setEntityTypeFilter($entity_type->getEntityTypeId()) + ->setAttributeGroupFilter($node->getId()) + ->load(); + + if ($nodeChildren->getSize() > 0) { + $item['children'] = array(); + foreach ($nodeChildren->getItems() as $child) { + /* @var $child Mage_Eav_Model_Entity_Attribute */ + $attr = array( + 'text' => $child->getAttributeCode(), + 'id' => $child->getAttributeId(), + 'cls' => (!$child->getIsUserDefined()) ? 'system-leaf' : 'leaf', + 'allowDrop' => false, + 'allowDrag' => true, + 'leaf' => true, + 'is_user_defined' => $child->getIsUserDefined(), + 'entity_id' => $child->getEntityAttributeId() + ); + + $item['children'][] = $attr; + } + } + + $items[] = $item; + } + + return Mage::helper('core')->jsonEncode($items); + } + + /** + * Retrieve Unused in Attribute Set Attribute Tree as JSON + * + * @return string + */ + public function getAttributeTreeJson() + { + $items = array(); + $setId = $this->_getSetId(); + + /* @var $entity_type Mage_Eav_Model_Entity_Type */ + $entity_type = Mage::registry('entity_type'); + + /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection */ + $collection = Mage::getResourceModel($entity_type->getEntityAttributeCollection()); + $collection->setEntityTypeFilter($entity_type->getEntityTypeId()) + ->setAttributeSetFilter($setId) + ->load(); + + $attributesIds = array('0'); + /* @var $item Mage_Eav_Model_Entity_Attribute */ + foreach ($collection->getItems() as $item) { + $attributesIds[] = $item->getAttributeId(); + } + + /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $attributes */ + $attributes = Mage::getResourceModel($entity_type->getEntityAttributeCollection()); + $attributes->setEntityTypeFilter($entity_type->getEntityTypeId()) + ->setAttributesExcludeFilter($attributesIds) + ->setOrder('attribute_code', 'asc') + ->load(); + + foreach ($attributes as $child) { + $attr = array( + 'text' => $child->getAttributeCode(), + 'id' => $child->getAttributeId(), + 'cls' => 'leaf', + 'allowDrop' => false, + 'allowDrag' => true, + 'leaf' => true, + 'is_user_defined' => $child->getIsUserDefined(), + 'entity_id' => $child->getEntityId() + ); + + $items[] = $attr; + } + + if (count($items) == 0) { + $items[] = array( + 'text' => Mage::helper('eav')->__('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::registry('entity_type')->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 + */ + protected function _toHtml() + { + $type = Mage::registry('entity_type')->getEntityTypeCode(); + Mage::dispatchEvent("adminhtml_{$type}_attribute_set_main_html_before", array('block' => $this)); + return parent::_toHtml(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php new file mode 100644 index 000000000..99ab6c967 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php @@ -0,0 +1,65 @@ + + */ + +class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Formattribute extends Mage_Adminhtml_Block_Widget_Form +{ + public function __construct() + { + parent::__construct(); + } + + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + + $fieldset = $form->addFieldset('set_fieldset', array('legend'=>Mage::helper('eav')->__('Add New Attribute'))); + + $fieldset->addField('new_attribute', 'text', + array( + 'label' => Mage::helper('eav')->__('Name'), + 'name' => 'new_attribute', + 'required' => true, + ) + ); + + $fieldset->addField('submit', 'note', + array( + 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData(array( + 'label' => Mage::helper('eav')->__('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/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php new file mode 100644 index 000000000..dcdf46643 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php @@ -0,0 +1,81 @@ + + */ + +class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Formgroup extends Mage_Adminhtml_Block_Widget_Form +{ + public function __construct() + { + parent::__construct(); + } + + protected function _prepareForm() + { + $form = new Varien_Data_Form(); + + $fieldset = $form->addFieldset('set_fieldset', array('legend'=>Mage::helper('eav')->__('Add New Group'))); + + $fieldset->addField('attribute_group_name', 'text', + array( + 'label' => Mage::helper('eav')->__('Name'), + 'name' => 'attribute_group_name', + 'required' => true, + ) + ); + + $fieldset->addField('submit', 'note', + array( + 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData(array( + 'label' => Mage::helper('eav')->__('Add Group'), + 'onclick' => 'this.form.submit();', + 'class' => 'add' + )) + ->toHtml(), + ) + ); + + $fieldset->addField('attribute_set_id', 'hidden', + array( + 'name' => 'attribute_set_id', + 'value' => $this->_getSetId(), + ) + + ); + + $form->setUseContainer(true); + $form->setMethod('post'); + $form->setAction($this->getUrl('*/*/save')); + $this->setForm($form); + return $this; + } + + protected function _getSetId() + { + return ( intval($this->getRequest()->getParam('id')) > 0 ) + ? intval($this->getRequest()->getParam('id')) + : Mage::registry('entity_type')->getDefaultAttributeSetId(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php new file mode 100644 index 000000000..301d9ad99 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php @@ -0,0 +1,86 @@ + + */ + +class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Formset extends Mage_Adminhtml_Block_Widget_Form +{ + public function __construct() + { + parent::__construct(); + } + + /** + * Prepares attribute set form + * + */ + 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', array('legend'=> Mage::helper('eav')->__('Edit Set Name'))); + $fieldset->addField('attribute_set_name', 'text', array( + 'label' => Mage::helper('eav')->__('Name'), + 'note' => Mage::helper('eav')->__('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', array( + 'name' => 'gotoEdit', + 'value' => '1' + )); + + /** @var Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection @collection */ + $collection = Mage::getModel('eav/entity_attribute_set') + ->getResourceCollection(); + + $sets = $collection->setEntityTypeFilter(Mage::registry('entity_type')->getEntityTypeId()) + ->setOrder('attribute_set_name', 'asc') + ->load() + ->toOptionArray(); + + $fieldset->addField('skeleton_set', 'select', array( + '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/Set/Main/Tree/Attribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php new file mode 100644 index 000000000..8bd7ad8d0 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php @@ -0,0 +1,33 @@ + + */ + +class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Tree_Attribute extends Mage_Adminhtml_Block_Template +{ + protected function _construct() + { + $this->setTemplate('eav/attribute/set/main/tree/attribute.phtml'); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php new file mode 100644 index 000000000..e4eba07c4 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php @@ -0,0 +1,33 @@ + + */ + +class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Tree_Group extends Mage_Adminhtml_Block_Template +{ + protected function _construct() + { + $this->setTemplate('eav/attribute/set/main/tree/group.phtml'); + } +} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php new file mode 100644 index 000000000..b87f5c3a9 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php @@ -0,0 +1,82 @@ + + */ +class Mage_Eav_Block_Adminhtml_Attribute_Set_Toolbar_Add extends Mage_Adminhtml_Block_Template +{ + protected function _construct() + { + $this->setTemplate('eav/attribute/set/toolbar/add.phtml'); + } + + protected function _prepareLayout() + { + $this->setChild('save_button', + $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData(array( + '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(array( + 'label' => Mage::helper('eav')->__('Back'), + 'onclick' => 'setLocation(\''.$this->getUrl('*/*/').'\')', + 'class' => 'back' + ))); + + $this->setChild('setForm', + $this->getLayout()->createBlock('eav/adminhtml_attribute_set_main_formset') + ); + return parent::_prepareLayout(); + } + + protected function _getHeader() + { + return Mage::helper('eav')->__('Add New Attribute Set'); + } + + protected function getSaveButtonHtml() + { + return $this->getChildHtml('save_button'); + } + + protected function getBackButtonHtml() + { + return $this->getChildHtml('back_button'); + } + + protected function getFormHtml() + { + return $this->getChildHtml('setForm'); + } + + protected function getFormId() + { + return $this->getChild('setForm')->getForm()->getId(); + } +} 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..a2818da62 --- /dev/null +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -0,0 +1,337 @@ + + */ + +abstract class Mage_Eav_Controller_Adminhtml_Attribute_Abstract extends Mage_Adminhtml_Controller_Action +{ + + /** @var string $_entityCode */ + protected $_entityCode; + + /** @var Mage_Eav_Model_Entity_Type $_entityType */ + protected $_entityType; + + /** + * Controller predispatch method + * + * @return Mage_Adminhtml_Controller_Action + */ + public function preDispatch() + { + $this->_setForcedFormKeyActions('delete'); + $this->_entityType = Mage::getModel('eav/entity')->setType($this->_entityCode)->getEntityType(); + if (!Mage::registry('entity_type')) { + Mage::register('entity_type', $this->_entityType); + } + return parent::preDispatch(); + } + + protected function _initAction() + { + return $this->loadLayout(); + } + + public function indexAction() + { + $this->_initAction() + ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute')) + ->renderLayout(); + } + + public function newAction() + { + $this->_forward('edit'); + } + + public function editAction() + { + $id = $this->getRequest()->getParam('attribute_id'); + $model = Mage::getModel($this->_entityType->getAttributeModel()) + ->setEntityTypeId($this->_entityType->getEntityTypeId()); + if ($id) { + $model->load($id); + + if (! $model->getId()) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('eav')->__('This attribute no longer exists')); + $this->_redirect('*/*/'); + return; + } + + // entity type check + if ($model->getEntityTypeId() != $this->_entityType->getEntityTypeId()) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('eav')->__('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('eav')->__('Edit Attribute') + : Mage::helper('eav')->__('New Attribute'); + + $this->_addBreadcrumb($item, $item); + + $this->_addLeft($this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tabs')) + ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_edit')); + + $this->_addJs( + $this->getLayout()->createBlock('adminhtml/template') + ->setTemplate('eav/attribute/js.phtml') + ); + + $this->renderLayout(); + + } + + public function validateAction() + { + $response = new Varien_Object(); + $response->setError(false); + + $attributeCode = $this->getRequest()->getParam('attribute_code'); + $attributeId = $this->getRequest()->getParam('attribute_id'); + + /** @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( + Mage::helper('eav')->__('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) { + //labels + $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() + { + $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_Eav_Model_Entity_Attribute $model */ + $model = Mage::getModel($this->_entityType->getAttributeModel()); + /** @var Mage_Eav_Helper_Data $helper */ + $helper = Mage::helper('eav'); + + $id = $this->getRequest()->getParam('attribute_id'); + + //validate attribute_code + if (isset($data['attribute_code'])) { + $validatorAttrCode = new Zend_Validate_Regex(array('pattern' => '/^(?!event$)[a-z][a-z_0-9]{1,254}$/')); + if (!$validatorAttrCode->isValid($data['attribute_code'])) { + $session->addError( + Mage::helper('eav')->__('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', array('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', array('attribute_id' => $id, '_current' => true)); + return; + } + } + + if ($id) { + $model->load($id); + + if (!$model->getId()) { + $session->addError( + Mage::helper('eav')->__('This Attribute no longer exists')); + $this->_redirect('*/*/'); + return; + } + + // entity type check + if ($model->getEntityTypeId() != $this->_entityType->getEntityTypeId()) { + $session->addError( + Mage::helper('eav')->__('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 (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 ($model) { + $data['entity_type_id'] = $model->getEntityTypeId(); + } + + //filter + $data = $this->_filterPostData($data); + $model->addData($data); + + if (!$id) { + $model->setEntityTypeId($this->_entityType->getEntityTypeId()); + $model->setIsUserDefined(1); + } + + + if ($this->getRequest()->getParam('set') && $this->getRequest()->getParam('group')) { + // For creating attribute on page we need specify attribute set and group + $model->setAttributeSetId($this->getRequest()->getParam('set')); + $model->setAttributeGroupId($this->getRequest()->getParam('group')); + } + + Mage::dispatchEvent( + "adminhtml_{$this->_entityCode}_attribute_edit_prepare_save", + array('object' => $model, 'request' => $this->getRequest()) + ); + + try { + $model->save(); + $session->addSuccess( + Mage::helper('eav')->__('The attribute has been saved.')); + + /** + * Clear translation cache because attribute labels are stored in translation + */ + Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG)); + $session->setAttributeData(false); + if ($redirectBack) { + $this->_redirect('*/*/edit', array('attribute_id' => $model->getId(),'_current'=>true)); + } else { + $this->_redirect('*/*/', array()); + } + return; + } catch (Exception $e) { + $session->addError($e->getMessage()); + $session->setAttributeData($data); + $this->_redirect('*/*/edit', array('attribute_id' => $id, '_current' => true)); + return; + } + } + $this->_redirect('*/*/'); + } + + public function deleteAction() + { + if ($id = $this->getRequest()->getParam('attribute_id')) { + $model = Mage::getModel($this->_entityType->getAttributeModel()); + + // entity type check + $model->load($id); + if ($model->getEntityTypeId() != $this->_entityType->getEntityTypeId() || !$model->getIsUserDefined()) { + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('eav')->__('This attribute cannot be deleted.')); + $this->_redirect('*/*/'); + return; + } + + try { + $model->delete(); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('eav')->__('The attribute has been deleted.')); + $this->_redirect('*/*/'); + return; + } catch (Exception $e) { + Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); + $this->_redirect('*/*/edit', array('attribute_id' => $this->getRequest()->getParam('attribute_id'))); + return; + } + } + Mage::getSingleton('adminhtml/session')->addError( + Mage::helper('eav')->__('Unable to find an attribute to delete.')); + $this->_redirect('*/*/'); + } + +} 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..d9aaebd0f --- /dev/null +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php @@ -0,0 +1,195 @@ + + */ + +abstract class Mage_Eav_Controller_Adminhtml_Set_Abstract extends Mage_Adminhtml_Controller_Action +{ + + /** @var string $_entityCode */ + protected $_entityCode; + + /** @var Mage_Eav_Model_Entity_Type $_entityType */ + protected $_entityType; + + /** + * Controller predispatch method + * + * @return Mage_Adminhtml_Controller_Action + */ + public function preDispatch() + { + $this->_setForcedFormKeyActions('delete'); + $this->_entityType = Mage::getModel('eav/entity')->setType($this->_entityCode)->getEntityType(); + if (!Mage::registry('entity_type')) { + Mage::register('entity_type', $this->_entityType); + } + return parent::preDispatch(); + } + + protected function _initAction() + { + return $this->loadLayout(); + } + + public function indexAction() + { + $this->_initAction() + ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_set')) + ->renderLayout(); + } + + public function editAction() + { + $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->getId() ? $attributeSet->getAttributeSetName() : $this->__('New Set')) + ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_set_main')); + + $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); + + $this->renderLayout(); + } + + public function setGridAction() + { + $this->getResponse()->setBody( + $this->getLayout() + ->createBlock('eav/adminhtml_attribute_set_grid') + ->toHtml()); + } + + /** + * Save attribute set action + * + * [POST] Create attribute set from another set and redirect to edit page + * [AJAX] Save attribute set data + * + */ + public function saveAction() + { + $entityTypeId = $this->_entityType->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_Eav_Helper_Data $helper */ + $helper = Mage::helper('eav'); + + 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('eav')->__('This attribute set no longer exists.')); + } + $data = Mage::helper('core')->jsonDecode($this->getRequest()->getPost('data')); + + //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('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 ($isNewSet) { + if ($hasError) { + $this->_redirect('*/*/add'); + } else { + $this->_redirect('*/*/edit', array('id' => $model->getId())); + } + } else { + $response = array(); + 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->_initAction() + ->_title($this->__('New Set')) + ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_set_toolbar_add')) + ->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(); + } + } + +} diff --git a/app/code/core/Mage/Eav/Helper/Data.php b/app/code/core/Mage/Eav/Helper/Data.php index 3d9cdbc8a..41d7a81f0 100644 --- a/app/code/core/Mage/Eav/Helper/Data.php +++ b/app/code/core/Mage/Eav/Helper/Data.php @@ -133,4 +133,81 @@ public function getInputTypesValidatorData() { return Mage::getStoreConfig(self::XML_PATH_VALIDATOR_DATA_INPUT_TYPES); } + + /** + * Return information array of 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 + * + * @param string $inputType + * @return array + */ + public function getAttributeInputTypes($inputType = null) + { + /** + * @todo specify there all relations for properties depending on input type + */ + $inputTypes = array( + 'multiselect' => array( + 'backend_model' => 'eav/entity_attribute_backend_array' + ), + 'boolean' => array( + 'source_model' => 'eav/entity_attribute_source_boolean' + ) + ); + + if (is_null($inputType)) { + return $inputTypes; + } elseif (isset($inputTypes[$inputType])) { + return $inputTypes[$inputType]; + } + return array(); + } + + /** + * Return default attribute backend model by input type + * + * @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 default attribute source model by input type + * + * @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 entity code formatted for humans + * + * @param Mage_Eav_Model_Entity_Type|string $entityTypeCode + * @return string + */ + public function formatTypeCode($entityTypeCode) + { + if ($entityTypeCode instanceof Mage_Eav_Model_Entity_Type) { + $entityTypeCode = $entityTypeCode->getEntityTypeCode(); + } + if (!is_string($entityTypeCode)) { + $entityTypeCode = ''; + } + return ucwords(str_replace('_', ' ', $entityTypeCode)); + } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Entity/Attribute.php index 966a0587e..cfa3d6e1e 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute.php @@ -31,6 +31,10 @@ */ class Mage_Eav_Model_Entity_Attribute extends Mage_Eav_Model_Entity_Attribute_Abstract { + const SCOPE_STORE = 0; + const SCOPE_GLOBAL = 1; + const SCOPE_WEBSITE = 2; + /** * Prefix of model events names * 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 2c879b98a..3c65c03db 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php @@ -135,7 +135,7 @@ 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 * @inheritDoc */ #[\Override] @@ -155,6 +155,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); diff --git a/app/code/core/Mage/Eav/etc/config.xml b/app/code/core/Mage/Eav/etc/config.xml index 3379d7667..31c4ef95f 100644 --- a/app/code/core/Mage/Eav/etc/config.xml +++ b/app/code/core/Mage/Eav/etc/config.xml @@ -87,6 +87,11 @@ + + + Mage_Eav_Block + + diff --git a/app/design/adminhtml/default/default/template/eav/attribute/js.phtml b/app/design/adminhtml/default/default/template/eav/attribute/js.phtml new file mode 100644 index 000000000..4f32178b0 --- /dev/null +++ b/app/design/adminhtml/default/default/template/eav/attribute/js.phtml @@ -0,0 +1,174 @@ + + diff --git a/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml b/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml new file mode 100644 index 000000000..9fee7cf55 --- /dev/null +++ b/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml @@ -0,0 +1,450 @@ + +
+ + + + + +

escapeHtml($this->_getHeader()) ?>

+ getBackButtonHtml() ?> + getResetButtonHtml() ?> + getDeleteButtonHtml() ?> + getSaveButtonHtml() ?> +
+
+ + + + + + +
+ getSetFormHtml() ?> + +
+ + + + + + +

__('Groups') ?>

+
+ + getIsReadOnly()): ?> +

getAddGroupButton() ?> getDeleteGroupButton() ?>

+

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

+ + + getSetsFilterHtml() ?> + getGroupTreeHtml() ?> +
+
+ + + + + + +

__('Unassigned Attributes') ?>

+
+
+ +
diff --git a/app/design/adminhtml/default/default/template/eav/attribute/set/main/tree/attribute.phtml b/app/design/adminhtml/default/default/template/eav/attribute/set/main/tree/attribute.phtml new file mode 100644 index 000000000..807cf7a92 --- /dev/null +++ b/app/design/adminhtml/default/default/template/eav/attribute/set/main/tree/attribute.phtml @@ -0,0 +1,20 @@ + diff --git a/app/design/adminhtml/default/default/template/eav/attribute/set/main/tree/group.phtml b/app/design/adminhtml/default/default/template/eav/attribute/set/main/tree/group.phtml new file mode 100644 index 000000000..b2c248246 --- /dev/null +++ b/app/design/adminhtml/default/default/template/eav/attribute/set/main/tree/group.phtml @@ -0,0 +1,21 @@ + +
diff --git a/app/design/adminhtml/default/default/template/eav/attribute/set/toolbar/add.phtml b/app/design/adminhtml/default/default/template/eav/attribute/set/toolbar/add.phtml new file mode 100644 index 000000000..2b7a3b33d --- /dev/null +++ b/app/design/adminhtml/default/default/template/eav/attribute/set/toolbar/add.phtml @@ -0,0 +1,35 @@ + +
+ + + + + +

_getHeader() ?>

+ getBackButtonHtml() ?> + getSaveButtonHtml() ?> +
+
+getFormHtml() ?> + diff --git a/app/locale/en_US/Mage_Eav.csv b/app/locale/en_US/Mage_Eav.csv index 13201b521..500dbbb7d 100644 --- a/app/locale/en_US/Mage_Eav.csv +++ b/app/locale/en_US/Mage_Eav.csv @@ -46,6 +46,7 @@ "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 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" @@ -102,6 +103,7 @@ "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" @@ -117,6 +119,7 @@ "URL","URL" "Unique Value","Unique Value" "Unique Value (not shared with other products)","Unique Value (not shared with other products)" +"Unique Value (not shared with other %s)","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 +128,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?" From 851e5675fab35f3608e8a5c7cae7cd5d6c9d7418 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 3 Aug 2022 07:38:55 -0700 Subject: [PATCH 002/113] Mage_Eav: Add generic form element renderers --- .../Block/Adminhtml/Helper/Form/Boolean.php | 44 +++++++ .../core/Mage/Eav/Block/Widget/Abstract.php | 90 +++++++++++++ .../core/Mage/Eav/Block/Widget/Boolean.php | 54 ++++++++ app/code/core/Mage/Eav/Block/Widget/Date.php | 124 ++++++++++++++++++ .../Mage/Eav/Block/Widget/Multiselect.php | 58 ++++++++ .../core/Mage/Eav/Block/Widget/Select.php | 48 +++++++ app/code/core/Mage/Eav/Block/Widget/Text.php | 38 ++++++ .../core/Mage/Eav/Block/Widget/Textarea.php | 38 ++++++ .../default/template/eav/widget/boolean.phtml | 32 +++++ .../default/template/eav/widget/date.phtml | 58 ++++++++ .../template/eav/widget/multiselect.phtml | 32 +++++ .../default/template/eav/widget/select.phtml | 32 +++++ .../default/template/eav/widget/text.phtml | 26 ++++ .../template/eav/widget/textarea.phtml | 26 ++++ 14 files changed, 700 insertions(+) create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php create mode 100644 app/code/core/Mage/Eav/Block/Widget/Abstract.php create mode 100644 app/code/core/Mage/Eav/Block/Widget/Boolean.php create mode 100644 app/code/core/Mage/Eav/Block/Widget/Date.php create mode 100644 app/code/core/Mage/Eav/Block/Widget/Multiselect.php create mode 100644 app/code/core/Mage/Eav/Block/Widget/Select.php create mode 100644 app/code/core/Mage/Eav/Block/Widget/Text.php create mode 100644 app/code/core/Mage/Eav/Block/Widget/Textarea.php create mode 100644 app/design/frontend/base/default/template/eav/widget/boolean.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/date.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/multiselect.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/select.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/text.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/textarea.phtml diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php b/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php new file mode 100644 index 000000000..508eb2fba --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php @@ -0,0 +1,44 @@ + + */ +class Mage_Eav_Block_Adminhtml_Helper_Form_Boolean extends Varien_Data_Form_Element_Select +{ + public function __construct($attributes=array()) + { + parent::__construct($attributes); + $this->setValues(array( + array( + 'label' => Mage::helper('eav')->__('No'), + 'value' => 0, + ), + array( + 'label' => Mage::helper('eav')->__('Yes'), + 'value' => 1, + ), + )); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Abstract.php b/app/code/core/Mage/Eav/Block/Widget/Abstract.php new file mode 100644 index 000000000..54c824a87 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Abstract.php @@ -0,0 +1,90 @@ +getAttribute()->getIsVisible(); + } + + /** + * Check if attribute marked as required + * + * @return bool + */ + public function isRequired() + { + return (bool)$this->getAttribute()->getIsRequired(); + } + + /** + * @return string + */ + public function getFieldIdFormat() + { + if (!$this->hasData('field_id_format')) { + $this->setData('field_id_format', '%s'); + } + return $this->getData('field_id_format'); + } + + /** + * @return string + */ + public function getFieldNameFormat() + { + if (!$this->hasData('field_name_format')) { + $this->setData('field_name_format', '%s'); + } + return $this->getData('field_name_format'); + } + + /** + * @param string $field + * @return string + */ + public function getFieldId($field) + { + return sprintf($this->getFieldIdFormat(), $field); + } + + /** + * @param string $field + * @return string + */ + public function getFieldName($field) + { + return sprintf($this->getFieldNameFormat(), $field); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Boolean.php b/app/code/core/Mage/Eav/Block/Widget/Boolean.php new file mode 100644 index 000000000..cb0973cd8 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Boolean.php @@ -0,0 +1,54 @@ + + */ +class Mage_Eav_Block_Widget_Boolean extends Mage_Eav_Block_Widget_Abstract +{ + /** + * Initialize block + */ + public function _construct() + { + parent::_construct(); + $this->setTemplate('eav/widget/boolean.phtml'); + } + + /** + * Get select options + * + * @return array + */ + public function getOptions() + { + $options = array( + array('value' => '', 'label' => Mage::helper('eav')->__('')), + array('value' => '1', 'label' => Mage::helper('eav')->__('Yes')), + array('value' => '0', 'label' => Mage::helper('eav')->__('No')) + ); + + return $options; + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Date.php b/app/code/core/Mage/Eav/Block/Widget/Date.php new file mode 100644 index 000000000..11a49172c --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Date.php @@ -0,0 +1,124 @@ +setTemplate('eav/widget/date.phtml'); + } + + /** + * @param string $date + * @return $this + */ + public function setDate($date) + { + $this->setTime($date ? strtotime($date) : false); + $this->setData('date', $date); + return $this; + } + + /** + * @return false|string + */ + public function getDay() + { + return $this->getTime() ? date('d', $this->getTime()) : ''; + } + + /** + * @return false|string + */ + public function getMonth() + { + return $this->getTime() ? date('m', $this->getTime()) : ''; + } + + /** + * @return false|string + */ + public function getYear() + { + return $this->getTime() ? date('Y', $this->getTime()) : ''; + } + + /** + * 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; + } + + /** + * Sort date inputs by dateformat order of current locale + * + * @return string + */ + public function getSortedDateInputs() + { + $strtr = array( + '%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/Multiselect.php b/app/code/core/Mage/Eav/Block/Widget/Multiselect.php new file mode 100644 index 000000000..329216986 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Multiselect.php @@ -0,0 +1,58 @@ + + */ +class Mage_Eav_Block_Widget_Multiselect extends Mage_Eav_Block_Widget_Abstract +{ + /** + * Initialize block + */ + public function _construct() + { + parent::_construct(); + $this->setTemplate('eav/widget/multiselect.phtml'); + } + + /** + * Get select element extra attributes + * + * @return string + */ + public function getFieldParams() + { + return 'multiple'; + } + + /** + * Get select options + * + * @return array + */ + public function getOptions() + { + return $this->getAttribute()->getSource()->getAllOptions(false); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Select.php b/app/code/core/Mage/Eav/Block/Widget/Select.php new file mode 100644 index 000000000..b97509537 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Select.php @@ -0,0 +1,48 @@ + + */ +class Mage_Eav_Block_Widget_Select extends Mage_Eav_Block_Widget_Abstract +{ + /** + * Initialize block + */ + public function _construct() + { + parent::_construct(); + $this->setTemplate('eav/widget/select.phtml'); + } + + /** + * Get select options + * + * @return array + */ + public function getOptions() + { + return $this->getAttribute()->getSource()->getAllOptions(); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Text.php b/app/code/core/Mage/Eav/Block/Widget/Text.php new file mode 100644 index 000000000..4402d6645 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Text.php @@ -0,0 +1,38 @@ + + */ +class Mage_Eav_Block_Widget_Text extends Mage_Eav_Block_Widget_Abstract +{ + /** + * Initialize block + */ + public function _construct() + { + parent::_construct(); + $this->setTemplate('eav/widget/text.phtml'); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Textarea.php b/app/code/core/Mage/Eav/Block/Widget/Textarea.php new file mode 100644 index 000000000..5989f5e84 --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Textarea.php @@ -0,0 +1,38 @@ + + */ +class Mage_Eav_Block_Widget_Textarea extends Mage_Eav_Block_Widget_Abstract +{ + /** + * Initialize block + */ + public function _construct() + { + parent::_construct(); + $this->setTemplate('eav/widget/textarea.phtml'); + } +} diff --git a/app/design/frontend/base/default/template/eav/widget/boolean.phtml b/app/design/frontend/base/default/template/eav/widget/boolean.phtml new file mode 100644 index 000000000..9fdff1496 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/boolean.phtml @@ -0,0 +1,32 @@ + +getAttribute() ?> +getAttributeCode() ?> + +
+ +
diff --git a/app/design/frontend/base/default/template/eav/widget/date.phtml b/app/design/frontend/base/default/template/eav/widget/date.phtml new file mode 100644 index 000000000..1716f9315 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/date.phtml @@ -0,0 +1,58 @@ + +getAttribute() ?> +getAttributeCode() ?> + +
+setDateInput('d', + '
+ getFieldParams() . ' /> + +
' + ); + + $this->setDateInput('m', + '
+ getFieldParams() . ' /> + +
' + ); + + $this->setDateInput('y', + '
+ getFieldParams() . ' /> + +
' + ); +?> + getSortedDateInputs() ?> + + + +
+ diff --git a/app/design/frontend/base/default/template/eav/widget/multiselect.phtml b/app/design/frontend/base/default/template/eav/widget/multiselect.phtml new file mode 100644 index 000000000..16bb71bda --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/multiselect.phtml @@ -0,0 +1,32 @@ + +getAttribute() ?> +getAttributeCode() ?> + +
+ +
diff --git a/app/design/frontend/base/default/template/eav/widget/select.phtml b/app/design/frontend/base/default/template/eav/widget/select.phtml new file mode 100644 index 000000000..9fdff1496 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/select.phtml @@ -0,0 +1,32 @@ + +getAttribute() ?> +getAttributeCode() ?> + +
+ +
diff --git a/app/design/frontend/base/default/template/eav/widget/text.phtml b/app/design/frontend/base/default/template/eav/widget/text.phtml new file mode 100644 index 000000000..1e8578584 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/text.phtml @@ -0,0 +1,26 @@ + +getAttribute() ?> +getAttributeCode() ?> + +
+ getFieldParams() ?> /> +
diff --git a/app/design/frontend/base/default/template/eav/widget/textarea.phtml b/app/design/frontend/base/default/template/eav/widget/textarea.phtml new file mode 100644 index 000000000..803cb98d0 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/textarea.phtml @@ -0,0 +1,26 @@ + +getAttribute() ?> +getAttributeCode() ?> + +
+ +
From e86bf29048d7b5990ca9fa74e6e24ee80cc4ccaf Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 13 Jul 2022 09:19:29 -0700 Subject: [PATCH 003/113] Mage_Catalog: add EAV grids Co-authored-by: Fabrizio Balliano --- .../Block/Catalog/Category/Tab/Attributes.php | 3 +- .../Catalog/Category/AttributeController.php | 68 +++++++++++++++++++ .../Catalog/Category/SetController.php | 68 +++++++++++++++++++ app/code/core/Mage/Catalog/etc/adminhtml.xml | 22 ++++-- app/locale/en_US/Mage_Adminhtml.csv | 2 + app/locale/en_US/Mage_Catalog.csv | 1 + 6 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php create mode 100644 app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php index ae7f447bf..c71657abc 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php @@ -161,7 +161,8 @@ protected function _getAdditionalElementTypes() { return [ 'image' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_category_helper_image'), - 'textarea' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_helper_form_wysiwyg') + 'textarea' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_helper_form_wysiwyg'), + 'boolean' => Mage::getConfig()->getBlockClassName('eav/adminhtml_helper_form_boolean'), ]; } } 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..b5475c0ad --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php @@ -0,0 +1,68 @@ + + */ + +class Mage_Adminhtml_Catalog_Category_AttributeController extends Mage_Eav_Adminhtml_Attribute_AbstractController +{ + /** + * Additional initialization + * + */ + protected function _construct() + { + $this->_entityCode = Mage_Catalog_Model_Category::ENTITY; + } + + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Catalog')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Category Attributes')); + + $this->_setActiveMenu('catalog/attributes') + ->_addBreadcrumb( + $this->__('Catalog'), + $this->__('Catalog') + ) + ->_addBreadcrumb( + $this->__('Manage Category Attributes'), + $this->__('Manage Category Attributes') + ); + + return $this; + } + + protected function _isAllowed() + { + return Mage::getSingleton('admin/session')->isAllowed('catalog/attributes/category_attributes'); + } + +} 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..30a35771b --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php @@ -0,0 +1,68 @@ + + */ + +class Mage_Adminhtml_Catalog_Category_SetController extends Mage_Eav_Adminhtml_Set_AbstractController +{ + /** + * Additional initialization + * + */ + protected function _construct() + { + $this->_entityCode = Mage_Catalog_Model_Category::ENTITY; + } + + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Catalog')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Category Attribute Sets')); + + $this->_setActiveMenu('catalog/attributes') + ->_addBreadcrumb( + $this->__('Catalog'), + $this->__('Catalog') + ) + ->_addBreadcrumb( + $this->__('Manage Category Attribute Sets'), + $this->__('Manage Category Attribute Sets') + ); + + return $this; + } + + protected function _isAllowed() + { + return Mage::getSingleton('admin/session')->isAllowed('catalog/attributes/category_sets'); + } + +} diff --git a/app/code/core/Mage/Catalog/etc/adminhtml.xml b/app/code/core/Mage/Catalog/etc/adminhtml.xml index 74f4a4747..445a5765f 100644 --- a/app/code/core/Mage/Catalog/etc/adminhtml.xml +++ b/app/code/core/Mage/Catalog/etc/adminhtml.xml @@ -34,13 +34,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 +83,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/locale/en_US/Mage_Adminhtml.csv b/app/locale/en_US/Mage_Adminhtml.csv index 2ac5e7751..f87cf84c0 100644 --- a/app/locale/en_US/Mage_Adminhtml.csv +++ b/app/locale/en_US/Mage_Adminhtml.csv @@ -572,6 +572,8 @@ "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" diff --git a/app/locale/en_US/Mage_Catalog.csv b/app/locale/en_US/Mage_Catalog.csv index 6f461c89f..07ab84a2f 100644 --- a/app/locale/en_US/Mage_Catalog.csv +++ b/app/locale/en_US/Mage_Catalog.csv @@ -396,6 +396,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" From 42524dbc3ec492281405ef513ab42f0c0ca08b9a Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 13 Jul 2022 09:19:46 -0700 Subject: [PATCH 004/113] Mage_Customer: Add EAV grids Co-authored-by: Fabrizio Balliano --- .../Customer/Address/AttributeController.php | 68 +++++++++++++++++++ .../Customer/Address/SetController.php | 68 +++++++++++++++++++ .../Customer/AttributeController.php | 68 +++++++++++++++++++ .../controllers/Customer/SetController.php | 68 +++++++++++++++++++ app/code/core/Mage/Customer/Model/Address.php | 2 + .../core/Mage/Customer/Model/Customer.php | 8 ++- app/code/core/Mage/Customer/etc/adminhtml.xml | 40 ++++++++++- app/locale/en_US/Mage_Adminhtml.csv | 4 ++ 8 files changed, 322 insertions(+), 4 deletions(-) create mode 100644 app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php create mode 100644 app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php create mode 100644 app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php create mode 100644 app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php 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..df57d7cfc --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php @@ -0,0 +1,68 @@ + + */ + +class Mage_Adminhtml_Customer_Address_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract +{ + /** + * Additional initialization + * + */ + protected function _construct() + { + $this->_entityCode = Mage_Customer_Model_Address::ENTITY; + } + + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Customers')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Customer Address Attributes')); + + $this->_setActiveMenu('customer/attributes') + ->_addBreadcrumb( + $this->__('Customers'), + $this->__('Customers') + ) + ->_addBreadcrumb( + $this->__('Manage Customer Address Attributes'), + $this->__('Manage Customer Address Attributes') + ); + + return $this; + } + + protected function _isAllowed() + { + return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_address_attributes'); + } + +} 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..a0b7a56a5 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php @@ -0,0 +1,68 @@ + + */ + +class Mage_Adminhtml_Customer_Address_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract +{ + /** + * Additional initialization + * + */ + protected function _construct() + { + $this->_entityCode = Mage_Customer_Model_Address::ENTITY; + } + + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Customers')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Customer Address Attribute Sets')); + + $this->_setActiveMenu('customer/attributes') + ->_addBreadcrumb( + $this->__('Customers'), + $this->__('Customers') + ) + ->_addBreadcrumb( + $this->__('Manage Customer Address Attribute Sets'), + $this->__('Manage Customer Address Attribute Sets') + ); + + return $this; + } + + protected function _isAllowed() + { + return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_address_sets'); + } + +} 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..9bb5691ac --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php @@ -0,0 +1,68 @@ + + */ + +class Mage_Adminhtml_Customer_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract +{ + /** + * Additional initialization + * + */ + protected function _construct() + { + $this->_entityCode = Mage_Customer_Model_Customer::ENTITY; + } + + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Customers')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Customer Attributes')); + + $this->_setActiveMenu('customer/attributes') + ->_addBreadcrumb( + $this->__('Customers'), + $this->__('Customers') + ) + ->_addBreadcrumb( + $this->__('Manage Customer Attributes'), + $this->__('Manage Customer Attributes') + ); + + return $this; + } + + protected function _isAllowed() + { + return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_attributes'); + } + +} 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..85954b093 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php @@ -0,0 +1,68 @@ + + */ + +class Mage_Adminhtml_Customer_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract +{ + /** + * Additional initialization + * + */ + protected function _construct() + { + $this->_entityCode = Mage_Customer_Model_Customer::ENTITY; + } + + protected function _initAction() + { + parent::_initAction(); + + $this->_title($this->__('Customers')) + ->_title($this->__('Attributes')) + ->_title($this->__('Manage Customer Attribute Sets')); + + $this->_setActiveMenu('customer/attributes') + ->_addBreadcrumb( + $this->__('Customers'), + $this->__('Customers') + ) + ->_addBreadcrumb( + $this->__('Manage Customer Attribute Sets'), + $this->__('Manage Customer Attribute Sets') + ); + + return $this; + } + + protected function _isAllowed() + { + return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_sets'); + } + +} diff --git a/app/code/core/Mage/Customer/Model/Address.php b/app/code/core/Mage/Customer/Model/Address.php index 28434e267..5f05f0dbb 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 { + const ENTITY = 'customer_address'; + protected $_customer; #[\Override] diff --git a/app/code/core/Mage/Customer/Model/Customer.php b/app/code/core/Mage/Customer/Model/Customer.php index 5cc25b1ef..3f5e14881 100644 --- a/app/code/core/Mage/Customer/Model/Customer.php +++ b/app/code/core/Mage/Customer/Model/Customer.php @@ -104,6 +104,8 @@ */ class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract { + const ENTITY = 'customer'; + /** * Configuration paths for email templates and identities */ @@ -137,7 +139,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'; + const CACHE_TAG = self::ENTITY; /** * Minimum Password Length @@ -160,14 +162,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 diff --git a/app/code/core/Mage/Customer/etc/adminhtml.xml b/app/code/core/Mage/Customer/etc/adminhtml.xml index 8bf4d2015..f4753aa96 100644 --- a/app/code/core/Mage/Customer/etc/adminhtml.xml +++ b/app/code/core/Mage/Customer/etc/adminhtml.xml @@ -15,7 +15,6 @@ Customers 40 - Manage Customers @@ -27,6 +26,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 +72,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/locale/en_US/Mage_Adminhtml.csv b/app/locale/en_US/Mage_Adminhtml.csv index f87cf84c0..19977f158 100644 --- a/app/locale/en_US/Mage_Adminhtml.csv +++ b/app/locale/en_US/Mage_Adminhtml.csv @@ -577,6 +577,10 @@ "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" From c3fff1f4f88c64ff0d4647a584c7bfa093f2c524 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Mon, 1 Aug 2022 15:45:47 -0700 Subject: [PATCH 005/113] Mage_Customer: Add use_in_forms support --- .../Adminhtml/Model/Customer/Observer.php | 148 ++++++++++++++++++ app/code/core/Mage/Adminhtml/etc/config.xml | 32 ++++ .../Mage/Checkout/Block/Onepage/Billing.php | 31 ++++ .../core/Mage/Checkout/Model/Type/Onepage.php | 18 +++ .../core/Mage/Customer/Block/Address/Edit.php | 26 +++ .../core/Mage/Customer/Block/Form/Edit.php | 25 +++ .../Mage/Customer/Block/Form/Register.php | 21 +++ .../Customer/Model/Config/Address/Forms.php | 64 ++++++++ .../core/Mage/Customer/Model/Config/Forms.php | 72 +++++++++ .../Eav/Model/Resource/Form/Attribute.php | 23 +++ .../template/checkout/onepage/billing.phtml | 8 + .../default/template/customer/form/edit.phtml | 9 ++ .../template/customer/form/register.phtml | 9 ++ .../persistent/checkout/onepage/billing.phtml | 8 + .../template/customer/address/edit.phtml | 12 ++ .../default/template/customer/form/edit.phtml | 9 ++ .../persistent/checkout/onepage/billing.phtml | 8 + 17 files changed, 523 insertions(+) create mode 100644 app/code/core/Mage/Adminhtml/Model/Customer/Observer.php create mode 100644 app/code/core/Mage/Customer/Model/Config/Address/Forms.php create mode 100644 app/code/core/Mage/Customer/Model/Config/Forms.php diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php new file mode 100644 index 000000000..240764a96 --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -0,0 +1,148 @@ + + */ +class Mage_Adminhtml_Model_Customer_Observer +{ + + /** + * Add frontend properties to customer attribute edit form + * + * @param Varien_Event_Observer $observer + * @return $this + */ + public function customerAttributeEditPrepareForm($observer) + { + /** @var Mage_Customer_Model_Attribute $attribute */ + $attribute = $observer->getAttribute(); + + /** @var Varien_Data_Form $form */ + $form = $observer->getForm(); + + /** @var Varien_Data_Form_Element_Fieldset $fieldset */ + $fieldset = $form->getElement('base_fieldset'); + + // frontend properties fieldset + $fieldset = $form->addFieldset('front_fieldset', array('legend'=>Mage::helper('adminhtml')->__('Extra Properties'))); + + $fieldset->addField('use_in_forms', 'multiselect', array( + 'name' => 'use_in_forms', + 'label' => Mage::helper('adminhtml')->__('Use in Forms'), + 'title' => Mage::helper('adminhtml')->__('Use in Forms'), + 'values' => Mage::getModel('customer/config_forms')->toOptionArray(), + 'value' => Mage::getResourceModel('customer/form_attribute')->getFormTypesByAttribute($attribute) + )); + + return $this; + } + + /** + * Save frontend properties from customer attribute edit form + * + * @param Varien_Event_Observer $observer + * @return $this + */ + public function customerAttributeEditPrepareSave($observer) + { + /** @var Mage_Core_Controller_Request_Http $request */ + $request = $observer->getRequest(); + + $data = $request->getPost(); + if ($data) { + + /** @var Mage_Eav_Model_Entity_Attribute $model */ + $model = $observer->getObject(); + + if (!isset($data['use_in_forms'])) { + $data['use_in_forms'] = array(); + } + + $model->setData('used_in_forms', $data['use_in_forms']); + + } + return $this; + } + + /** + * Add frontend properties to customer address attribute edit form + * + * @param Varien_Event_Observer $observer + * @return $this + */ + public function customerAddressAttributeEditPrepareForm($observer) + { + /** @var Mage_Customer_Model_Attribute $attribute */ + $attribute = $observer->getAttribute(); + + /** @var Varien_Data_Form $form */ + $form = $observer->getForm(); + + /** @var Varien_Data_Form_Element_Fieldset $fieldset */ + $fieldset = $form->getElement('base_fieldset'); + + // frontend properties fieldset + $fieldset = $form->addFieldset('front_fieldset', array('legend'=>Mage::helper('adminhtml')->__('Extra Properties'))); + + $fieldset->addField('use_in_forms', 'multiselect', array( + 'name' => 'use_in_forms', + 'label' => Mage::helper('adminhtml')->__('Use in Forms'), + 'title' => Mage::helper('adminhtml')->__('Use in Forms'), + 'values' => Mage::getModel('customer/config_address_forms')->toOptionArray(), + 'value' => Mage::getResourceModel('customer/form_attribute')->getFormTypesByAttribute($attribute) + )); + + return $this; + } + + /** + * Save frontend properties from customer address attribute edit form + * + * @param Varien_Event_Observer $observer + * @return $this + */ + public function customerAddressAttributeEditPrepareSave($observer) + { + /** @var Mage_Core_Controller_Request_Http $request */ + $request = $observer->getRequest(); + + $data = $request->getPost(); + if ($data) { + + /** @var Mage_Eav_Model_Entity_Attribute $model */ + $model = $observer->getObject(); + + if (!isset($data['use_in_forms'])) { + $data['use_in_forms'] = array(); + } + + $model->setData('used_in_forms', $data['use_in_forms']); + + } + return $this; + } + +} diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index f89e07145..5d9f90542 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -111,6 +111,38 @@ + + + + adminhtml/customer_observer + customerAttributeEditPrepareForm + + + + + + + adminhtml/customer_observer + customerAttributeEditPrepareSave + + + + + + + adminhtml/customer_observer + customerAddressAttributeEditPrepareForm + + + + + + + adminhtml/customer_observer + customerAddressAttributeEditPrepareSave + + + diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Billing.php b/app/code/core/Mage/Checkout/Block/Onepage/Billing.php index 02d366502..c169b532d 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Billing.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Billing.php @@ -204,4 +204,35 @@ public function getTaxvatHtml() ->setFieldNameFormat('billing[%s]') ->toHtml(); } + + /** + * Return extra EAV fields used in this form + * + * @return array + */ + public function extraFields() + { + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode('checkout_register'); + + $attributes = $form->getAttributes(); + foreach ($attributes as $code => $attribute) { + if (!$attribute->getIsUserDefined()) { + unset($attributes[$code]); + } + } + + return $attributes; + } + + /** + * Return extra EAV fields from incomplete checkout session + * + * @return Varien_Object + */ + public function getExtraFieldsSession() + { + return new Varien_Object($this->getCheckout()->getExtraFields()); + } } diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index 36d795fa4..aab64ca38 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -413,6 +413,16 @@ protected function _validateCustomerData(array $data) // set customer password $customer->setPassword($customerRequest->getParam('customer_password')); $customer->setPasswordConfirmation($customerRequest->getParam('confirm_password')); + + // 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(); @@ -710,6 +720,14 @@ protected function _prepareNewCustomerQuote() $customerBilling->setIsDefaultShipping(true); } + // 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/Customer/Block/Address/Edit.php b/app/code/core/Mage/Customer/Block/Address/Edit.php index 5be900739..85a4ea64e 100644 --- a/app/code/core/Mage/Customer/Block/Address/Edit.php +++ b/app/code/core/Mage/Customer/Block/Address/Edit.php @@ -211,4 +211,30 @@ public function getBackButtonUrl() return $this->getUrl('customer/account/'); } } + + /** + * Return extra EAV fields used in this form + * + * @return array + */ + public function extraFields() + { + /** @var Mage_Customer_Model_Customer $customer */ + $customer = $this->getCustomer(); + + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode('customer_address_edit') + ->setEntity($this->getAddress()) + ->initDefaultValues(); + + $attributes = $form->getAttributes(); + foreach ($attributes as $code => $attribute) { + if (!$attribute->getIsUserDefined()) { + unset($attributes[$code]); + } + } + + return $attributes; + } } diff --git a/app/code/core/Mage/Customer/Block/Form/Edit.php b/app/code/core/Mage/Customer/Block/Form/Edit.php index b76cd115c..50838a1d7 100644 --- a/app/code/core/Mage/Customer/Block/Form/Edit.php +++ b/app/code/core/Mage/Customer/Block/Form/Edit.php @@ -17,4 +17,29 @@ */ class Mage_Customer_Block_Form_Edit extends Mage_Customer_Block_Account_Dashboard { + /** + * Return extra EAV fields used in this form + * + * @return array + */ + public function extraFields() + { + /** @var Mage_Customer_Model_Customer $customer */ + $customer = $this->getCustomer(); + + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode('customer_account_edit') + ->setEntity($customer) + ->initDefaultValues(); + + $attributes = $form->getAttributes(); + foreach ($attributes as $code => $attribute) { + if (!$attribute->getIsUserDefined()) { + unset($attributes[$code]); + } + } + + return $attributes; + } } diff --git a/app/code/core/Mage/Customer/Block/Form/Register.php b/app/code/core/Mage/Customer/Block/Form/Register.php index 87ef0c9d5..d345ca48c 100644 --- a/app/code/core/Mage/Customer/Block/Form/Register.php +++ b/app/code/core/Mage/Customer/Block/Form/Register.php @@ -178,4 +178,25 @@ public function getMinPasswordLength() { return Mage::getModel('customer/customer')->getMinPasswordLength(); } + + /** + * Return extra EAV fields used in this form + * + * @return array + */ + public function extraFields() + { + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode('customer_account_create'); + + $attributes = $form->getAttributes(); + foreach ($attributes as $code => $attribute) { + if (!$attribute->getIsUserDefined()) { + unset($attributes[$code]); + } + } + + return $attributes; + } } diff --git a/app/code/core/Mage/Customer/Model/Config/Address/Forms.php b/app/code/core/Mage/Customer/Model/Config/Address/Forms.php new file mode 100644 index 000000000..8dce22ad2 --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Config/Address/Forms.php @@ -0,0 +1,64 @@ + 'adminhtml_customer_address', + 'label' => Mage::helper('customer')->__('Adminhtml Customer Address') + ), + array( + 'value' => 'customer_address_edit', + 'label' => Mage::helper('customer')->__('Customer Address Edit') + ), + array( + 'value' => 'customer_register_address', + 'label' => Mage::helper('customer')->__('Customer Register Address') + ), + ); + } + + /** + * Get options in "key-value" format + * + * @return array + */ + public function toOptionHash() + { + return array_combine( + array_column($this->toOptionArray(), 'value'), + array_column($this->toOptionArray(), 'label') + ); + } + +} diff --git a/app/code/core/Mage/Customer/Model/Config/Forms.php b/app/code/core/Mage/Customer/Model/Config/Forms.php new file mode 100644 index 000000000..2c85a830a --- /dev/null +++ b/app/code/core/Mage/Customer/Model/Config/Forms.php @@ -0,0 +1,72 @@ + 'adminhtml_checkout', + 'label' => Mage::helper('customer')->__('Adminhtml Checkout') + ), + array( + 'value' => 'adminhtml_customer', + 'label' => Mage::helper('customer')->__('Adminhtml Customer') + ), + array( + 'value' => 'checkout_register', + 'label' => Mage::helper('customer')->__('Checkout Register') + ), + array( + 'value' => 'customer_account_create', + 'label' => Mage::helper('customer')->__('Customer Account Create') + ), + array( + 'value' => 'customer_account_edit', + 'label' => Mage::helper('customer')->__('Customer Account Edit') + ), + ); + } + + /** + * Get options in "key-value" format + * + * @return array + */ + public function toOptionHash() + { + return array_combine( + array_column($this->toOptionArray(), 'value'), + array_column($this->toOptionArray(), 'label') + ); + } + +} diff --git a/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php b/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php index 3dce32e79..73588662b 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php @@ -32,4 +32,27 @@ public function getFormAttributeIds($formCode) return $this->_getReadAdapter()->fetchCol($select, $bind); } + + /** + * Retrieve form type filtered by given attribute + * + * @param Mage_Eav_Model_Entity_Attribute_Abstract|int $attribute + * @return array + */ + public function getFormTypesByAttribute($attribute) + { + if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { + $attribute = $attribute->getId(); + } + if (!$attribute) { + return array(); + } + + $bind = array('attribute_id' => $attribute); + $select = $this->_getReadAdapter()->select() + ->from($this->getMainTable(), 'form_code') + ->where('attribute_id = :attribute_id'); + + return $this->_getReadAdapter()->fetchCol($select, $bind); + } } 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 3481a2f90..817d87e74 100644 --- a/app/design/frontend/base/default/template/checkout/onepage/billing.phtml +++ b/app/design/frontend/base/default/template/checkout/onepage/billing.phtml @@ -146,6 +146,14 @@ + extraFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute)->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]') ?> + isEnabled()): ?> +
  • setObject($this->getExtraFieldsSession())->toHtml() ?>
  • + + +
  • 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..834e734d7 100644 --- a/app/design/frontend/base/default/template/customer/form/edit.phtml +++ b/app/design/frontend/base/default/template/customer/form/edit.phtml @@ -40,6 +40,15 @@ isEnabled()): ?>
  • setGender($this->getCustomer()->getGender())->toHtml() ?>
  • + + extraFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> + isEnabled()): ?> +
  • setObject($this->getCustomer())->toHtml() ?>
  • + + +
  • diff --git a/app/design/frontend/base/default/template/customer/form/register.phtml b/app/design/frontend/base/default/template/customer/form/register.phtml index fcedf6734..af9757a98 100644 --- a/app/design/frontend/base/default/template/customer/form/register.phtml +++ b/app/design/frontend/base/default/template/customer/form/register.phtml @@ -63,6 +63,15 @@ isEnabled()): ?>
  • setGender($this->getFormData()->getGender())->toHtml() ?>
  • + + extraFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> + isEnabled()): ?> +
  • setObject($this->getFormData())->toHtml() ?>
  • + + + getShowAddressFields()): ?> diff --git a/app/design/frontend/base/default/template/persistent/checkout/onepage/billing.phtml b/app/design/frontend/base/default/template/persistent/checkout/onepage/billing.phtml index e5ba9b5e9..c7a35442a 100644 --- a/app/design/frontend/base/default/template/persistent/checkout/onepage/billing.phtml +++ b/app/design/frontend/base/default/template/persistent/checkout/onepage/billing.phtml @@ -139,6 +139,14 @@
  • getTaxvatHtml() ?>
  • + extraFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute)->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]') ?> + isEnabled()): ?> +
  • setObject($this->getExtraFieldsSession())->toHtml() ?>
  • + + +
  • diff --git a/app/design/frontend/rwd/default/template/customer/address/edit.phtml b/app/design/frontend/rwd/default/template/customer/address/edit.phtml index 672ff0c0f..db064acb6 100644 --- a/app/design/frontend/rwd/default/template/customer/address/edit.phtml +++ b/app/design/frontend/rwd/default/template/customer/address/edit.phtml @@ -139,6 +139,18 @@
  • +
    +

    __('Other') ?>

    +
      + extraFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> + isEnabled()): ?> +
    • setObject($this->getAddress())->toHtml() ?>
    • + + +
    +
    diff --git a/app/design/frontend/rwd/default/template/customer/form/edit.phtml b/app/design/frontend/rwd/default/template/customer/form/edit.phtml index 351ab8434..63f0ba76a 100644 --- a/app/design/frontend/rwd/default/template/customer/form/edit.phtml +++ b/app/design/frontend/rwd/default/template/customer/form/edit.phtml @@ -41,6 +41,15 @@ isEnabled()): ?>
  • setGender($this->getCustomer()->getGender())->toHtml() ?>
  • + + extraFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> + isEnabled()): ?> +
  • setObject($this->getCustomer())->toHtml() ?>
  • + + +
  • diff --git a/app/design/frontend/rwd/default/template/persistent/checkout/onepage/billing.phtml b/app/design/frontend/rwd/default/template/persistent/checkout/onepage/billing.phtml index 69b87f435..b9ddb8297 100644 --- a/app/design/frontend/rwd/default/template/persistent/checkout/onepage/billing.phtml +++ b/app/design/frontend/rwd/default/template/persistent/checkout/onepage/billing.phtml @@ -142,6 +142,14 @@
  • getTaxvatHtml() ?>
  • + extraFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute)->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]') ?> + isEnabled()): ?> +
  • setObject($this->getExtraFieldsSession())->toHtml() ?>
  • + + +
  • From ab6a3fa088c2ae682869a3ccd09b391261d9497e Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 3 Aug 2022 08:49:56 -0700 Subject: [PATCH 006/113] WIP: GUI to set attribute sets for customer groups --- .../Block/Customer/Group/Edit/Form.php | 35 +++++++++++++++++++ .../controllers/Customer/GroupController.php | 7 ++++ 2 files changed, 42 insertions(+) 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..90936384c 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 @@ -64,6 +64,41 @@ protected function _prepareLayout() ] ); + // show attribute set fields for all groups except not logged in + if (is_null($customerGroup->getId()) || (int)$customerGroup->getId() !== Mage_Customer_Model_Group::NOT_LOGGED_IN_ID) { + + $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', array( + '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', array( + '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( diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php index 6899657fe..dd6f7c96b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php @@ -108,6 +108,13 @@ public function saveAction() $customerGroup->load((int)$id); } + // save these fields for all groups except not logged in + if (is_null($id) || (int)$id !== Mage_Customer_Model_Group::NOT_LOGGED_IN_ID) { + $customerGroup->setCode((string)$this->getRequest()->getParam('code')); + $customerGroup->setCustomerAttributeSetId((int)$this->getRequest()->getParam('customer_attribute_set')); + $customerGroup->setCustomerAddressAttributeSetId((int)$this->getRequest()->getParam('customer_address_attribute_set')); + } + $taxClass = (int)$this->getRequest()->getParam('tax_class'); if ($taxClass) { From 0e0c4ddad0de4ecec22e3b4fd3838f7844bffd9d Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 3 Aug 2022 14:00:47 -0700 Subject: [PATCH 007/113] WIP: Change form based on customer group --- .../Block/Customer/Edit/Tab/Addresses.php | 1 + app/code/core/Mage/Customer/Model/Form.php | 27 +++++++++++++++++-- .../Resource/Form/Attribute/Collection.php | 19 +++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) 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 4d7eb9908..436b52af5 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 @@ -117,6 +117,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') diff --git a/app/code/core/Mage/Customer/Model/Form.php b/app/code/core/Mage/Customer/Model/Form.php index 7231baabf..e8253b8a9 100644 --- a/app/code/core/Mage/Customer/Model/Form.php +++ b/app/code/core/Mage/Customer/Model/Form.php @@ -41,7 +41,30 @@ class Mage_Customer_Model_Form extends Mage_Eav_Model_Form #[\Override] protected function _getFormAttributeCollection() { - return parent::_getFormAttributeCollection() - ->addFieldToFilter('attribute_code', ['neq' => 'created_at']); + $collection = parent::_getFormAttributeCollection() + ->addFieldToFilter('ea.attribute_code', array('neq' => 'created_at')); + + $entity = $this->getEntity(); + $attributeSetId = null; + + if ($entity instanceof Mage_Customer_Model_Customer) { + $group = Mage::getModel('customer/group') + ->load($entity->getGroupId()); + $attributeSetId = $group->getCustomerAttributeSetId(); + + } else if ($entity instanceof Mage_Customer_Model_Address) { + $customer = $entity->getCustomer(); + if ($customer) { + $group = Mage::getModel('customer/group') + ->load($customer->getGroupId()); + $attributeSetId = $group->getCustomerAddressAttributeSetId(); + } + } + + if (!is_null($attributeSetId) && $attributeSetId != 0) { + $collection->filterAttributeSet($attributeSetId); + } + + return $collection; } } diff --git a/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php index ed17b3a1f..45d867f46 100644 --- a/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php +++ b/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php @@ -52,4 +52,23 @@ protected function _getEavWebsiteTable() { return $this->getTable('customer/eav_attribute_website'); } + + public function filterAttributeSet($attributeSetId) + { + $this->getSelect() + ->joinInner( + array('eea' => $this->getTable('eav/entity_attribute')), + 'main_table.attribute_id = eea.attribute_id', + array() + ) + ->joinLeft( + array('eag' => $this->getTable('eav/attribute_group')), + 'eea.attribute_group_id = eag.attribute_group_id', + array('eag.attribute_group_name') + ) + ->where('eea.attribute_set_id = ?', $attributeSetId) + ->order(array('eag.sort_order', 'eea.sort_order')); + + return $this; + } } From a88557b5d67e2578e756bc64e1f199f056530a46 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Thu, 19 Sep 2024 16:35:06 +0100 Subject: [PATCH 008/113] phpcs --- .../Block/Customer/Group/Edit/Form.php | 10 +- .../Adminhtml/Model/Customer/Observer.php | 22 ++--- .../Catalog/Category/AttributeController.php | 1 - .../Catalog/Category/SetController.php | 1 - .../Customer/Address/AttributeController.php | 1 - .../Customer/Address/SetController.php | 1 - .../Customer/AttributeController.php | 1 - .../controllers/Customer/SetController.php | 1 - app/code/core/Mage/Customer/Model/Address.php | 2 +- .../Customer/Model/Config/Address/Forms.php | 18 ++-- .../core/Mage/Customer/Model/Config/Forms.php | 26 +++-- .../core/Mage/Customer/Model/Customer.php | 4 +- app/code/core/Mage/Customer/Model/Form.php | 5 +- .../Resource/Form/Attribute/Collection.php | 10 +- .../Mage/Eav/Block/Adminhtml/Attribute.php | 1 - .../Eav/Block/Adminhtml/Attribute/Edit.php | 13 +-- .../Block/Adminhtml/Attribute/Edit/Form.php | 2 +- .../Adminhtml/Attribute/Edit/Tab/Main.php | 24 ++--- .../Block/Adminhtml/Attribute/Edit/Tabs.php | 9 +- .../Eav/Block/Adminhtml/Attribute/Grid.php | 8 +- .../Eav/Block/Adminhtml/Attribute/Set.php | 1 - .../Block/Adminhtml/Attribute/Set/Grid.php | 8 +- .../Block/Adminhtml/Attribute/Set/Main.php | 94 +++++++++++-------- .../Attribute/Set/Main/Formattribute.php | 38 ++++---- .../Attribute/Set/Main/Formgroup.php | 55 ++++++----- .../Adminhtml/Attribute/Set/Main/Formset.php | 16 ++-- .../Adminhtml/Attribute/Set/Toolbar/Add.php | 21 +++-- .../Block/Adminhtml/Helper/Form/Boolean.php | 14 +-- .../core/Mage/Eav/Block/Widget/Boolean.php | 10 +- app/code/core/Mage/Eav/Block/Widget/Date.php | 6 +- .../Adminhtml/Attribute/Abstract.php | 48 +++++----- .../Eav/Controller/Adminhtml/Set/Abstract.php | 15 +-- app/code/core/Mage/Eav/Helper/Data.php | 14 +-- .../core/Mage/Eav/Model/Entity/Attribute.php | 6 +- .../Eav/Model/Resource/Form/Attribute.php | 4 +- 35 files changed, 260 insertions(+), 250 deletions(-) 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 90936384c..de4eac53d 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 @@ -66,21 +66,20 @@ protected function _prepareLayout() // show attribute set fields for all groups except not logged in if (is_null($customerGroup->getId()) || (int)$customerGroup->getId() !== Mage_Customer_Model_Group::NOT_LOGGED_IN_ID) { - $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', array( + $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()) @@ -88,15 +87,14 @@ protected function _prepareLayout() ->load() ->toOptionArray(); - $fieldset->addField('customer_address_attribute_set_id', 'select', array( + $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())) { diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index 240764a96..312aef5b2 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -28,7 +28,6 @@ */ class Mage_Adminhtml_Model_Customer_Observer { - /** * Add frontend properties to customer attribute edit form * @@ -47,15 +46,15 @@ public function customerAttributeEditPrepareForm($observer) $fieldset = $form->getElement('base_fieldset'); // frontend properties fieldset - $fieldset = $form->addFieldset('front_fieldset', array('legend'=>Mage::helper('adminhtml')->__('Extra Properties'))); + $fieldset = $form->addFieldset('front_fieldset', ['legend'=>Mage::helper('adminhtml')->__('Extra Properties')]); - $fieldset->addField('use_in_forms', 'multiselect', array( + $fieldset->addField('use_in_forms', 'multiselect', [ 'name' => 'use_in_forms', 'label' => Mage::helper('adminhtml')->__('Use in Forms'), 'title' => Mage::helper('adminhtml')->__('Use in Forms'), 'values' => Mage::getModel('customer/config_forms')->toOptionArray(), 'value' => Mage::getResourceModel('customer/form_attribute')->getFormTypesByAttribute($attribute) - )); + ]); return $this; } @@ -73,16 +72,14 @@ public function customerAttributeEditPrepareSave($observer) $data = $request->getPost(); if ($data) { - /** @var Mage_Eav_Model_Entity_Attribute $model */ $model = $observer->getObject(); if (!isset($data['use_in_forms'])) { - $data['use_in_forms'] = array(); + $data['use_in_forms'] = []; } $model->setData('used_in_forms', $data['use_in_forms']); - } return $this; } @@ -105,15 +102,15 @@ public function customerAddressAttributeEditPrepareForm($observer) $fieldset = $form->getElement('base_fieldset'); // frontend properties fieldset - $fieldset = $form->addFieldset('front_fieldset', array('legend'=>Mage::helper('adminhtml')->__('Extra Properties'))); + $fieldset = $form->addFieldset('front_fieldset', ['legend'=>Mage::helper('adminhtml')->__('Extra Properties')]); - $fieldset->addField('use_in_forms', 'multiselect', array( + $fieldset->addField('use_in_forms', 'multiselect', [ 'name' => 'use_in_forms', 'label' => Mage::helper('adminhtml')->__('Use in Forms'), 'title' => Mage::helper('adminhtml')->__('Use in Forms'), 'values' => Mage::getModel('customer/config_address_forms')->toOptionArray(), 'value' => Mage::getResourceModel('customer/form_attribute')->getFormTypesByAttribute($attribute) - )); + ]); return $this; } @@ -131,18 +128,15 @@ public function customerAddressAttributeEditPrepareSave($observer) $data = $request->getPost(); if ($data) { - /** @var Mage_Eav_Model_Entity_Attribute $model */ $model = $observer->getObject(); if (!isset($data['use_in_forms'])) { - $data['use_in_forms'] = array(); + $data['use_in_forms'] = []; } $model->setData('used_in_forms', $data['use_in_forms']); - } return $this; } - } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php index b5475c0ad..878a7e67a 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php @@ -64,5 +64,4 @@ protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('catalog/attributes/category_attributes'); } - } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php index 30a35771b..df4580be4 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php @@ -64,5 +64,4 @@ protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('catalog/attributes/category_sets'); } - } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php index df57d7cfc..5973827ab 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php @@ -64,5 +64,4 @@ protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_address_attributes'); } - } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php index a0b7a56a5..ece68c6a6 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php @@ -64,5 +64,4 @@ protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_address_sets'); } - } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php index 9bb5691ac..3d45fdb5b 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php @@ -64,5 +64,4 @@ protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_attributes'); } - } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php index 85954b093..76d8fa793 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php @@ -64,5 +64,4 @@ protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_sets'); } - } diff --git a/app/code/core/Mage/Customer/Model/Address.php b/app/code/core/Mage/Customer/Model/Address.php index 5f05f0dbb..ad7334322 100644 --- a/app/code/core/Mage/Customer/Model/Address.php +++ b/app/code/core/Mage/Customer/Model/Address.php @@ -26,7 +26,7 @@ */ class Mage_Customer_Model_Address extends Mage_Customer_Model_Address_Abstract { - const ENTITY = 'customer_address'; + public const ENTITY = 'customer_address'; protected $_customer; diff --git a/app/code/core/Mage/Customer/Model/Config/Address/Forms.php b/app/code/core/Mage/Customer/Model/Config/Address/Forms.php index 8dce22ad2..ab1152ad7 100644 --- a/app/code/core/Mage/Customer/Model/Config/Address/Forms.php +++ b/app/code/core/Mage/Customer/Model/Config/Address/Forms.php @@ -24,7 +24,6 @@ */ class Mage_Customer_Model_Config_Address_Forms { - /** * Options getter * @@ -32,20 +31,20 @@ class Mage_Customer_Model_Config_Address_Forms */ public function toOptionArray() { - return array( - array( + return [ + [ 'value' => 'adminhtml_customer_address', 'label' => Mage::helper('customer')->__('Adminhtml Customer Address') - ), - array( + ], + [ 'value' => 'customer_address_edit', 'label' => Mage::helper('customer')->__('Customer Address Edit') - ), - array( + ], + [ 'value' => 'customer_register_address', 'label' => Mage::helper('customer')->__('Customer Register Address') - ), - ); + ], + ]; } /** @@ -60,5 +59,4 @@ public function toOptionHash() array_column($this->toOptionArray(), 'label') ); } - } diff --git a/app/code/core/Mage/Customer/Model/Config/Forms.php b/app/code/core/Mage/Customer/Model/Config/Forms.php index 2c85a830a..f7e209cb3 100644 --- a/app/code/core/Mage/Customer/Model/Config/Forms.php +++ b/app/code/core/Mage/Customer/Model/Config/Forms.php @@ -24,7 +24,6 @@ */ class Mage_Customer_Model_Config_Forms { - /** * Options getter * @@ -32,28 +31,28 @@ class Mage_Customer_Model_Config_Forms */ public function toOptionArray() { - return array( - array( + return [ + [ 'value' => 'adminhtml_checkout', 'label' => Mage::helper('customer')->__('Adminhtml Checkout') - ), - array( + ], + [ 'value' => 'adminhtml_customer', 'label' => Mage::helper('customer')->__('Adminhtml Customer') - ), - array( + ], + [ 'value' => 'checkout_register', 'label' => Mage::helper('customer')->__('Checkout Register') - ), - array( + ], + [ 'value' => 'customer_account_create', 'label' => Mage::helper('customer')->__('Customer Account Create') - ), - array( + ], + [ 'value' => 'customer_account_edit', 'label' => Mage::helper('customer')->__('Customer Account Edit') - ), - ); + ], + ]; } /** @@ -68,5 +67,4 @@ public function toOptionHash() array_column($this->toOptionArray(), 'label') ); } - } diff --git a/app/code/core/Mage/Customer/Model/Customer.php b/app/code/core/Mage/Customer/Model/Customer.php index 3f5e14881..94ba9a072 100644 --- a/app/code/core/Mage/Customer/Model/Customer.php +++ b/app/code/core/Mage/Customer/Model/Customer.php @@ -104,7 +104,7 @@ */ class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract { - const ENTITY = 'customer'; + public const ENTITY = 'customer'; /** * Configuration paths for email templates and identities @@ -139,7 +139,7 @@ class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract public const SUBSCRIBED_YES = 'yes'; public const SUBSCRIBED_NO = 'no'; - const CACHE_TAG = self::ENTITY; + public const CACHE_TAG = self::ENTITY; /** * Minimum Password Length diff --git a/app/code/core/Mage/Customer/Model/Form.php b/app/code/core/Mage/Customer/Model/Form.php index e8253b8a9..e6e87734d 100644 --- a/app/code/core/Mage/Customer/Model/Form.php +++ b/app/code/core/Mage/Customer/Model/Form.php @@ -42,7 +42,7 @@ class Mage_Customer_Model_Form extends Mage_Eav_Model_Form protected function _getFormAttributeCollection() { $collection = parent::_getFormAttributeCollection() - ->addFieldToFilter('ea.attribute_code', array('neq' => 'created_at')); + ->addFieldToFilter('ea.attribute_code', ['neq' => 'created_at']); $entity = $this->getEntity(); $attributeSetId = null; @@ -51,8 +51,7 @@ protected function _getFormAttributeCollection() $group = Mage::getModel('customer/group') ->load($entity->getGroupId()); $attributeSetId = $group->getCustomerAttributeSetId(); - - } else if ($entity instanceof Mage_Customer_Model_Address) { + } elseif ($entity instanceof Mage_Customer_Model_Address) { $customer = $entity->getCustomer(); if ($customer) { $group = Mage::getModel('customer/group') diff --git a/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php index 45d867f46..7f9df9fc1 100644 --- a/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php +++ b/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php @@ -57,17 +57,17 @@ public function filterAttributeSet($attributeSetId) { $this->getSelect() ->joinInner( - array('eea' => $this->getTable('eav/entity_attribute')), + ['eea' => $this->getTable('eav/entity_attribute')], 'main_table.attribute_id = eea.attribute_id', - array() + [] ) ->joinLeft( - array('eag' => $this->getTable('eav/attribute_group')), + ['eag' => $this->getTable('eav/attribute_group')], 'eea.attribute_group_id = eag.attribute_group_id', - array('eag.attribute_group_name') + ['eag.attribute_group_name'] ) ->where('eea.attribute_set_id = ?', $attributeSetId) - ->order(array('eag.sort_order', 'eea.sort_order')); + ->order(['eag.sort_order', 'eea.sort_order']); return $this; } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php index ef4ad4eb6..64d801155 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php @@ -45,5 +45,4 @@ public function getHeaderCssClass() { return 'icon-head head-eav-attribute'; } - } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php index e56fe4674..3fff53e84 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php @@ -20,7 +20,6 @@ class Mage_Eav_Block_Adminhtml_Attribute_Edit extends Mage_Adminhtml_Block_Widget_Form_Container { - public function __construct() { $this->_objectId = 'attribute_id'; @@ -31,11 +30,11 @@ public function __construct() $this->_addButton( 'save_and_edit_button', - array( + [ 'label' => Mage::helper('eav')->__('Save and Continue Edit'), 'onclick' => 'saveAndContinueEdit()', 'class' => 'save' - ), + ], 100 ); @@ -57,25 +56,23 @@ public function getHeaderText() $frontendLabel = $frontendLabel[0]; } return Mage::helper('eav')->__('Edit %s Attribute "%s"', Mage::helper('eav')->formatTypeCode(Mage::registry('entity_type')), $this->escapeHtml($frontendLabel)); - } - else { + } else { return Mage::helper('eav')->__('New %s Attribute', Mage::helper('eav')->formatTypeCode(Mage::registry('entity_type'))); } } public function getValidationUrl() { - return $this->getUrl('*/*/validate', array('_current'=>true)); + return $this->getUrl('*/*/validate', ['_current'=>true]); } public function getSaveUrl() { - return $this->getUrl('*/*/save', array('_current'=>true, 'back'=>null)); + return $this->getUrl('*/*/save', ['_current'=>true, 'back'=>null]); } public function getHeaderCssClass() { return 'icon-head head-eav-attribute'; } - } 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 index 7a37b2b7a..fa39774e2 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Form.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Form.php @@ -22,7 +22,7 @@ class Mage_Eav_Block_Adminhtml_Attribute_Edit_Form extends Mage_Adminhtml_Block_ { protected function _prepareForm() { - $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')); + $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/Eav/Block/Adminhtml/Attribute/Edit/Tab/Main.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Main.php index 430ae987c..ffd56f672 100644 --- 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 @@ -57,13 +57,13 @@ protected function _prepareForm() ); $frontendInputElm = $form->getElement('frontend_input'); - $additionalTypes = array(); + $additionalTypes = []; $response = new Varien_Object(); - $response->setTypes(array()); - Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_types", array('response'=>$response)); - $_disabledTypes = array(); - $_hiddenFields = array(); + $response->setTypes([]); + Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_types", ['response'=>$response]); + $_disabledTypes = []; + $_hiddenFields = []; foreach ($response->getTypes() as $type) { $additionalTypes[] = $type; if (isset($type['hide_fields'])) { @@ -79,11 +79,11 @@ protected function _prepareForm() $frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes); $frontendInputElm->setValues($frontendInputValues); - $scopes = array( + $scopes = [ Mage_Eav_Model_Entity_Attribute::SCOPE_STORE =>Mage::helper('eav')->__('Store View'), Mage_Eav_Model_Entity_Attribute::SCOPE_WEBSITE =>Mage::helper('eav')->__('Website'), Mage_Eav_Model_Entity_Attribute::SCOPE_GLOBAL =>Mage::helper('eav')->__('Global'), - ); + ]; if ($attributeObject->getAttributeCode() == 'status') { unset($scopes[Mage_Eav_Model_Entity_Attribute::SCOPE_STORE]); @@ -92,20 +92,20 @@ protected function _prepareForm() $response = new Varien_Object(); $response->setScopes($scopes); $response->setAttribute($attributeObject); - Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_scopes", array('response'=>$response)); + Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_scopes", ['response'=>$response]); - $fieldset->addField('is_global', 'select', array( + $fieldset->addField('is_global', 'select', [ 'name' => 'is_global', 'label' => Mage::helper('eav')->__('Scope'), 'title' => Mage::helper('eav')->__('Scope'), 'note' => Mage::helper('eav')->__('Declare attribute value saving scope'), 'values'=> $response->getScopes(), - ), 'attribute_code'); + ], 'attribute_code'); - Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_edit_prepare_form", array( + Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_edit_prepare_form", [ 'form' => $form, 'attribute' => $attributeObject - )); + ]); return $this; } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tabs.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tabs.php index 761995476..9806ea0e1 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tabs.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tabs.php @@ -30,22 +30,21 @@ public function __construct() protected function _beforeToHtml() { - $this->addTab('main', array( + $this->addTab('main', [ 'label' => Mage::helper('eav')->__('Properties'), 'title' => Mage::helper('eav')->__('Properties'), 'content' => $this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tab_main')->toHtml(), 'active' => true - )); + ]); $model = Mage::registry('entity_attribute'); - $this->addTab('labels', array( + $this->addTab('labels', [ 'label' => Mage::helper('eav')->__('Manage Label / Options'), 'title' => Mage::helper('eav')->__('Manage Label / Options'), 'content' => $this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tab_options')->toHtml(), - )); + ]); return parent::_beforeToHtml(); } - } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php index dc2568137..72f464fe2 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php @@ -45,18 +45,18 @@ protected function _prepareColumns() { parent::_prepareColumns(); - $this->addColumn('is_global', array( + $this->addColumn('is_global', [ 'header'=>Mage::helper('eav')->__('Scope'), 'sortable'=>true, 'index'=>'is_global', 'type' => 'options', - 'options' => array( + 'options' => [ Mage_Eav_Model_Entity_Attribute::SCOPE_STORE =>Mage::helper('eav')->__('Store View'), Mage_Eav_Model_Entity_Attribute::SCOPE_WEBSITE =>Mage::helper('eav')->__('Website'), Mage_Eav_Model_Entity_Attribute::SCOPE_GLOBAL =>Mage::helper('eav')->__('Global'), - ), + ], 'align' => 'center', - )); + ]); return $this; } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php index b22883bb3..c33be7006 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php @@ -50,5 +50,4 @@ public function getHeaderCssClass() { return 'icon-head head-eav-attribute-sets'; } - } 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 index 4251d08ac..4833137d2 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php @@ -27,7 +27,6 @@ */ class Mage_Eav_Block_Adminhtml_Attribute_Set_Grid extends Mage_Adminhtml_Block_Widget_Grid { - public function __construct() { parent::__construct(); @@ -56,17 +55,16 @@ protected function _prepareColumns() 'index' => 'attribute_set_id', ));*/ - $this->addColumn('set_name', array( + $this->addColumn('set_name', [ 'header' => Mage::helper('eav')->__('Set Name'), 'align' => 'left', 'sortable' => true, 'index' => 'attribute_set_name', - )); + ]); } public function getRowUrl($row) { - return $this->getUrl('*/*/edit', array('id'=>$row->getAttributeSetId())); + return $this->getUrl('*/*/edit', ['id'=>$row->getAttributeSetId()]); } - } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php index 23ccec4bc..d9030820e 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php @@ -45,47 +45,59 @@ protected function _prepareLayout() { $setId = $this->_getSetId(); - $this->setChild('group_tree', + $this->setChild( + 'group_tree', $this->getLayout()->createBlock('eav/adminhtml_attribute_set_main_tree_group') ); - $this->setChild('edit_set_form', + $this->setChild( + 'edit_set_form', $this->getLayout()->createBlock('eav/adminhtml_attribute_set_main_formset') ); - $this->setChild('delete_group_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + $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(array( + $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(array( + $this->setChild( + 'back_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ 'label' => Mage::helper('eav')->__('Back'), - 'onclick' => 'setLocation(\''.$this->getUrl('*/*/').'\')', + 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/') . '\')', 'class' => 'back' - ))); + ]) + ); - $this->setChild('reset_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + $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(array( + $this->setChild( + 'save_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ 'label' => Mage::helper('eav')->__('Save Attribute Set'), 'onclick' => 'editSet.save();', 'class' => 'save' - ))); + ]) + ); if ($entity_type = Mage::registry('entity_type')) { $deleteConfirmMessage = $this->jsQuoteEscape(Mage::helper('eav') @@ -94,19 +106,23 @@ protected function _prepareLayout() $deleteConfirmMessage = $this->jsQuoteEscape(Mage::helper('eav') ->__('All items of this set will be deleted! Are you sure you want to delete this attribute set?')); } - $deleteUrl = $this->getUrlSecure('*/*/delete', array('id' => $setId)); - $this->setChild('delete_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + $deleteUrl = $this->getUrlSecure('*/*/delete', ['id' => $setId]); + $this->setChild( + 'delete_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ 'label' => Mage::helper('eav')->__('Delete Attribute Set'), 'onclick' => 'deleteConfirm(\'' . $deleteConfirmMessage . '\', \'' . $deleteUrl . '\')', 'class' => 'delete' - ))); + ]) + ); - $this->setChild('rename_button', - $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array( + $this->setChild( + 'rename_button', + $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ 'label' => Mage::helper('eav')->__('New Set Name'), 'onclick' => 'editSet.rename()' - ))); + ]) + ); return parent::_prepareLayout(); } @@ -148,7 +164,7 @@ protected function _getHeader() */ public function getMoveUrl() { - return $this->getUrl('*/*/save', array('id' => $this->_getSetId())); + return $this->getUrl('*/*/save', ['id' => $this->_getSetId()]); } /** @@ -158,7 +174,7 @@ public function getMoveUrl() */ public function getGroupUrl() { - return $this->getUrl('*/*/save', array('id' => $this->_getSetId())); + return $this->getUrl('*/*/save', ['id' => $this->_getSetId()]); } /** @@ -168,7 +184,7 @@ public function getGroupUrl() */ public function getGroupTreeJson() { - $items = array(); + $items = []; $setId = $this->_getSetId(); /* @var $groups Mage_Eav_Model_Mysql4_Entity_Attribute_Group_Collection */ @@ -183,7 +199,7 @@ public function getGroupTreeJson() /* @var $node Mage_Eav_Model_Entity_Attribute_Group */ foreach ($groups as $node) { - $item = array(); + $item = []; $item['text'] = $node->getAttributeGroupName(); $item['id'] = $node->getAttributeGroupId(); $item['cls'] = 'folder'; @@ -197,10 +213,10 @@ public function getGroupTreeJson() ->load(); if ($nodeChildren->getSize() > 0) { - $item['children'] = array(); + $item['children'] = []; foreach ($nodeChildren->getItems() as $child) { /* @var $child Mage_Eav_Model_Entity_Attribute */ - $attr = array( + $attr = [ 'text' => $child->getAttributeCode(), 'id' => $child->getAttributeId(), 'cls' => (!$child->getIsUserDefined()) ? 'system-leaf' : 'leaf', @@ -209,7 +225,7 @@ public function getGroupTreeJson() 'leaf' => true, 'is_user_defined' => $child->getIsUserDefined(), 'entity_id' => $child->getEntityAttributeId() - ); + ]; $item['children'][] = $attr; } @@ -228,7 +244,7 @@ public function getGroupTreeJson() */ public function getAttributeTreeJson() { - $items = array(); + $items = []; $setId = $this->_getSetId(); /* @var $entity_type Mage_Eav_Model_Entity_Type */ @@ -240,7 +256,7 @@ public function getAttributeTreeJson() ->setAttributeSetFilter($setId) ->load(); - $attributesIds = array('0'); + $attributesIds = ['0']; /* @var $item Mage_Eav_Model_Entity_Attribute */ foreach ($collection->getItems() as $item) { $attributesIds[] = $item->getAttributeId(); @@ -254,7 +270,7 @@ public function getAttributeTreeJson() ->load(); foreach ($attributes as $child) { - $attr = array( + $attr = [ 'text' => $child->getAttributeCode(), 'id' => $child->getAttributeId(), 'cls' => 'leaf', @@ -263,19 +279,19 @@ public function getAttributeTreeJson() 'leaf' => true, 'is_user_defined' => $child->getIsUserDefined(), 'entity_id' => $child->getEntityId() - ); + ]; $items[] = $attr; } if (count($items) == 0) { - $items[] = array( + $items[] = [ 'text' => Mage::helper('eav')->__('Empty'), 'id' => 'empty', 'cls' => 'folder', 'allowDrop' => false, 'allowDrag' => false, - ); + ]; } return Mage::helper('core')->jsonEncode($items); @@ -409,7 +425,7 @@ protected function _getSetData() protected function _toHtml() { $type = Mage::registry('entity_type')->getEntityTypeCode(); - Mage::dispatchEvent("adminhtml_{$type}_attribute_set_main_html_before", array('block' => $this)); + Mage::dispatchEvent("adminhtml_{$type}_attribute_set_main_html_before", ['block' => $this]); return parent::_toHtml(); } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php index 99ab6c967..5cde32a59 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php @@ -35,26 +35,30 @@ protected function _prepareForm() { $form = new Varien_Data_Form(); - $fieldset = $form->addFieldset('set_fieldset', array('legend'=>Mage::helper('eav')->__('Add New Attribute'))); + $fieldset = $form->addFieldset('set_fieldset', ['legend'=>Mage::helper('eav')->__('Add New Attribute')]); - $fieldset->addField('new_attribute', 'text', - array( - 'label' => Mage::helper('eav')->__('Name'), - 'name' => 'new_attribute', - 'required' => true, - ) + $fieldset->addField( + 'new_attribute', + 'text', + [ + 'label' => Mage::helper('eav')->__('Name'), + 'name' => 'new_attribute', + 'required' => true, + ] ); - $fieldset->addField('submit', 'note', - array( - 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData(array( - 'label' => Mage::helper('eav')->__('Add Attribute'), - 'onclick' => 'this.form.submit();', - 'class' => 'add' - )) - ->toHtml(), - ) + $fieldset->addField( + 'submit', + 'note', + [ + 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData([ + 'label' => Mage::helper('eav')->__('Add Attribute'), + 'onclick' => 'this.form.submit();', + 'class' => 'add' + ]) + ->toHtml(), + ] ); $form->setUseContainer(true); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php index dcdf46643..edb52594f 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php @@ -35,34 +35,39 @@ protected function _prepareForm() { $form = new Varien_Data_Form(); - $fieldset = $form->addFieldset('set_fieldset', array('legend'=>Mage::helper('eav')->__('Add New Group'))); + $fieldset = $form->addFieldset('set_fieldset', ['legend'=>Mage::helper('eav')->__('Add New Group')]); - $fieldset->addField('attribute_group_name', 'text', - array( - 'label' => Mage::helper('eav')->__('Name'), - 'name' => 'attribute_group_name', - 'required' => true, - ) + $fieldset->addField( + 'attribute_group_name', + 'text', + [ + 'label' => Mage::helper('eav')->__('Name'), + 'name' => 'attribute_group_name', + 'required' => true, + ] ); - $fieldset->addField('submit', 'note', - array( - 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData(array( - 'label' => Mage::helper('eav')->__('Add Group'), - 'onclick' => 'this.form.submit();', - 'class' => 'add' - )) - ->toHtml(), - ) + $fieldset->addField( + 'submit', + 'note', + [ + 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData([ + 'label' => Mage::helper('eav')->__('Add Group'), + 'onclick' => 'this.form.submit();', + 'class' => 'add' + ]) + ->toHtml(), + ] ); - $fieldset->addField('attribute_set_id', 'hidden', - array( - 'name' => 'attribute_set_id', - 'value' => $this->_getSetId(), - ) - + $fieldset->addField( + 'attribute_set_id', + 'hidden', + [ + 'name' => 'attribute_set_id', + 'value' => $this->_getSetId(), + ] ); $form->setUseContainer(true); @@ -74,8 +79,8 @@ protected function _prepareForm() protected function _getSetId() { - return ( intval($this->getRequest()->getParam('id')) > 0 ) - ? intval($this->getRequest()->getParam('id')) + return ((int) ($this->getRequest()->getParam('id')) > 0) + ? (int) ($this->getRequest()->getParam('id')) : Mage::registry('entity_type')->getDefaultAttributeSetId(); } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php index 301d9ad99..dbc312145 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php @@ -41,21 +41,21 @@ protected function _prepareForm() ->load($this->getRequest()->getParam('id')); $form = new Varien_Data_Form(); - $fieldset = $form->addFieldset('set_name', array('legend'=> Mage::helper('eav')->__('Edit Set Name'))); - $fieldset->addField('attribute_set_name', 'text', array( + $fieldset = $form->addFieldset('set_name', ['legend'=> Mage::helper('eav')->__('Edit Set Name')]); + $fieldset->addField('attribute_set_name', 'text', [ 'label' => Mage::helper('eav')->__('Name'), 'note' => Mage::helper('eav')->__('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', array( + if (!$this->getRequest()->getParam('id', false)) { + $fieldset->addField('gotoEdit', 'hidden', [ 'name' => 'gotoEdit', 'value' => '1' - )); + ]); /** @var Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection @collection */ $collection = Mage::getModel('eav/entity_attribute_set') @@ -66,13 +66,13 @@ protected function _prepareForm() ->load() ->toOptionArray(); - $fieldset->addField('skeleton_set', 'select', array( + $fieldset->addField('skeleton_set', 'select', [ 'label' => Mage::helper('eav')->__('Based On'), 'name' => 'skeleton_set', 'required' => true, 'class' => 'required-entry', 'values' => $sets, - )); + ]); } $form->setMethod('post'); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php index b87f5c3a9..bee78224f 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php @@ -34,22 +34,27 @@ protected function _construct() protected function _prepareLayout() { - $this->setChild('save_button', + $this->setChild( + 'save_button', $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData(array( + ->setData([ 'label' => Mage::helper('eav')->__('Save Attribute Set'), 'onclick' => 'if (addSet.submit()) disableElements(\'save\');', 'class' => 'save' - ))); - $this->setChild('back_button', + ]) + ); + $this->setChild( + 'back_button', $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData(array( + ->setData([ 'label' => Mage::helper('eav')->__('Back'), - 'onclick' => 'setLocation(\''.$this->getUrl('*/*/').'\')', + 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/') . '\')', 'class' => 'back' - ))); + ]) + ); - $this->setChild('setForm', + $this->setChild( + 'setForm', $this->getLayout()->createBlock('eav/adminhtml_attribute_set_main_formset') ); return parent::_prepareLayout(); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php b/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php index 508eb2fba..2255eb263 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php @@ -27,18 +27,18 @@ */ class Mage_Eav_Block_Adminhtml_Helper_Form_Boolean extends Varien_Data_Form_Element_Select { - public function __construct($attributes=array()) + public function __construct($attributes=[]) { parent::__construct($attributes); - $this->setValues(array( - array( + $this->setValues([ + [ 'label' => Mage::helper('eav')->__('No'), 'value' => 0, - ), - array( + ], + [ 'label' => Mage::helper('eav')->__('Yes'), 'value' => 1, - ), - )); + ], + ]); } } diff --git a/app/code/core/Mage/Eav/Block/Widget/Boolean.php b/app/code/core/Mage/Eav/Block/Widget/Boolean.php index cb0973cd8..caea5d177 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Boolean.php +++ b/app/code/core/Mage/Eav/Block/Widget/Boolean.php @@ -43,11 +43,11 @@ public function _construct() */ public function getOptions() { - $options = array( - array('value' => '', 'label' => Mage::helper('eav')->__('')), - array('value' => '1', 'label' => Mage::helper('eav')->__('Yes')), - array('value' => '0', 'label' => Mage::helper('eav')->__('No')) - ); + $options = [ + ['value' => '', 'label' => Mage::helper('eav')->__('')], + ['value' => '1', 'label' => Mage::helper('eav')->__('Yes')], + ['value' => '0', 'label' => Mage::helper('eav')->__('No')] + ]; return $options; } diff --git a/app/code/core/Mage/Eav/Block/Widget/Date.php b/app/code/core/Mage/Eav/Block/Widget/Date.php index 11a49172c..b75f474ec 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Date.php +++ b/app/code/core/Mage/Eav/Block/Widget/Date.php @@ -29,7 +29,7 @@ class Mage_Eav_Block_Widget_Date extends Mage_Eav_Block_Widget_Abstract * * @var array */ - protected $_dateInputs = array(); + protected $_dateInputs = []; public function _construct() { @@ -102,7 +102,7 @@ public function setDateInput($code, $html) */ public function getSortedDateInputs() { - $strtr = array( + $strtr = [ '%b' => '%1$s', '%B' => '%1$s', '%m' => '%1$s', @@ -110,7 +110,7 @@ public function getSortedDateInputs() '%e' => '%2$s', '%Y' => '%3$s', '%y' => '%3$s' - ); + ]; $dateFormat = preg_replace('/[^\%\w]/', '\\1', $this->getDateFormat()); diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php index a2818da62..bd111e833 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -28,7 +28,6 @@ abstract class Mage_Eav_Controller_Adminhtml_Attribute_Abstract extends Mage_Adminhtml_Controller_Action { - /** @var string $_entityCode */ protected $_entityCode; @@ -77,7 +76,8 @@ public function editAction() if (! $model->getId()) { Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('eav')->__('This attribute no longer exists')); + Mage::helper('eav')->__('This attribute no longer exists') + ); $this->_redirect('*/*/'); return; } @@ -85,7 +85,8 @@ public function editAction() // entity type check if ($model->getEntityTypeId() != $this->_entityType->getEntityTypeId()) { Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('eav')->__('This attribute cannot be edited.')); + Mage::helper('eav')->__('This attribute cannot be edited.') + ); $this->_redirect('*/*/'); return; } @@ -117,7 +118,6 @@ public function editAction() ); $this->renderLayout(); - } public function validateAction() @@ -134,7 +134,8 @@ public function validateAction() if ($attribute->getId() && !$attributeId) { Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('eav')->__('Attribute with the same code already exists')); + Mage::helper('eav')->__('Attribute with the same code already exists') + ); $this->_initLayoutMessages('adminhtml/session'); $response->setError(true); $response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml()); @@ -188,12 +189,12 @@ public function saveAction() //validate attribute_code if (isset($data['attribute_code'])) { - $validatorAttrCode = new Zend_Validate_Regex(array('pattern' => '/^(?!event$)[a-z][a-z_0-9]{1,254}$/')); + $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('eav')->__('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', array('attribute_id' => $id, '_current' => true)); + $this->_redirect('*/*/edit', ['attribute_id' => $id, '_current' => true]); return; } } @@ -207,7 +208,7 @@ public function saveAction() foreach ($validatorInputType->getMessages() as $message) { $session->addError($message); } - $this->_redirect('*/*/edit', array('attribute_id' => $id, '_current' => true)); + $this->_redirect('*/*/edit', ['attribute_id' => $id, '_current' => true]); return; } } @@ -217,7 +218,8 @@ public function saveAction() if (!$model->getId()) { $session->addError( - Mage::helper('eav')->__('This Attribute no longer exists')); + Mage::helper('eav')->__('This Attribute no longer exists') + ); $this->_redirect('*/*/'); return; } @@ -225,7 +227,8 @@ public function saveAction() // entity type check if ($model->getEntityTypeId() != $this->_entityType->getEntityTypeId()) { $session->addError( - Mage::helper('eav')->__('This attribute cannot be updated.')); + Mage::helper('eav')->__('This attribute cannot be updated.') + ); $session->setAttributeData($data); $this->_redirect('*/*/'); return; @@ -274,29 +277,30 @@ public function saveAction() Mage::dispatchEvent( "adminhtml_{$this->_entityCode}_attribute_edit_prepare_save", - array('object' => $model, 'request' => $this->getRequest()) + ['object' => $model, 'request' => $this->getRequest()] ); try { $model->save(); $session->addSuccess( - Mage::helper('eav')->__('The attribute has been saved.')); + Mage::helper('eav')->__('The attribute has been saved.') + ); /** * Clear translation cache because attribute labels are stored in translation */ - Mage::app()->cleanCache(array(Mage_Core_Model_Translate::CACHE_TAG)); + Mage::app()->cleanCache([Mage_Core_Model_Translate::CACHE_TAG]); $session->setAttributeData(false); if ($redirectBack) { - $this->_redirect('*/*/edit', array('attribute_id' => $model->getId(),'_current'=>true)); + $this->_redirect('*/*/edit', ['attribute_id' => $model->getId(),'_current'=>true]); } else { - $this->_redirect('*/*/', array()); + $this->_redirect('*/*/', []); } return; } catch (Exception $e) { $session->addError($e->getMessage()); $session->setAttributeData($data); - $this->_redirect('*/*/edit', array('attribute_id' => $id, '_current' => true)); + $this->_redirect('*/*/edit', ['attribute_id' => $id, '_current' => true]); return; } } @@ -312,7 +316,8 @@ public function deleteAction() $model->load($id); if ($model->getEntityTypeId() != $this->_entityType->getEntityTypeId() || !$model->getIsUserDefined()) { Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('eav')->__('This attribute cannot be deleted.')); + Mage::helper('eav')->__('This attribute cannot be deleted.') + ); $this->_redirect('*/*/'); return; } @@ -320,18 +325,19 @@ public function deleteAction() try { $model->delete(); Mage::getSingleton('adminhtml/session')->addSuccess( - Mage::helper('eav')->__('The attribute has been deleted.')); + Mage::helper('eav')->__('The attribute has been deleted.') + ); $this->_redirect('*/*/'); return; } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); - $this->_redirect('*/*/edit', array('attribute_id' => $this->getRequest()->getParam('attribute_id'))); + $this->_redirect('*/*/edit', ['attribute_id' => $this->getRequest()->getParam('attribute_id')]); return; } } Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('eav')->__('Unable to find an attribute to delete.')); + Mage::helper('eav')->__('Unable to find an attribute to delete.') + ); $this->_redirect('*/*/'); } - } diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php index d9aaebd0f..e5fb12428 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php @@ -28,7 +28,6 @@ abstract class Mage_Eav_Controller_Adminhtml_Set_Abstract extends Mage_Adminhtml_Controller_Action { - /** @var string $_entityCode */ protected $_entityCode; @@ -88,7 +87,8 @@ public function setGridAction() $this->getResponse()->setBody( $this->getLayout() ->createBlock('eav/adminhtml_attribute_set_grid') - ->toHtml()); + ->toHtml() + ); } /** @@ -143,8 +143,10 @@ public function saveAction() $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.')); + $this->_getSession()->addException( + $e, + Mage::helper('eav')->__('An error occurred while saving the attribute set.') + ); $hasError = true; } @@ -152,10 +154,10 @@ public function saveAction() if ($hasError) { $this->_redirect('*/*/add'); } else { - $this->_redirect('*/*/edit', array('id' => $model->getId())); + $this->_redirect('*/*/edit', ['id' => $model->getId()]); } } else { - $response = array(); + $response = []; if ($hasError) { $this->_initLayoutMessages('adminhtml/session'); $response['error'] = 1; @@ -191,5 +193,4 @@ public function deleteAction() $this->_redirectReferer(); } } - } diff --git a/app/code/core/Mage/Eav/Helper/Data.php b/app/code/core/Mage/Eav/Helper/Data.php index 41d7a81f0..234f03e0a 100644 --- a/app/code/core/Mage/Eav/Helper/Data.php +++ b/app/code/core/Mage/Eav/Helper/Data.php @@ -147,21 +147,21 @@ public function getAttributeInputTypes($inputType = null) /** * @todo specify there all relations for properties depending on input type */ - $inputTypes = array( - 'multiselect' => array( + $inputTypes = [ + 'multiselect' => [ 'backend_model' => 'eav/entity_attribute_backend_array' - ), - 'boolean' => array( + ], + 'boolean' => [ 'source_model' => 'eav/entity_attribute_source_boolean' - ) - ); + ] + ]; if (is_null($inputType)) { return $inputTypes; } elseif (isset($inputTypes[$inputType])) { return $inputTypes[$inputType]; } - return array(); + return []; } /** diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Entity/Attribute.php index cfa3d6e1e..c680c0acb 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute.php @@ -31,9 +31,9 @@ */ class Mage_Eav_Model_Entity_Attribute extends Mage_Eav_Model_Entity_Attribute_Abstract { - const SCOPE_STORE = 0; - const SCOPE_GLOBAL = 1; - const SCOPE_WEBSITE = 2; + public const SCOPE_STORE = 0; + public const SCOPE_GLOBAL = 1; + public const SCOPE_WEBSITE = 2; /** * Prefix of model events names diff --git a/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php b/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php index 73588662b..fa811db60 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php @@ -45,10 +45,10 @@ public function getFormTypesByAttribute($attribute) $attribute = $attribute->getId(); } if (!$attribute) { - return array(); + return []; } - $bind = array('attribute_id' => $attribute); + $bind = ['attribute_id' => $attribute]; $select = $this->_getReadAdapter()->select() ->from($this->getMainTable(), 'form_code') ->where('attribute_id = :attribute_id'); From 69ffce0785ac31155bf4abe07d83853ee6c308a5 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Thu, 19 Sep 2024 09:35:11 -0700 Subject: [PATCH 009/113] Fix category controllers to extend correct class. --- .../controllers/Catalog/Category/AttributeController.php | 4 ++-- .../Adminhtml/controllers/Catalog/Category/SetController.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php index 878a7e67a..11246181a 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php @@ -18,7 +18,7 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -require_once 'Mage/Eav/controllers/Adminhtml/Attribute/AbstractController.php'; +require_once 'Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php'; /** * Catalog category attribute controller @@ -28,7 +28,7 @@ * @author Magento Core Team */ -class Mage_Adminhtml_Catalog_Category_AttributeController extends Mage_Eav_Adminhtml_Attribute_AbstractController +class Mage_Adminhtml_Catalog_Category_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { /** * Additional initialization diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php index df4580be4..6af05bf34 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php @@ -18,7 +18,7 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -require_once 'Mage/Eav/controllers/Adminhtml/Set/AbstractController.php'; +require_once 'Mage/Eav/Controller/Adminhtml/Set/Abstract.php'; /** * Catalog category attribute sets controller @@ -28,7 +28,7 @@ * @author Magento Core Team */ -class Mage_Adminhtml_Catalog_Category_SetController extends Mage_Eav_Adminhtml_Set_AbstractController +class Mage_Adminhtml_Catalog_Category_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { /** * Additional initialization From 0383ab584cc0da0c577922b73a6dd518ef2b6bb9 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Thu, 19 Sep 2024 18:06:54 +0100 Subject: [PATCH 010/113] File headers + merge --- .../Adminhtml/Model/Customer/Observer.php | 22 +++-------- .../Catalog/Category/AttributeController.php | 6 --- .../Catalog/Category/SetController.php | 5 --- .../Customer/Address/AttributeController.php | 27 +++---------- .../Customer/Address/SetController.php | 27 +++---------- .../Customer/AttributeController.php | 27 +++---------- .../controllers/Customer/SetController.php | 27 +++---------- .../Customer/Model/Config/Address/Forms.php | 30 +++++--------- .../core/Mage/Customer/Model/Config/Forms.php | 30 +++++--------- .../Mage/Eav/Block/Adminhtml/Attribute.php | 23 +++-------- .../Eav/Block/Adminhtml/Attribute/Edit.php | 25 +++++------- .../Block/Adminhtml/Attribute/Edit/Form.php | 25 +++++------- .../Adminhtml/Attribute/Edit/Tab/Main.php | 27 +++++-------- .../Adminhtml/Attribute/Edit/Tab/Options.php | 25 +++++------- .../Block/Adminhtml/Attribute/Edit/Tabs.php | 25 +++++------- .../Eav/Block/Adminhtml/Attribute/Grid.php | 25 +++++------- .../Eav/Block/Adminhtml/Attribute/Set.php | 23 +++-------- .../Block/Adminhtml/Attribute/Set/Grid.php | 32 +++------------ .../Block/Adminhtml/Attribute/Set/Main.php | 26 +++---------- .../Attribute/Set/Main/Formattribute.php | 23 +++-------- .../Attribute/Set/Main/Formgroup.php | 23 +++-------- .../Adminhtml/Attribute/Set/Main/Formset.php | 27 +++---------- .../Attribute/Set/Main/Tree/Attribute.php | 23 +++-------- .../Attribute/Set/Main/Tree/Group.php | 23 +++-------- .../Adminhtml/Attribute/Set/Toolbar/Add.php | 24 +++--------- .../Block/Adminhtml/Helper/Form/Boolean.php | 22 +++-------- .../core/Mage/Eav/Block/Widget/Abstract.php | 21 +++------- .../core/Mage/Eav/Block/Widget/Boolean.php | 32 ++++----------- app/code/core/Mage/Eav/Block/Widget/Date.php | 23 +++-------- .../Mage/Eav/Block/Widget/Multiselect.php | 39 ++++--------------- .../core/Mage/Eav/Block/Widget/Select.php | 32 ++++----------- app/code/core/Mage/Eav/Block/Widget/Text.php | 25 +++--------- .../core/Mage/Eav/Block/Widget/Textarea.php | 25 +++--------- .../Adminhtml/Attribute/Abstract.php | 23 +++-------- .../Eav/Controller/Adminhtml/Set/Abstract.php | 23 +++-------- .../default/template/eav/attribute/js.phtml | 21 +++------- 36 files changed, 238 insertions(+), 648 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index 312aef5b2..3d4968f28 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -1,21 +1,12 @@ */ class Mage_Adminhtml_Model_Customer_Observer { diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php index 11246181a..b5600ba75 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php @@ -25,15 +25,9 @@ * * @category Mage * @package Mage_Adminhtml - * @author Magento Core Team */ - class Mage_Adminhtml_Catalog_Category_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { - /** - * Additional initialization - * - */ protected function _construct() { $this->_entityCode = Mage_Catalog_Model_Category::ENTITY; diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php index 6af05bf34..61d861ad3 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php @@ -27,13 +27,8 @@ * @package Mage_Adminhtml * @author Magento Core Team */ - class Mage_Adminhtml_Catalog_Category_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { - /** - * Additional initialization - * - */ protected function _construct() { $this->_entityCode = Mage_Catalog_Model_Category::ENTITY; diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php index 5973827ab..6b9e44af6 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php @@ -1,21 +1,12 @@ */ - class Mage_Adminhtml_Customer_Address_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { - /** - * Additional initialization - * - */ protected function _construct() { $this->_entityCode = Mage_Customer_Model_Address::ENTITY; diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php index ece68c6a6..f40bbe574 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php @@ -1,21 +1,12 @@ */ - class Mage_Adminhtml_Customer_Address_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { - /** - * Additional initialization - * - */ protected function _construct() { $this->_entityCode = Mage_Customer_Model_Address::ENTITY; diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php index 3d45fdb5b..f8fcd97aa 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php @@ -1,21 +1,12 @@ */ - class Mage_Adminhtml_Customer_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { - /** - * Additional initialization - * - */ protected function _construct() { $this->_entityCode = Mage_Customer_Model_Customer::ENTITY; diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php index 76d8fa793..ce0495c1f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php @@ -1,21 +1,12 @@ */ - class Mage_Adminhtml_Customer_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { - /** - * Additional initialization - * - */ protected function _construct() { $this->_entityCode = Mage_Customer_Model_Customer::ENTITY; diff --git a/app/code/core/Mage/Customer/Model/Config/Address/Forms.php b/app/code/core/Mage/Customer/Model/Config/Address/Forms.php index ab1152ad7..4ae39df47 100644 --- a/app/code/core/Mage/Customer/Model/Config/Address/Forms.php +++ b/app/code/core/Mage/Customer/Model/Config/Address/Forms.php @@ -1,35 +1,23 @@ */ - class Mage_Eav_Block_Adminhtml_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Container { public function __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 index 3fff53e84..fae309680 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php @@ -1,23 +1,18 @@ */ - class Mage_Eav_Block_Adminhtml_Attribute_Set extends Mage_Adminhtml_Block_Widget_Grid_Container { public function __construct() 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 index 4833137d2..664103538 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php @@ -1,29 +1,17 @@ */ class Mage_Eav_Block_Adminhtml_Attribute_Set_Grid extends Mage_Adminhtml_Block_Widget_Grid { @@ -47,14 +35,6 @@ protected function _prepareCollection() protected function _prepareColumns() { - /*$this->addColumn('set_id', array( - 'header' => Mage::helper('eav')->__('ID'), - 'align' => 'right', - 'sortable' => true, - 'width' => '50px', - 'index' => 'attribute_set_id', - ));*/ - $this->addColumn('set_name', [ 'header' => Mage::helper('eav')->__('Set Name'), 'align' => 'left', diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php index d9030820e..35e1f85d5 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php @@ -1,21 +1,12 @@ */ class Mage_Eav_Block_Adminhtml_Attribute_Set_Main extends Mage_Adminhtml_Block_Template { - /** - * Initialize template - * - */ protected function _construct() { $this->setTemplate('eav/attribute/set/main.phtml'); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php index 5cde32a59..1f3aefa18 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php @@ -1,29 +1,18 @@ */ - class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Formattribute extends Mage_Adminhtml_Block_Widget_Form { public function __construct() diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php index edb52594f..657e654c4 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php @@ -1,29 +1,18 @@ */ - class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Formgroup extends Mage_Adminhtml_Block_Widget_Form { public function __construct() diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php index dbc312145..8455b32a7 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php @@ -1,29 +1,18 @@ */ - class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Formset extends Mage_Adminhtml_Block_Widget_Form { public function __construct() @@ -31,10 +20,6 @@ public function __construct() parent::__construct(); } - /** - * Prepares attribute set form - * - */ protected function _prepareForm() { $data = Mage::getModel('eav/entity_attribute_set') diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php index 8bd7ad8d0..8d4e30816 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php @@ -1,29 +1,18 @@ */ - class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Tree_Attribute extends Mage_Adminhtml_Block_Template { protected function _construct() diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php index e4eba07c4..ee268aa45 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php @@ -1,29 +1,18 @@ */ - class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Tree_Group extends Mage_Adminhtml_Block_Template { protected function _construct() diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php index bee78224f..e60c7af63 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php @@ -1,29 +1,17 @@ */ class Mage_Eav_Block_Adminhtml_Attribute_Set_Toolbar_Add extends Mage_Adminhtml_Block_Template { diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php b/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php index 2255eb263..cc57a5416 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php @@ -1,21 +1,12 @@ */ class Mage_Eav_Block_Adminhtml_Helper_Form_Boolean extends Varien_Data_Form_Element_Select { diff --git a/app/code/core/Mage/Eav/Block/Widget/Abstract.php b/app/code/core/Mage/Eav/Block/Widget/Abstract.php index 54c824a87..84bc45fc1 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Abstract.php +++ b/app/code/core/Mage/Eav/Block/Widget/Abstract.php @@ -1,21 +1,12 @@ */ class Mage_Eav_Block_Widget_Boolean extends Mage_Eav_Block_Widget_Abstract { - /** - * Initialize block - */ public function _construct() { parent::_construct(); $this->setTemplate('eav/widget/boolean.phtml'); } - /** - * Get select options - * - * @return array - */ - public function getOptions() + public function getOptions(): array { $options = [ ['value' => '', 'label' => Mage::helper('eav')->__('')], diff --git a/app/code/core/Mage/Eav/Block/Widget/Date.php b/app/code/core/Mage/Eav/Block/Widget/Date.php index b75f474ec..b647048ee 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Date.php +++ b/app/code/core/Mage/Eav/Block/Widget/Date.php @@ -1,21 +1,12 @@ */ class Mage_Eav_Block_Widget_Multiselect extends Mage_Eav_Block_Widget_Abstract { - /** - * Initialize block - */ public function _construct() { parent::_construct(); $this->setTemplate('eav/widget/multiselect.phtml'); } - /** - * Get select element extra attributes - * - * @return string - */ - public function getFieldParams() + public function getFieldParams(): string { return 'multiple'; } - /** - * Get select options - * - * @return array - */ - public function getOptions() + public function getOptions(): array { return $this->getAttribute()->getSource()->getAllOptions(false); } diff --git a/app/code/core/Mage/Eav/Block/Widget/Select.php b/app/code/core/Mage/Eav/Block/Widget/Select.php index b97509537..5eeef362d 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Select.php +++ b/app/code/core/Mage/Eav/Block/Widget/Select.php @@ -1,21 +1,12 @@ */ class Mage_Eav_Block_Widget_Select extends Mage_Eav_Block_Widget_Abstract { - /** - * Initialize block - */ public function _construct() { parent::_construct(); $this->setTemplate('eav/widget/select.phtml'); } - /** - * Get select options - * - * @return array - */ - public function getOptions() + public function getOptions(): array { return $this->getAttribute()->getSource()->getAllOptions(); } diff --git a/app/code/core/Mage/Eav/Block/Widget/Text.php b/app/code/core/Mage/Eav/Block/Widget/Text.php index 4402d6645..649224202 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Text.php +++ b/app/code/core/Mage/Eav/Block/Widget/Text.php @@ -1,21 +1,12 @@ */ class Mage_Eav_Block_Widget_Text extends Mage_Eav_Block_Widget_Abstract { - /** - * Initialize block - */ public function _construct() { parent::_construct(); diff --git a/app/code/core/Mage/Eav/Block/Widget/Textarea.php b/app/code/core/Mage/Eav/Block/Widget/Textarea.php index 5989f5e84..16d24b1f1 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Textarea.php +++ b/app/code/core/Mage/Eav/Block/Widget/Textarea.php @@ -1,21 +1,12 @@ */ class Mage_Eav_Block_Widget_Textarea extends Mage_Eav_Block_Widget_Abstract { - /** - * Initialize block - */ public function _construct() { parent::_construct(); diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php index bd111e833..3da23bc9a 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -1,21 +1,12 @@ */ - abstract class Mage_Eav_Controller_Adminhtml_Attribute_Abstract extends Mage_Adminhtml_Controller_Action { /** @var string $_entityCode */ diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php index e5fb12428..ae4f73745 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php @@ -1,21 +1,12 @@ */ - abstract class Mage_Eav_Controller_Adminhtml_Set_Abstract extends Mage_Adminhtml_Controller_Action { /** @var string $_entityCode */ diff --git a/app/design/adminhtml/default/default/template/eav/attribute/js.phtml b/app/design/adminhtml/default/default/template/eav/attribute/js.phtml index 4f32178b0..70d7af43f 100644 --- a/app/design/adminhtml/default/default/template/eav/attribute/js.phtml +++ b/app/design/adminhtml/default/default/template/eav/attribute/js.phtml @@ -1,21 +1,12 @@ + From 817c3e9f1e4d4818437cfe26b6915fdee18cd125 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Fri, 27 Sep 2024 16:34:05 -0700 Subject: [PATCH 023/113] Support attributes with website tables --- .../Adminhtml/Model/Customer/Observer.php | 95 ++----------------- app/code/core/Mage/Adminhtml/etc/config.xml | 16 +--- .../core/Mage/Customer/Model/Attribute.php | 27 ++++++ app/code/core/Mage/Customer/etc/config.xml | 18 ++++ .../Attribute/Edit/Main/Abstract.php | 66 ++++++++++++- .../Edit/Renderer/Fieldset/Element.php | 89 +++++++++++++++++ .../Adminhtml/Attribute/Abstract.php | 63 +++++++++--- app/code/core/Mage/Eav/Model/Attribute.php | 11 +++ .../core/Mage/Eav/Model/Entity/Attribute.php | 4 + .../Mage/Eav/Model/Resource/Attribute.php | 41 ++++++-- .../Eav/Model/Resource/Entity/Attribute.php | 10 ++ .../edit/renderer/fieldset/element.phtml | 44 +++++++++ 12 files changed, 363 insertions(+), 121 deletions(-) create mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Renderer/Fieldset/Element.php create mode 100644 app/design/adminhtml/default/default/template/eav/attribute/edit/renderer/fieldset/element.phtml diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index 0801bf942..dcd9aa457 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -19,12 +19,12 @@ class Mage_Adminhtml_Model_Customer_Observer { /** - * Add frontend properties to customer attribute edit form + * Modify customer and customer_address attribute edit forms * * @param Varien_Event_Observer $observer * @return $this */ - public function customerAttributeEditPrepareForm($observer) + public function attributeEditPrepareForm($observer) { /** @var Mage_Customer_Model_Attribute $attribute */ $attribute = $observer->getAttribute(); @@ -35,9 +35,6 @@ public function customerAttributeEditPrepareForm($observer) /** @var Varien_Data_Form_Element_Fieldset $fieldset */ $fieldset = $form->getElement('base_fieldset'); - // frontend properties fieldset - $fieldset = $form->addFieldset('front_fieldset', ['legend' => Mage::helper('adminhtml')->__('Extra Properties')]); - $fieldset->addField('use_in_forms', 'multiselect', [ 'name' => 'use_in_forms', 'label' => Mage::helper('adminhtml')->__('Use in Forms'), @@ -50,102 +47,26 @@ public function customerAttributeEditPrepareForm($observer) } /** - * Save frontend properties from customer attribute edit form + * Save extra properties from customer and customer_address attribute edit forms * * @param Varien_Event_Observer $observer * @return $this */ - public function customerAttributeEditPrepareSave($observer) + public function attributeEditPrepareSave($observer) { /** @var Mage_Core_Controller_Request_Http $request */ $request = $observer->getRequest(); - $data = $request->getPost(); - if ($data) { - /** @var Mage_Eav_Model_Entity_Attribute $model */ - $model = $observer->getObject(); - - if (!isset($data['use_in_forms'])) { - $data['use_in_forms'] = []; - } - - $model->setData('used_in_forms', $data['use_in_forms']); - } - return $this; - } - - /** - * Add website switcher to customer attribute edit form - * - * @param Varien_Event_Observer $observer - * @return $this - */ - public function customerAttributeEditGenerateBlocksAfter($observer) - { - $controller = $observer->getAction(); - $fullActionName = $controller->getFullActionName(); - $attribute_id = (int)$controller->getRequest()->getParam('attribute_id'); - - if ($fullActionName === 'adminhtml_customer_attribute_edit' && $attribute_id) { - $controller->getLayout()->getBlock('left')->append( - $controller->getLayout()->createBlock('adminhtml/website_switcher') - ->setLabel($controller->__('Current Configuration Scope:')) - ->setDefaultWebsiteName($controller->__('Default Config')) - ); - } - return; - } - - /** - * Add frontend properties to customer address attribute edit form - * - * @param Varien_Event_Observer $observer - * @return $this - */ - public function customerAddressAttributeEditPrepareForm($observer) - { - /** @var Mage_Customer_Model_Attribute $attribute */ - $attribute = $observer->getAttribute(); - - /** @var Varien_Data_Form $form */ - $form = $observer->getForm(); - - // frontend properties fieldset - $fieldset = $form->addFieldset('front_fieldset', ['legend' => Mage::helper('adminhtml')->__('Extra Properties')]); - - $fieldset->addField('use_in_forms', 'multiselect', [ - 'name' => 'use_in_forms', - 'label' => Mage::helper('adminhtml')->__('Use in Forms'), - 'title' => Mage::helper('adminhtml')->__('Use in Forms'), - 'values' => Mage::getModel('customer/config_address_forms')->toOptionArray(), - 'value' => Mage::getResourceModel('customer/form_attribute')->getFormTypesByAttribute($attribute) - ]); - - return $this; - } - - /** - * Save frontend properties from customer address attribute edit form - * - * @param Varien_Event_Observer $observer - * @return $this - */ - public function customerAddressAttributeEditPrepareSave($observer) - { - /** @var Mage_Core_Controller_Request_Http $request */ - $request = $observer->getRequest(); + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + $attribute = $observer->getObject(); $data = $request->getPost(); if ($data) { - /** @var Mage_Eav_Model_Entity_Attribute $model */ - $model = $observer->getObject(); - if (!isset($data['use_in_forms'])) { - $data['use_in_forms'] = []; + $attribute->setData('used_in_forms', []); } - - $model->setData('used_in_forms', $data['use_in_forms']); } + return $this; } } diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index 7b6676c95..0f29b05a3 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -111,19 +111,11 @@ - - - - adminhtml/customer_observer - customerAttributeEditGenerateBlocksAfter - - - adminhtml/customer_observer - customerAttributeEditPrepareForm + attributeEditPrepareForm @@ -131,7 +123,7 @@ adminhtml/customer_observer - customerAttributeEditPrepareSave + attributeEditPrepareSave @@ -139,7 +131,7 @@ adminhtml/customer_observer - customerAddressAttributeEditPrepareForm + attributeEditPrepareForm @@ -147,7 +139,7 @@ adminhtml/customer_observer - customerAddressAttributeEditPrepareSave + attributeEditPrepareSave diff --git a/app/code/core/Mage/Customer/Model/Attribute.php b/app/code/core/Mage/Customer/Model/Attribute.php index 5a561b43d..a78f8b408 100644 --- a/app/code/core/Mage/Customer/Model/Attribute.php +++ b/app/code/core/Mage/Customer/Model/Attribute.php @@ -54,4 +54,31 @@ protected function _construct() { $this->_init('customer/attribute'); } + + /** + * Save additional data + * + * @inheritDoc + */ + #[\Override] + protected function _afterSave() + { + $websiteId = (int)$this->getWebsite()->getId(); + $dataFieldPrefix = $websiteId ? 'scope_' : ''; + + // See Mage_Adminhtml_Model_System_Config_Backend_Customer_Show_Customer + if ($this->getData($dataFieldPrefix . 'is_required') !== $this->getOrigData($dataFieldPrefix . 'is_required') + || $this->getData($dataFieldPrefix . 'is_visible') !== $this->getOrigData($dataFieldPrefix . 'is_visible') + ) { + $code = $this->getAttributeCode(); + if (in_array($code, ['prefix', 'middlename', 'lastname'])) { + // Note, with EAV editor it is possible to have different values for customer vs customer address + // TODO: sync value with customer_address + } + if (in_array($code, ['prefix', 'middlename', 'lastname', 'dob', 'taxvat', 'gender'])) { + // TODO: sync these values back to core_config, e.g. set 'customer/address/prefix_show' to '', 'opt', or 'req' + } + } + return parent::_afterSave(); + } } diff --git a/app/code/core/Mage/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index 76779c391..4e7d732df 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -446,6 +446,24 @@ + + + + middlename + + + + + + + + middlename + + + + + + 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 e01d26dde..3e190ed93 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 @@ -38,6 +38,26 @@ public function getAttributeObject() return $this->_attribute ?? Mage::registry('entity_attribute'); } + /** + * + * + * @return Mage_Core_Block_Abstract + */ + #[\Override] + protected function _prepareLayout() + { + parent::_prepareLayout(); + + // If entity type has a scoped table, change renderer to allow "Use Default Value" checkbox + if (!Mage::app()->isSingleStoreMode() && $this->getAttributeObject()->getResource()->hasScopeTable()) { + Varien_Data_Form::setFieldsetElementRenderer( + $this->getLayout()->createBlock('eav/adminhtml_attribute_edit_renderer_fieldset_element') + ); + } + + return $this; + } + /** * Preparing default form elements for editing attribute * @@ -54,6 +74,8 @@ protected function _prepareForm() 'method' => 'post' ]); + $form->setDataObject($attributeObject); + $fieldset = $form->addFieldset( 'base_fieldset', ['legend' => Mage::helper('eav')->__('Attribute Properties')] @@ -167,8 +189,21 @@ protected function _prepareForm() 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(); } @@ -181,9 +216,12 @@ protected function _initFormValues() protected function _beforeToHtml() { parent::_beforeToHtml(); + + $form = $this->getForm(); $attributeObject = $this->getAttributeObject(); + + // 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()])) { @@ -195,6 +233,28 @@ protected function _beforeToHtml() } } } + + // 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/Renderer/Fieldset/Element.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Renderer/Fieldset/Element.php new file mode 100644 index 000000000..c58c5635c --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Renderer/Fieldset/Element.php @@ -0,0 +1,89 @@ +setTemplate('eav/attribute/edit/renderer/fieldset/element.phtml'); + } + + /** + * Check "Use default" checkbox display availability + * + * @return bool + */ + protected function canDisplayUseDefault() + { + $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 + * + * @return bool + */ + protected function usedDefault() + { + $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 + * + * @return $this + */ + public function checkFieldDisable() + { + if ($this->canDisplayUseDefault() && $this->usedDefault()) { + $this->getElement()->setDisabled(true); + } + return $this; + } + + /** + * Retrieve label of attribute scope + * + * GLOBAL | WEBSITE + * + * @return string + */ + protected function getScopeLabel() + { + $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/Controller/Adminhtml/Attribute/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php index f5f8b36e4..43d857819 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -62,6 +62,9 @@ public function editAction() $model = Mage::getModel($this->_entityType->getAttributeModel()) ->setEntityTypeId($this->_entityType->getEntityTypeId()); if ($id) { + if ($websiteId = $this->getRequest()->getParam('website')) { + $model->setWebsite($websiteId); + } $model->load($id); if (!$model->getId()) { @@ -84,7 +87,17 @@ public function editAction() // set entered data if was error when we do save $data = Mage::getSingleton('adminhtml/session')->getAttributeData(true); - if (! empty($data)) { + + if (!empty($data)) { + // If website specified, prefix relevant fields in saved data + if ($model->getWebsite() && (int)$model->getWebsite()->getId()) { + foreach ($model->getResource()->getScopeFields($model) as $field) { + if (array_key_exists($field, $data)) { + $data['scope_' . $field] = $data[$field]; + unset($data[$field]); + } + } + } $model->addData($data); } @@ -99,6 +112,16 @@ public function editAction() $this->_addBreadcrumb($item, $item); + // Add website switcher if editing existing attribute and we have a scope table + if (!Mage::app()->isSingleStoreMode()) { + if ($id && $model->getResource()->hasScopeTable()) { + $this->_addLeft( + $this->getLayout()->createBlock('adminhtml/website_switcher') + ->setDefaultWebsiteName($this->__('Default Values')) + ); + } + } + $this->_addLeft($this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tabs')) ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_edit')); @@ -143,7 +166,7 @@ public function validateAction() protected function _filterPostData($data) { if ($data) { - //labels + // labels $data['frontend_label'] = (array) $data['frontend_label']; foreach ($data['frontend_label'] as & $value) { if ($value) { @@ -177,7 +200,7 @@ public function saveAction() $id = $this->getRequest()->getParam('attribute_id'); - //validate attribute_code + // 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'])) { @@ -190,7 +213,7 @@ public function saveAction() } - //validate frontend_input + // 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'); @@ -204,6 +227,9 @@ public function saveAction() } if ($id) { + if ($websiteId = $this->getRequest()->getParam('website')) { + $model->setWebsite($websiteId); + } $model->load($id); if (!$model->getId()) { @@ -249,8 +275,28 @@ public function saveAction() $data['entity_type_id'] = $model->getEntityTypeId(); } - //filter + // filter $data = $this->_filterPostData($data); + + if ($model->getWebsite() && (int)$model->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 ($model->getResource()->getScopeFields($model) as $field) { + if (array_key_exists($field, $data)) { + $data['scope_' . $field] = $data[$field]; + unset($data[$field]); + } + } + } + $model->addData($data); if (!$id) { @@ -258,13 +304,6 @@ public function saveAction() $model->setIsUserDefined(1); } - - if ($this->getRequest()->getParam('set') && $this->getRequest()->getParam('group')) { - // For creating attribute on page we need specify attribute set and group - $model->setAttributeSetId($this->getRequest()->getParam('set')); - $model->setAttributeGroupId($this->getRequest()->getParam('group')); - } - Mage::dispatchEvent( "adminhtml_{$this->_entityCode}_attribute_edit_prepare_save", ['object' => $model, 'request' => $this->getRequest()] diff --git a/app/code/core/Mage/Eav/Model/Attribute.php b/app/code/core/Mage/Eav/Model/Attribute.php index 982b6c014..58c8365eb 100644 --- a/app/code/core/Mage/Eav/Model/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Attribute.php @@ -137,6 +137,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/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Entity/Attribute.php index 38f2c2ac7..e9e840b76 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute.php @@ -31,6 +31,10 @@ */ class Mage_Eav_Model_Entity_Attribute extends Mage_Eav_Model_Entity_Attribute_Abstract { + public const SCOPE_STORE = 0; + public const SCOPE_GLOBAL = 1; + public const SCOPE_WEBSITE = 2; + /** * Prefix of model events names * diff --git a/app/code/core/Mage/Eav/Model/Resource/Attribute.php b/app/code/core/Mage/Eav/Model/Resource/Attribute.php index 0a7e6a026..1f35e2367 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Attribute.php @@ -69,9 +69,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( @@ -127,7 +125,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); @@ -135,11 +132,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; } @@ -150,6 +145,38 @@ 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 + */ + 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 * 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 a535e188c..9c6b1ac43 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php @@ -551,4 +551,14 @@ public function getValidAttributeIds($attributeIds) return $adapter->fetchCol($select); } + + /** + * Check if we have a scope table for attribute + * + * @return bool + */ + public function hasScopeTable() + { + return false; + } } diff --git a/app/design/adminhtml/default/default/template/eav/attribute/edit/renderer/fieldset/element.phtml b/app/design/adminhtml/default/default/template/eav/attribute/edit/renderer/fieldset/element.phtml new file mode 100644 index 000000000..abad56268 --- /dev/null +++ b/app/design/adminhtml/default/default/template/eav/attribute/edit/renderer/fieldset/element.phtml @@ -0,0 +1,44 @@ + +getElement(); +$_note = $_element->getNote(); +$_trId = $_element->getHtmlContainerId(); +$_class = $_element->getFieldsetHtmlClass(); + +$this->checkFieldDisable(); +$elementToggleCode = $_element->getToggleCode() ? $_element->getToggleCode() + : 'toggleValueElements(this, this.parentNode.parentNode)'; +?> +getNoDisplay()): ?> + id=""> + getType()=='hidden'): ?> + getElementHtml()) ?> + + ">getLabelHtml()) ?> + "> + getElementHtml()) ?> + +

    " id="note_getId() ?>">

    + + + getScopeLabel() ?> + canDisplayUseDefault()): ?> + + getReadonly()):?> disabled="disabled" type="checkbox" name="use_default[]" id="getHtmlId() ?>_default"usedDefault()): ?> checked="checked" onclick="" value="getName() ?>"/> + + + + + + From aea7bdeb14b01b322cf12b013d56bc41fb18b330 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Fri, 27 Sep 2024 16:59:28 -0700 Subject: [PATCH 024/113] phpstan --- .../core/Mage/Eav/Model/Resource/Entity/Attribute.php | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 9c6b1ac43..f2f5b0663 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php @@ -561,4 +561,14 @@ public function hasScopeTable() { return false; } + + /** + * Return scoped fields for attribute + * + * @return array + */ + public function getScopeFields(Mage_Eav_Model_Attribute $object) + { + return []; + } } From 45572a0ac62c837ae90021554a9f85cb2f0fa7bf Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Sat, 28 Sep 2024 11:19:59 +0100 Subject: [PATCH 025/113] Rector --- app/code/core/Mage/Eav/Model/Resource/Attribute.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/core/Mage/Eav/Model/Resource/Attribute.php b/app/code/core/Mage/Eav/Model/Resource/Attribute.php index 1f35e2367..504109157 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Attribute.php @@ -161,6 +161,7 @@ public function hasScopeTable() * * @return array */ + #[\Override] public function getScopeFields(Mage_Eav_Model_Attribute $object) { if (!$this->hasScopeTable()) { From 5c63c64f72a5b129739c8f5b0f88c7b13f4faf66 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 28 Sep 2024 05:15:22 -0700 Subject: [PATCH 026/113] Fix use_in_forms --- app/code/core/Mage/Adminhtml/Model/Customer/Observer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index dcd9aa457..db207f5bc 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -63,8 +63,9 @@ public function attributeEditPrepareSave($observer) $data = $request->getPost(); if ($data) { if (!isset($data['use_in_forms'])) { - $attribute->setData('used_in_forms', []); + $data['use_in_forms'] = []; } + $attribute->setData('used_in_forms', $data['use_in_forms']); } return $this; From 2faf08e68684d5150764e9d93660fe3b23fd2bd8 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 28 Sep 2024 06:45:17 -0700 Subject: [PATCH 027/113] fixes --- app/code/core/Mage/Adminhtml/Model/Customer/Observer.php | 8 +++++--- app/code/core/Mage/Customer/Block/Form/Register.php | 8 +++++++- .../template/persistent/customer/form/register.phtml | 8 ++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index db207f5bc..1d71a9692 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -62,10 +62,12 @@ public function attributeEditPrepareSave($observer) $data = $request->getPost(); if ($data) { - if (!isset($data['use_in_forms'])) { - $data['use_in_forms'] = []; + if (!$attribute->getWebsite()->getId()) { + if (!isset($data['use_in_forms'])) { + $data['use_in_forms'] = []; + } + $attribute->setData('used_in_forms', $data['use_in_forms']); } - $attribute->setData('used_in_forms', $data['use_in_forms']); } return $this; diff --git a/app/code/core/Mage/Customer/Block/Form/Register.php b/app/code/core/Mage/Customer/Block/Form/Register.php index d345ca48c..089e27cfe 100644 --- a/app/code/core/Mage/Customer/Block/Form/Register.php +++ b/app/code/core/Mage/Customer/Block/Form/Register.php @@ -186,11 +186,17 @@ public function getMinPasswordLength() */ public function extraFields() { + /** @var Mage_Customer_Model_Customer $customer */ + $customer = Mage::getModel('customer/customer'); + /** @var Mage_Customer_Model_Form $form */ $form = Mage::getModel('customer/form'); - $form->setFormCode('customer_account_create'); + $form->setFormCode('customer_account_create') + ->setEntity($customer) + ->initDefaultValues(); $attributes = $form->getAttributes(); + foreach ($attributes as $code => $attribute) { if (!$attribute->getIsUserDefined()) { unset($attributes[$code]); diff --git a/app/design/frontend/rwd/default/template/persistent/customer/form/register.phtml b/app/design/frontend/rwd/default/template/persistent/customer/form/register.phtml index 37fe36409..889d39f45 100644 --- a/app/design/frontend/rwd/default/template/persistent/customer/form/register.phtml +++ b/app/design/frontend/rwd/default/template/persistent/customer/form/register.phtml @@ -54,6 +54,14 @@
  • setGender($this->getFormData()->getGender())->toHtml() ?>
  • + extraFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> + isEnabled()): ?> +
  • setObject($this->getFormData())->toHtml() ?>
  • + + + getShowAddressFields()): ?>
  • setGender($this->getFormData()->getGender())->toHtml() ?>
  • + + extraFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> + isEnabled()): ?> +
  • setObject($this->getFormData())->toHtml() ?>
  • + + +
    getShowAddressFields()): ?> From 86cf0c5721e967a587900b9ea3a988eab594f769 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 28 Sep 2024 09:20:59 -0700 Subject: [PATCH 031/113] add install script --- app/code/core/Mage/Customer/etc/config.xml | 2 +- .../upgrade-1.6.2.0.7-1.6.2.0.8.php | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/code/core/Mage/Customer/sql/customer_setup/upgrade-1.6.2.0.7-1.6.2.0.8.php diff --git a/app/code/core/Mage/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index 642f72314..9c852db27 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -13,7 +13,7 @@ - 1.6.2.0.7 + 1.6.2.0.8 diff --git a/app/code/core/Mage/Customer/sql/customer_setup/upgrade-1.6.2.0.7-1.6.2.0.8.php b/app/code/core/Mage/Customer/sql/customer_setup/upgrade-1.6.2.0.7-1.6.2.0.8.php new file mode 100644 index 000000000..158bb0ba3 --- /dev/null +++ b/app/code/core/Mage/Customer/sql/customer_setup/upgrade-1.6.2.0.7-1.6.2.0.8.php @@ -0,0 +1,33 @@ +startSetup(); + +$installer->getConnection() + ->addColumn($installer->getTable('customer/customer_group'), 'customer_attribute_set_id', [ + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => 0, + 'comment' => 'Customer Group Attribute Set ID', + ]); + +$installer->getConnection() + ->addColumn($installer->getTable('customer/customer_group'), 'customer_address_attribute_set_id', [ + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => 0, + 'comment' => 'Customer Group Address Attribute Set ID', + ]); + +$installer->endSetup(); From b6e792bddaaaf121cd2617d75efae8013828cc57 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 28 Sep 2024 10:38:02 -0700 Subject: [PATCH 032/113] Support custom form types via config.xml See: https://github.com/OpenMage/magento-lts/pull/2352#pullrequestreview-1058955635 --- .../Adminhtml/Model/Customer/Observer.php | 3 +- .../Customer/Model/Config/Address/Forms.php | 50 ---------------- .../core/Mage/Customer/Model/Config/Forms.php | 58 ------------------- app/code/core/Mage/Customer/etc/config.xml | 30 ++++++++++ .../Mage/Eav/Model/Config/Source/Form.php | 47 +++++++++++++++ 5 files changed, 79 insertions(+), 109 deletions(-) delete mode 100644 app/code/core/Mage/Customer/Model/Config/Address/Forms.php delete mode 100644 app/code/core/Mage/Customer/Model/Config/Forms.php create mode 100644 app/code/core/Mage/Eav/Model/Config/Source/Form.php diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index 1d71a9692..dc93f54d5 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -28,6 +28,7 @@ public function attributeEditPrepareForm($observer) { /** @var Mage_Customer_Model_Attribute $attribute */ $attribute = $observer->getAttribute(); + $attributeTypeCode = $attribute->getEntityType()->getEntityTypeCode(); /** @var Varien_Data_Form $form */ $form = $observer->getForm(); @@ -39,7 +40,7 @@ public function attributeEditPrepareForm($observer) 'name' => 'use_in_forms', 'label' => Mage::helper('adminhtml')->__('Use in Forms'), 'title' => Mage::helper('adminhtml')->__('Use in Forms'), - 'values' => Mage::getModel('customer/config_forms')->toOptionArray(), + 'values' => Mage::getModel('eav/config_source_form')->toOptionArray($attributeTypeCode), 'value' => Mage::getResourceModel('customer/form_attribute')->getFormTypesByAttribute($attribute) ]); diff --git a/app/code/core/Mage/Customer/Model/Config/Address/Forms.php b/app/code/core/Mage/Customer/Model/Config/Address/Forms.php deleted file mode 100644 index 4ae39df47..000000000 --- a/app/code/core/Mage/Customer/Model/Config/Address/Forms.php +++ /dev/null @@ -1,50 +0,0 @@ - 'adminhtml_customer_address', - 'label' => Mage::helper('customer')->__('Adminhtml Customer Address') - ], - [ - 'value' => 'customer_address_edit', - 'label' => Mage::helper('customer')->__('Customer Address Edit') - ], - [ - 'value' => 'customer_register_address', - 'label' => Mage::helper('customer')->__('Customer Register Address') - ], - ]; - } - - /** - * Get options in "key-value" format - * - * @return array - */ - public function toOptionHash() - { - return array_combine( - array_column($this->toOptionArray(), 'value'), - array_column($this->toOptionArray(), 'label') - ); - } -} diff --git a/app/code/core/Mage/Customer/Model/Config/Forms.php b/app/code/core/Mage/Customer/Model/Config/Forms.php deleted file mode 100644 index d977f952b..000000000 --- a/app/code/core/Mage/Customer/Model/Config/Forms.php +++ /dev/null @@ -1,58 +0,0 @@ - 'adminhtml_checkout', - 'label' => Mage::helper('customer')->__('Adminhtml Checkout') - ], - [ - 'value' => 'adminhtml_customer', - 'label' => Mage::helper('customer')->__('Adminhtml Customer') - ], - [ - 'value' => 'checkout_register', - 'label' => Mage::helper('customer')->__('Checkout Register') - ], - [ - 'value' => 'customer_account_create', - 'label' => Mage::helper('customer')->__('Customer Account Create') - ], - [ - 'value' => 'customer_account_edit', - 'label' => Mage::helper('customer')->__('Customer Account Edit') - ], - ]; - } - - /** - * Get options in "key-value" format - * - * @return array - */ - public function toOptionHash() - { - return array_combine( - array_column($this->toOptionArray(), 'value'), - array_column($this->toOptionArray(), 'label') - ); - } -} diff --git a/app/code/core/Mage/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index 9c852db27..1948b8533 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -446,6 +446,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/core/Mage/Eav/Model/Config/Source/Form.php b/app/code/core/Mage/Eav/Model/Config/Source/Form.php new file mode 100644 index 000000000..d2d6f2e4e --- /dev/null +++ b/app/code/core/Mage/Eav/Model/Config/Source/Form.php @@ -0,0 +1,47 @@ +getNode(self::XML_PATH_EAV_FORMS . '/' . $entity); + if ($node === false) { + return []; + } + foreach ($node->children() as $form) { + $moduleName = $form->getAttribute('module') ?? 'eav'; + $translatedLabel = Mage::helper($moduleName)->__((string)$form->label[0]); + $forms[] = [ + 'label' => $translatedLabel, + 'value' => $form->getName() + ]; + } + return $forms; + } + + public function toOptionHash(string $entity = ''): array + { + $optionArray = $this->toOptionArray($entity); + return array_combine( + array_column($optionArray, 'value'), + array_column($optionArray, 'label') + ); + } +} From 857709e7a774dea025cbff998bd39ae7410423de Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Sat, 28 Sep 2024 20:46:44 +0100 Subject: [PATCH 033/113] PHPStan --- app/code/core/Mage/Eav/Model/Config/Source/Form.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/core/Mage/Eav/Model/Config/Source/Form.php b/app/code/core/Mage/Eav/Model/Config/Source/Form.php index d2d6f2e4e..e82beb951 100644 --- a/app/code/core/Mage/Eav/Model/Config/Source/Form.php +++ b/app/code/core/Mage/Eav/Model/Config/Source/Form.php @@ -25,6 +25,8 @@ public function toOptionArray(string $entity = ''): array if ($node === false) { return []; } + + $forms = []; foreach ($node->children() as $form) { $moduleName = $form->getAttribute('module') ?? 'eav'; $translatedLabel = Mage::helper($moduleName)->__((string)$form->label[0]); From e4f3862aa5878914ecad1354e1cbc3c22e1853fe Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Sat, 28 Sep 2024 21:28:39 +0100 Subject: [PATCH 034/113] Fixed docblock --- .phpstan.baseline.neon | 5 ----- app/code/core/Mage/Core/Model/Config.php | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.phpstan.baseline.neon b/.phpstan.baseline.neon index a9d6d4f79..a96f018af 100644 --- a/.phpstan.baseline.neon +++ b/.phpstan.baseline.neon @@ -2160,11 +2160,6 @@ parameters: count: 1 path: app/code/core/Mage/Core/Model/Config.php - - - message: "#^Method Mage_Core_Model_Config\\:\\:getNode\\(\\) should return Mage_Core_Model_Config_Element but returns Varien_Simplexml_Element\\|false\\.$#" - count: 1 - path: app/code/core/Mage/Core/Model/Config.php - - message: "#^Return type \\(Mage_Core_Model_App\\) of method Mage_Core_Model_Config\\:\\:_saveCache\\(\\) should be compatible with return type \\(bool\\) of method Varien_Simplexml_Config\\:\\:_saveCache\\(\\)$#" count: 1 diff --git a/app/code/core/Mage/Core/Model/Config.php b/app/code/core/Mage/Core/Model/Config.php index 05cc41581..9c67c9282 100644 --- a/app/code/core/Mage/Core/Model/Config.php +++ b/app/code/core/Mage/Core/Model/Config.php @@ -757,7 +757,7 @@ public function getSectionNode($path) * Returns node found by the $path and scope info * * @inheritDoc - * @return Mage_Core_Model_Config_Element + * @return Mage_Core_Model_Config_Element|false */ #[\Override] public function getNode($path = null, $scope = '', $scopeCode = null) From 8d94b5d518ed839b4be449ba2458ea5ab14b2ce7 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 28 Sep 2024 15:01:34 -0700 Subject: [PATCH 035/113] Generic EAV used_in_forms code --- .../Adminhtml/Model/Customer/Observer.php | 76 ------------------- app/code/core/Mage/Adminhtml/etc/config.xml | 32 -------- .../Attribute/Edit/Main/Abstract.php | 15 ++++ .../Adminhtml/Attribute/Abstract.php | 7 ++ .../Mage/Eav/Model/Config/Source/Form.php | 2 +- .../Mage/Eav/Model/Resource/Attribute.php | 11 +++ .../Eav/Model/Resource/Entity/Attribute.php | 10 +++ 7 files changed, 44 insertions(+), 109 deletions(-) delete mode 100644 app/code/core/Mage/Adminhtml/Model/Customer/Observer.php diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php deleted file mode 100644 index dc93f54d5..000000000 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ /dev/null @@ -1,76 +0,0 @@ -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('use_in_forms', 'multiselect', [ - 'name' => 'use_in_forms', - 'label' => Mage::helper('adminhtml')->__('Use in Forms'), - 'title' => Mage::helper('adminhtml')->__('Use in Forms'), - 'values' => Mage::getModel('eav/config_source_form')->toOptionArray($attributeTypeCode), - 'value' => Mage::getResourceModel('customer/form_attribute')->getFormTypesByAttribute($attribute) - ]); - - return $this; - } - - /** - * Save extra properties from customer and customer_address attribute edit forms - * - * @param Varien_Event_Observer $observer - * @return $this - */ - public function attributeEditPrepareSave($observer) - { - /** @var Mage_Core_Controller_Request_Http $request */ - $request = $observer->getRequest(); - - /** @var Mage_Eav_Model_Entity_Attribute $attribute */ - $attribute = $observer->getObject(); - - $data = $request->getPost(); - if ($data) { - if (!$attribute->getWebsite()->getId()) { - if (!isset($data['use_in_forms'])) { - $data['use_in_forms'] = []; - } - $attribute->setData('used_in_forms', $data['use_in_forms']); - } - } - - return $this; - } -} diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index 6a538bacb..b9715916c 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -111,38 +111,6 @@ - - - - adminhtml/customer_observer - attributeEditPrepareForm - - - - - - - adminhtml/customer_observer - attributeEditPrepareSave - - - - - - - adminhtml/customer_observer - attributeEditPrepareForm - - - - - - - adminhtml/customer_observer - attributeEditPrepareSave - - - 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 a0a37b023..3da74c660 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 @@ -166,6 +166,21 @@ protected function _prepareForm() 'values' => Mage::helper('eav')->getFrontendClasses($attributeObject->getEntityType()->getEntityTypeCode()) ]); + if ($attributeObject->getResource()->hasFormTable()) { + /** @var Mage_Eav_Model_Resource_Form_Attribute $resourceModel */ + $resourceModel = Mage::getResourceModel(strstr($attributeObject->getResourceName(), '/', true) . '/form_attribute'); + if ($resourceModel) { + $attributeObjectTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); + $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::getModel('eav/config_source_form')->toOptionArray($attributeObjectTypeCode), + 'value' => $resourceModel->getFormTypesByAttribute($attributeObject) + ]); + } + } + if ($attributeObject->getId()) { $form->getElement('attribute_code')->setDisabled(1); $form->getElement('frontend_input')->setDisabled(1); diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php index 43d857819..e9fc80bd1 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -295,6 +295,13 @@ public function saveAction() unset($data[$field]); } } + } else { + // Check for no forms selected and set to empty array + if ($model->getResource()->hasFormTable()) { + if (!isset($data['used_in_forms'])) { + $data['used_in_forms'] = []; + } + } } $model->addData($data); diff --git a/app/code/core/Mage/Eav/Model/Config/Source/Form.php b/app/code/core/Mage/Eav/Model/Config/Source/Form.php index e82beb951..a28272b73 100644 --- a/app/code/core/Mage/Eav/Model/Config/Source/Form.php +++ b/app/code/core/Mage/Eav/Model/Config/Source/Form.php @@ -10,7 +10,7 @@ */ /** - * Used in creating options for use_in_forms selection + * Used in creating options for used_in_forms selection * * @category Mage * @package Mage_Eav diff --git a/app/code/core/Mage/Eav/Model/Resource/Attribute.php b/app/code/core/Mage/Eav/Model/Resource/Attribute.php index 504109157..18b3feb9f 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Attribute.php @@ -204,6 +204,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/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php index f2f5b0663..e3a267c89 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Entity/Attribute.php @@ -571,4 +571,14 @@ 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; + } } From 81a2fafd1d11770a9ca76e66a77d5267b431d4a4 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sun, 29 Sep 2024 05:14:31 -0700 Subject: [PATCH 036/113] Remove new function getFormTypesByAttribute See: https://github.com/OpenMage/magento-lts/pull/2352#pullrequestreview-1061097301 --- .../Attribute/Edit/Main/Abstract.php | 20 +++++++--------- .../Eav/Model/Resource/Form/Attribute.php | 23 ------------------- 2 files changed, 8 insertions(+), 35 deletions(-) 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 3da74c660..c5223770b 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 @@ -167,18 +167,14 @@ protected function _prepareForm() ]); if ($attributeObject->getResource()->hasFormTable()) { - /** @var Mage_Eav_Model_Resource_Form_Attribute $resourceModel */ - $resourceModel = Mage::getResourceModel(strstr($attributeObject->getResourceName(), '/', true) . '/form_attribute'); - if ($resourceModel) { - $attributeObjectTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); - $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::getModel('eav/config_source_form')->toOptionArray($attributeObjectTypeCode), - 'value' => $resourceModel->getFormTypesByAttribute($attributeObject) - ]); - } + $attributeObjectTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); + $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::getModel('eav/config_source_form')->toOptionArray($attributeObjectTypeCode), + 'value' => $attributeObject->getUsedInForms(), + ]); } if ($attributeObject->getId()) { diff --git a/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php b/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php index fa811db60..3dce32e79 100644 --- a/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Resource/Form/Attribute.php @@ -32,27 +32,4 @@ public function getFormAttributeIds($formCode) return $this->_getReadAdapter()->fetchCol($select, $bind); } - - /** - * Retrieve form type filtered by given attribute - * - * @param Mage_Eav_Model_Entity_Attribute_Abstract|int $attribute - * @return array - */ - public function getFormTypesByAttribute($attribute) - { - if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { - $attribute = $attribute->getId(); - } - if (!$attribute) { - return []; - } - - $bind = ['attribute_id' => $attribute]; - $select = $this->_getReadAdapter()->select() - ->from($this->getMainTable(), 'form_code') - ->where('attribute_id = :attribute_id'); - - return $this->_getReadAdapter()->fetchCol($select, $bind); - } } From 2ea282a32267c49fa301128263233c00580f6b4e Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 2 Oct 2024 16:00:58 -0700 Subject: [PATCH 037/113] Fixes, possibly broke something else, WIP --- .../Mage/Checkout/Block/Onepage/Billing.php | 28 +++++++--------- .../core/Mage/Checkout/Model/Type/Onepage.php | 2 ++ .../core/Mage/Customer/Block/Address/Edit.php | 22 ++----------- .../core/Mage/Customer/Block/Form/Edit.php | 22 ++----------- .../Mage/Customer/Block/Form/Register.php | 23 ++----------- .../core/Mage/Customer/Helper/Address.php | 32 +++++++++++++++++++ app/code/core/Mage/Customer/Helper/Data.php | 25 +++++++++++++++ app/code/core/Mage/Customer/etc/config.xml | 3 ++ .../template/checkout/onepage/billing.phtml | 11 ++++++- .../template/customer/address/edit.phtml | 12 +++++++ .../default/template/customer/form/edit.phtml | 2 +- .../template/customer/form/register.phtml | 2 +- .../template/customer/address/edit.phtml | 2 +- .../default/template/customer/form/edit.phtml | 2 +- 14 files changed, 105 insertions(+), 83 deletions(-) diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Billing.php b/app/code/core/Mage/Checkout/Block/Onepage/Billing.php index c169b532d..4db3d11a5 100644 --- a/app/code/core/Mage/Checkout/Block/Onepage/Billing.php +++ b/app/code/core/Mage/Checkout/Block/Onepage/Billing.php @@ -207,32 +207,26 @@ public function getTaxvatHtml() /** * Return extra EAV fields used in this form - * - * @return array */ - public function extraFields() + public function getExtraCustomerFields(): array { - /** @var Mage_Customer_Model_Form $form */ - $form = Mage::getModel('customer/form'); - $form->setFormCode('checkout_register'); - - $attributes = $form->getAttributes(); - foreach ($attributes as $code => $attribute) { - if (!$attribute->getIsUserDefined()) { - unset($attributes[$code]); - } - } + return Mage::helper('customer')->getExtraFields('checkout_register'); + } - return $attributes; + /** + * Return extra EAV fields used in this form + */ + public function getExtraCustomerAddressFields(): array + { + return Mage::helper('customer/address')->getExtraFields('checkout_address_create'); } /** * Return extra EAV fields from incomplete checkout session - * - * @return Varien_Object */ - public function getExtraFieldsSession() + public function getExtraFieldsSession(): Varien_Object { + // TODO, need to separate from customer and customer address return new Varien_Object($this->getCheckout()->getExtraFields()); } } diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index aab64ca38..f07d874d3 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -414,6 +414,7 @@ protected function _validateCustomerData(array $data) $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) { @@ -720,6 +721,7 @@ 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(); diff --git a/app/code/core/Mage/Customer/Block/Address/Edit.php b/app/code/core/Mage/Customer/Block/Address/Edit.php index 85a4ea64e..73bef909b 100644 --- a/app/code/core/Mage/Customer/Block/Address/Edit.php +++ b/app/code/core/Mage/Customer/Block/Address/Edit.php @@ -214,27 +214,9 @@ public function getBackButtonUrl() /** * Return extra EAV fields used in this form - * - * @return array */ - public function extraFields() + public function getExtraFields(): array { - /** @var Mage_Customer_Model_Customer $customer */ - $customer = $this->getCustomer(); - - /** @var Mage_Customer_Model_Form $form */ - $form = Mage::getModel('customer/form'); - $form->setFormCode('customer_address_edit') - ->setEntity($this->getAddress()) - ->initDefaultValues(); - - $attributes = $form->getAttributes(); - foreach ($attributes as $code => $attribute) { - if (!$attribute->getIsUserDefined()) { - unset($attributes[$code]); - } - } - - return $attributes; + return Mage::helper('customer/address')->getExtraFields('checkout_address_create', $this->getAddress()); } } diff --git a/app/code/core/Mage/Customer/Block/Form/Edit.php b/app/code/core/Mage/Customer/Block/Form/Edit.php index 50838a1d7..24862c9de 100644 --- a/app/code/core/Mage/Customer/Block/Form/Edit.php +++ b/app/code/core/Mage/Customer/Block/Form/Edit.php @@ -19,27 +19,9 @@ class Mage_Customer_Block_Form_Edit extends Mage_Customer_Block_Account_Dashboar { /** * Return extra EAV fields used in this form - * - * @return array */ - public function extraFields() + public function getExtraFields(): array { - /** @var Mage_Customer_Model_Customer $customer */ - $customer = $this->getCustomer(); - - /** @var Mage_Customer_Model_Form $form */ - $form = Mage::getModel('customer/form'); - $form->setFormCode('customer_account_edit') - ->setEntity($customer) - ->initDefaultValues(); - - $attributes = $form->getAttributes(); - foreach ($attributes as $code => $attribute) { - if (!$attribute->getIsUserDefined()) { - unset($attributes[$code]); - } - } - - return $attributes; + return Mage::helper('customer')->getExtraFields('customer_account_edit'); } } diff --git a/app/code/core/Mage/Customer/Block/Form/Register.php b/app/code/core/Mage/Customer/Block/Form/Register.php index 089e27cfe..8f061580e 100644 --- a/app/code/core/Mage/Customer/Block/Form/Register.php +++ b/app/code/core/Mage/Customer/Block/Form/Register.php @@ -181,28 +181,9 @@ public function getMinPasswordLength() /** * Return extra EAV fields used in this form - * - * @return array */ - public function extraFields() + public function getExtraFields(): array { - /** @var Mage_Customer_Model_Customer $customer */ - $customer = Mage::getModel('customer/customer'); - - /** @var Mage_Customer_Model_Form $form */ - $form = Mage::getModel('customer/form'); - $form->setFormCode('customer_account_create') - ->setEntity($customer) - ->initDefaultValues(); - - $attributes = $form->getAttributes(); - - foreach ($attributes as $code => $attribute) { - if (!$attribute->getIsUserDefined()) { - unset($attributes[$code]); - } - } - - return $attributes; + return Mage::helper('customer')->getExtraFields('customer_account_create'); } } diff --git a/app/code/core/Mage/Customer/Helper/Address.php b/app/code/core/Mage/Customer/Helper/Address.php index 8fe3c309c..8bf48e5c1 100644 --- a/app/code/core/Mage/Customer/Helper/Address.php +++ b/app/code/core/Mage/Customer/Helper/Address.php @@ -277,4 +277,36 @@ public function isVatAttributeVisible() { return Mage::getStoreConfigFlag(self::XML_PATH_VAT_FRONTEND_VISIBILITY); } + + /** + * Return extra EAV fields used in customer address forms + */ + public function getExtraFields(string $formCode, Mage_Customer_Model_Address|int $addressId = null): array + { + if ($addressId instanceof Mage_Customer_Model_Address) { + $address = $addressId; + } else if (is_int($addressId)) { + /** @var Mage_Customer_Model_Customer $customer */ + $customer = Mage::getModel('customer/customer'); + $address = $customer->getAddressById($addressId); + } else { + $address = Mage::getModel('customer/address'); + } + + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode($formCode) + ->setEntity($address) + ->initDefaultValues(); + + $attributes = $form->getAttributes(); + + foreach ($attributes as $code => $attribute) { + if (!$attribute->getIsUserDefined()) { + unset($attributes[$code]); + } + } + + return $attributes; + } } diff --git a/app/code/core/Mage/Customer/Helper/Data.php b/app/code/core/Mage/Customer/Helper/Data.php index 25c3168e9..f409e4236 100644 --- a/app/code/core/Mage/Customer/Helper/Data.php +++ b/app/code/core/Mage/Customer/Helper/Data.php @@ -742,4 +742,29 @@ protected function _getCountryCodeForVatNumber(string $countryCode): string return $countryCode === 'GR' ? 'EL' : $countryCode; } + + /** + * Return extra EAV fields used in customer forms + */ + public function getExtraFields(string $formCode): array + { + /** @var Mage_Customer_Model_Customer $customer */ + $customer = Mage::getModel('customer/customer'); + + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode($formCode) + ->setEntity($customer) + ->initDefaultValues(); + + $attributes = $form->getAttributes(); + + foreach ($attributes as $code => $attribute) { + if (!$attribute->getIsUserDefined()) { + unset($attributes[$code]); + } + } + + return $attributes; + } } diff --git a/app/code/core/Mage/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index 1948b8533..5f8853ee1 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -468,6 +468,9 @@ + + + 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 42e8489c5..30d16ee3a 100644 --- a/app/design/frontend/base/default/template/checkout/onepage/billing.phtml +++ b/app/design/frontend/base/default/template/checkout/onepage/billing.phtml @@ -118,6 +118,15 @@ + + getExtraCustomerAddressFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute)->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]') ?> + isEnabled()): ?> +
  • setObject($this->getExtraFieldsSession())->toHtml() ?>
  • + + + isCustomerLoggedIn()): ?> getLayout()->createBlock('customer/widget_dob') ?> @@ -141,7 +150,7 @@
  • getTaxvatHtml() ?>
  • - extraFields() as $_code => $_attribute): ?> + getExtraCustomerFields() as $_code => $_attribute): ?> getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute)->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]') ?> isEnabled()): ?> 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 f4ba950b8..7b1b9d234 100644 --- a/app/design/frontend/base/default/template/customer/address/edit.phtml +++ b/app/design/frontend/base/default/template/customer/address/edit.phtml @@ -137,6 +137,18 @@ +
    +

    __('Other') ?>

    +
      + getExtraFields() as $_code => $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> + isEnabled()): ?> +
    • setObject($this->getAddress())->toHtml() ?>
    • + + +
    +

    __('* 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 834e734d7..ac9cbc8cf 100644 --- a/app/design/frontend/base/default/template/customer/form/edit.phtml +++ b/app/design/frontend/base/default/template/customer/form/edit.phtml @@ -41,7 +41,7 @@
  • setGender($this->getCustomer()->getGender())->toHtml() ?>
  • - extraFields() as $_code => $_attribute): ?> + getExtraFields() as $_code => $_attribute): ?> getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> isEnabled()): ?> diff --git a/app/design/frontend/base/default/template/customer/form/register.phtml b/app/design/frontend/base/default/template/customer/form/register.phtml index a5a41e165..820608d4e 100644 --- a/app/design/frontend/base/default/template/customer/form/register.phtml +++ b/app/design/frontend/base/default/template/customer/form/register.phtml @@ -65,7 +65,7 @@
  • setGender($this->getFormData()->getGender())->toHtml() ?>
  • - extraFields() as $_code => $_attribute): ?> + getExtraFields() as $_code => $_attribute): ?> getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> isEnabled()): ?> diff --git a/app/design/frontend/rwd/default/template/customer/address/edit.phtml b/app/design/frontend/rwd/default/template/customer/address/edit.phtml index db064acb6..ed3e8f90f 100644 --- a/app/design/frontend/rwd/default/template/customer/address/edit.phtml +++ b/app/design/frontend/rwd/default/template/customer/address/edit.phtml @@ -142,7 +142,7 @@

    __('Other') ?>

      - extraFields() as $_code => $_attribute): ?> + getExtraFields() as $_code => $_attribute): ?> getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> isEnabled()): ?> diff --git a/app/design/frontend/rwd/default/template/customer/form/edit.phtml b/app/design/frontend/rwd/default/template/customer/form/edit.phtml index 63f0ba76a..9bb27285b 100644 --- a/app/design/frontend/rwd/default/template/customer/form/edit.phtml +++ b/app/design/frontend/rwd/default/template/customer/form/edit.phtml @@ -42,7 +42,7 @@
    • setGender($this->getCustomer()->getGender())->toHtml() ?>
    • - extraFields() as $_code => $_attribute): ?> + getExtraFields() as $_code => $_attribute): ?> getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> isEnabled()): ?> From d2b6331fa6673e75b574238592c7b764584f0d2f Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Mon, 14 Oct 2024 10:48:52 -0700 Subject: [PATCH 038/113] phpcs --- app/code/core/Mage/Customer/Helper/Address.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/Customer/Helper/Address.php b/app/code/core/Mage/Customer/Helper/Address.php index 8bf48e5c1..4da264ee5 100644 --- a/app/code/core/Mage/Customer/Helper/Address.php +++ b/app/code/core/Mage/Customer/Helper/Address.php @@ -281,11 +281,11 @@ public function isVatAttributeVisible() /** * Return extra EAV fields used in customer address forms */ - public function getExtraFields(string $formCode, Mage_Customer_Model_Address|int $addressId = null): array + public function getExtraFields(string $formCode, Mage_Customer_Model_Address|int|null $addressId = null): array { if ($addressId instanceof Mage_Customer_Model_Address) { $address = $addressId; - } else if (is_int($addressId)) { + } elseif (is_int($addressId)) { /** @var Mage_Customer_Model_Customer $customer */ $customer = Mage::getModel('customer/customer'); $address = $customer->getAddressById($addressId); From 53c61dbbcdfa9bab927228a988ad075f45f4cd70 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Mon, 14 Oct 2024 10:57:23 -0700 Subject: [PATCH 039/113] revert .phpstan.baseline.neon --- .phpstan.baseline.neon | 192 +---------------------------------------- 1 file changed, 1 insertion(+), 191 deletions(-) diff --git a/.phpstan.baseline.neon b/.phpstan.baseline.neon index f9babdf4c..7c7bfc6f9 100644 --- a/.phpstan.baseline.neon +++ b/.phpstan.baseline.neon @@ -70,21 +70,6 @@ parameters: count: 1 path: app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Settings.php - - - message: "#^Call to an undefined method Mage_Eav_Model_Entity_Attribute\\:\\:isScopeGlobal\\(\\)\\.$#" - count: 2 - path: app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php - - - - message: "#^Call to an undefined method Mage_Eav_Model_Entity_Attribute\\:\\:isScopeStore\\(\\)\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php - - - - message: "#^Call to an undefined method Mage_Eav_Model_Entity_Attribute\\:\\:isScopeWebsite\\(\\)\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery.php - - message: "#^Property Mage_Adminhtml_Block_Customer_Edit_Tab_View_Sales\\:\\:\\$_collection \\(Mage_Sales_Model_Entity_Sale_Collection\\) does not accept Varien_Data_Collection_Db\\.$#" count: 1 @@ -105,36 +90,6 @@ parameters: count: 1 path: app/code/core/Mage/Adminhtml/Block/Customer/Sales/Order/Address/Form/Renderer/Vat.php - - - message: "#^Variable \\$d might not be defined\\.$#" - count: 2 - path: app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php - - - - message: "#^Variable \\$localmaxlength might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php - - - - message: "#^Variable \\$localmaxvalue might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php - - - - message: "#^Variable \\$localminvalue might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php - - - - message: "#^Variable \\$class might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Severity.php - - - - message: "#^Variable \\$value might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Notification/Grid/Renderer/Severity.php - - message: "#^Access to an undefined property Mage_Adminhtml_Block_Notification_Window\\:\\:\\$_aclResourcePath\\.$#" count: 1 @@ -170,21 +125,6 @@ parameters: count: 1 path: app/code/core/Mage/Adminhtml/Block/Permissions/Usernroles.php - - - message: "#^Call to an undefined method Mage_Reports_Model_Resource_Report_Collection_Abstract\\:\\:addOrderStatusFilter\\(\\)\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php - - - - message: "#^Cannot call method setPeriod\\(\\) on Mage_Core_Model_Resource_Db_Collection_Abstract\\|false\\.$#" - count: 4 - path: app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php - - - - message: "#^Method Mage_Adminhtml_Block_Report_Grid_Abstract\\:\\:addColumn\\(\\) should return Mage_Adminhtml_Block_Report_Grid_Abstract but returns Mage_Adminhtml_Block_Widget_Grid\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Report/Grid/Abstract.php - - message: "#^Property Mage_Adminhtml_Block_Report_Grid_Abstract\\:\\:\\$_columnGroupBy \\(string\\) in isset\\(\\) is not nullable\\.$#" count: 1 @@ -200,11 +140,6 @@ parameters: count: 1 path: app/code/core/Mage/Adminhtml/Block/Report/Product/Grid.php - - - message: "#^Call to an undefined method Mage_Reports_Model_Resource_Report_Collection_Abstract\\:\\:addRuleFilter\\(\\)\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Report/Sales/Coupons/Grid.php - - message: "#^Return type \\(int\\) of method Mage_Adminhtml_Block_Review_Grid_Filter_Type\\:\\:getCondition\\(\\) should be compatible with return type \\(array\\|null\\) of method Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Select\\:\\:getCondition\\(\\)$#" count: 1 @@ -280,21 +215,6 @@ parameters: count: 1 path: app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Packaging.php - - - message: "#^Variable \\$createLabelUrl might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Packaging.php - - - - message: "#^Variable \\$itemsGridUrl might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Packaging.php - - - - message: "#^Variable \\$itemsOrderItemId might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Packaging.php - - message: "#^Return type \\(Mage_Sales_Model_Order_Shipment\\) of method Mage_Adminhtml_Block_Sales_Order_Shipment_View_Items\\:\\:getSource\\(\\) should be compatible with return type \\(Mage_Sales_Model_Order_Invoice\\) of method Mage_Adminhtml_Block_Sales_Items_Abstract\\:\\:getSource\\(\\)$#" count: 1 @@ -360,61 +280,6 @@ parameters: count: 1 path: app/code/core/Mage/Adminhtml/Block/System/Email/Template/Preview.php - - - message: "#^Variable \\$addLabel might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php - - - - message: "#^Variable \\$deleteLabel might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php - - - - message: "#^Variable \\$deleteUrl might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php - - - - message: "#^Variable \\$editLabel might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php - - - - message: "#^Variable \\$saveLabel might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit.php - - - - message: "#^Variable \\$groupModel might not be defined\\.$#" - count: 18 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit/Form.php - - - - message: "#^Variable \\$showGroupFieldset might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit/Form.php - - - - message: "#^Variable \\$showStoreFieldset might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit/Form.php - - - - message: "#^Variable \\$showWebsiteFieldset might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit/Form.php - - - - message: "#^Variable \\$storeModel might not be defined\\.$#" - count: 21 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit/Form.php - - - - message: "#^Variable \\$websiteModel might not be defined\\.$#" - count: 15 - path: app/code/core/Mage/Adminhtml/Block/System/Store/Edit/Form.php - - message: "#^Call to an undefined method Mage_Tag_Model_Resource_Tag_Collection\\:\\:addAttributeToFilter\\(\\)\\.$#" count: 1 @@ -830,11 +695,6 @@ parameters: count: 1 path: app/code/core/Mage/Api2/Model/Resource.php - - - message: "#^Method Mage_Api2_Model_Resource\\:\\:_getSubModel\\(\\) should return \\$this\\(Mage_Api2_Model_Resource\\) but returns Mage_Api2_Model_Resource\\.$#" - count: 1 - path: app/code/core/Mage/Api2/Model/Resource.php - - message: "#^Method Mage_Api2_Model_Resource\\:\\:_multiCreate\\(\\) invoked with 1 parameter, 0 required\\.$#" count: 1 @@ -1275,11 +1135,6 @@ parameters: count: 1 path: app/code/core/Mage/Catalog/Model/Category.php - - - message: "#^Method Mage_Catalog_Model_Category\\:\\:getParentDesignCategory\\(\\) should return \\$this\\(Mage_Catalog_Model_Category\\) but returns Mage_Catalog_Model_Category\\.$#" - count: 1 - path: app/code/core/Mage/Catalog/Model/Category.php - - message: "#^Cannot call method getRootCategoryId\\(\\) on int\\|string\\.$#" count: 1 @@ -1400,11 +1255,6 @@ parameters: count: 1 path: app/code/core/Mage/Catalog/Model/Product.php - - - message: "#^Method Mage_Catalog_Model_Product\\:\\:duplicate\\(\\) should return \\$this\\(Mage_Catalog_Model_Product\\) but returns Mage_Catalog_Model_Product\\.$#" - count: 1 - path: app/code/core/Mage/Catalog/Model/Product.php - - message: "#^Method Mage_Catalog_Model_Product\\:\\:getDefaultAttributeSetId\\(\\) should return int but returns string\\|null\\.$#" count: 1 @@ -2030,11 +1880,6 @@ parameters: count: 2 path: app/code/core/Mage/ConfigurableSwatches/Model/Resource/Catalog/Product/Type/Configurable/Product/Collection.php - - - message: "#^Method Mage_Core_Block_Abstract\\:\\:getHelper\\(\\) should return \\$this\\(Mage_Core_Block_Abstract\\) but returns Mage_Core_Block_Abstract\\.$#" - count: 1 - path: app/code/core/Mage/Core/Block/Abstract.php - - message: "#^Method Mage_Core_Block_Abstract\\:\\:getParentBlock\\(\\) should return \\$this\\(Mage_Core_Block_Abstract\\) but returns Mage_Core_Block_Abstract\\.$#" count: 1 @@ -2156,7 +2001,7 @@ parameters: path: app/code/core/Mage/Core/Model/App.php - - message: "#^Method Mage_Core_Model_Config\\:\\:cleanCache\\(\\) should return \\$this\\(Mage_Core_Model_Config\\) but returns Mage_Core_Model_Config\\.$#" + message: "#^Method Mage_Core_Model_Config\\:\\:getNode\\(\\) should return Mage_Core_Model_Config_Element but returns Varien_Simplexml_Element\\|false\\.$#" count: 1 path: app/code/core/Mage/Core/Model/Config.php @@ -2835,11 +2680,6 @@ parameters: count: 1 path: app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php - - - message: "#^Method Mage_Eav_Model_Entity_Attribute_Abstract\\:\\:getFlatUpdateSelect\\(\\) should return \\$this\\(Mage_Eav_Model_Entity_Attribute_Abstract\\)\\|Varien_Db_Select but returns null\\.$#" - count: 1 - path: app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php - - message: "#^Property Mage_Eav_Model_Entity_Attribute_Abstract\\:\\:\\$_backend \\(Mage_Eav_Model_Entity_Attribute_Backend_Abstract\\) in empty\\(\\) is not falsy\\.$#" count: 1 @@ -3100,11 +2940,6 @@ parameters: count: 1 path: app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php - - - message: "#^Method Mage_Index_Model_Lock\\:\\:getInstance\\(\\) should return \\$this\\(Mage_Index_Model_Lock\\) but returns Mage_Index_Model_Lock\\.$#" - count: 1 - path: app/code/core/Mage/Index/Model/Lock.php - - message: "#^Property Mage_Index_Model_Lock\\:\\:\\$_storage \\(Mage_Index_Model_Lock_Storage_Interface\\) does not accept Mage_Core_Model_Abstract\\|false\\.$#" count: 1 @@ -3295,16 +3130,6 @@ parameters: count: 1 path: app/code/core/Mage/Paypal/Block/Hosted/Pro/Info.php - - - message: "#^Method Mage_Paypal_Block_Iframe\\:\\:_getBlock\\(\\) should return \\$this\\(Mage_Paypal_Block_Iframe\\) but returns Mage_Payment_Block_Form\\.$#" - count: 1 - path: app/code/core/Mage/Paypal/Block/Iframe.php - - - - message: "#^Property Mage_Paypal_Block_Iframe\\:\\:\\$_block \\(Mage_Payment_Block_Form\\) does not accept Mage_Core_Block_Abstract\\|false\\.$#" - count: 1 - path: app/code/core/Mage/Paypal/Block/Iframe.php - - message: "#^Return type \\(false\\) of method Mage_Paypal_Block_Payflow_Link_Info\\:\\:getCcTypeName\\(\\) should be compatible with return type \\(string\\|null\\) of method Mage_Paypal_Block_Payment_Info\\:\\:getCcTypeName\\(\\)$#" count: 1 @@ -4050,21 +3875,11 @@ parameters: count: 1 path: app/code/core/Mage/Sales/Model/Status/List.php - - - message: "#^Method Mage_Sales_Billing_AgreementController\\:\\:preDispatch\\(\\) should return \\$this\\(Mage_Sales_Billing_AgreementController\\) but empty return statement found\\.$#" - count: 1 - path: app/code/core/Mage/Sales/controllers/Billing/AgreementController.php - - message: "#^Variable \\$billingAgreement might not be defined\\.$#" count: 2 path: app/code/core/Mage/Sales/controllers/Billing/AgreementController.php - - - message: "#^Method Mage_Sales_Recurring_ProfileController\\:\\:preDispatch\\(\\) should return \\$this\\(Mage_Sales_Recurring_ProfileController\\) but empty return statement found\\.$#" - count: 1 - path: app/code/core/Mage/Sales/controllers/Recurring/ProfileController.php - - message: "#^Return type \\(Mage_SalesRule_Model_Quote_Discount\\) of method Mage_SalesRule_Model_Quote_Discount\\:\\:fetch\\(\\) should be compatible with return type \\(array\\) of method Mage_Sales_Model_Quote_Address_Total_Abstract\\:\\:fetch\\(\\)$#" count: 1 @@ -4120,11 +3935,6 @@ parameters: count: 1 path: app/code/core/Mage/Shipping/Model/Carrier/Abstract.php - - - message: "#^Method Mage_Shipping_Model_Carrier_Abstract\\:\\:checkAvailableShipCountries\\(\\) should return \\$this\\(Mage_Shipping_Model_Carrier_Abstract\\)\\|bool\\|Mage_Core_Model_Abstract but returns Mage_Shipping_Model_Rate_Result_Error\\.$#" - count: 1 - path: app/code/core/Mage/Shipping/Model/Carrier/Abstract.php - - message: "#^Negated boolean expression is always false\\.$#" count: 1 From 90d975234837fc7af2b0910f56ebaf38694ce082 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Mon, 14 Oct 2024 11:02:26 -0700 Subject: [PATCH 040/113] phpstan --- .phpstan.baseline.neon | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.phpstan.baseline.neon b/.phpstan.baseline.neon index 7c7bfc6f9..625abb71e 100644 --- a/.phpstan.baseline.neon +++ b/.phpstan.baseline.neon @@ -2000,11 +2000,6 @@ parameters: count: 1 path: app/code/core/Mage/Core/Model/App.php - - - message: "#^Method Mage_Core_Model_Config\\:\\:getNode\\(\\) should return Mage_Core_Model_Config_Element but returns Varien_Simplexml_Element\\|false\\.$#" - count: 1 - path: app/code/core/Mage/Core/Model/Config.php - - message: "#^Return type \\(Mage_Core_Model_App\\) of method Mage_Core_Model_Config\\:\\:_saveCache\\(\\) should be compatible with return type \\(bool\\) of method Varien_Simplexml_Config\\:\\:_saveCache\\(\\)$#" count: 1 From 2400274037bec62f298ddae417d2e5d33b6e7ffa Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Mon, 14 Oct 2024 14:38:51 -0700 Subject: [PATCH 041/113] Reorder some fields, add field dependence, move blocks to lib/Varien, etc --- .../Block/Catalog/Category/Tab/Attributes.php | 3 +- .../Product/Attribute/Edit/Tab/Main.php | 31 +++-- .../Adminhtml/Model/Customer/Observer.php | 112 ++++++++++++++++++ app/code/core/Mage/Adminhtml/etc/config.xml | 40 +++++++ .../Attribute/Edit/Main/Abstract.php | 75 ++++++------ .../Adminhtml/Attribute/Edit/Tab/Main.php | 16 ++- .../Varien/Data/Form/Element}/Boolean.php | 17 ++- lib/Varien/Data/Form/Element/Number.php | 43 +++++++ 8 files changed, 275 insertions(+), 62 deletions(-) create mode 100644 app/code/core/Mage/Adminhtml/Model/Customer/Observer.php rename {app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form => lib/Varien/Data/Form/Element}/Boolean.php (53%) create mode 100644 lib/Varien/Data/Form/Element/Number.php diff --git a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php index c71657abc..ae7f447bf 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php @@ -161,8 +161,7 @@ protected function _getAdditionalElementTypes() { return [ 'image' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_category_helper_image'), - 'textarea' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_helper_form_wysiwyg'), - 'boolean' => Mage::getConfig()->getBlockClassName('eav/adminhtml_helper_form_boolean'), + 'textarea' => Mage::getConfig()->getBlockClassName('adminhtml/catalog_helper_form_wysiwyg') ]; } } 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..b7adffe65 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 @@ -112,13 +112,21 @@ protected function _prepareForm() 'custom' => Mage::helper('catalog')->__('Selected Product Types') ], 'required' => true - ], 'frontend_class'); + ]); $fieldset->addField('is_configurable', 'select', [ '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')]); @@ -230,18 +238,21 @@ protected function _prepareForm() // 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->addFieldMap('is_wysiwyg_enabled', 'wysiwyg_enabled') + ->addFieldMap('is_html_allowed_on_front', 'html_allowed_on_front') + ->addFieldMap('frontend_input', 'frontend_input_type') + ->addFieldDependence('wysiwyg_enabled', 'frontend_input_type', 'textarea') + ->addFieldDependence('html_allowed_on_front', 'wysiwyg_enabled', '0'); Mage::dispatchEvent('adminhtml_catalog_product_attribute_edit_prepare_form', [ - 'form' => $form, - 'attribute' => $attributeObject + 'form' => $form, + 'attribute' => $attributeObject, + 'dependence' => $block, ]); + $this->setChild('form_after', $block); + return $this; } diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php new file mode 100644 index 000000000..98a0e910e --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -0,0 +1,112 @@ +getAttribute(); + $attributeTypeCode = $attribute->getEntityType()->getEntityTypeCode(); + + /** @var Varien_Object $response */ + $response = $observer->getResponse(); + + $response->setTypes([ + ['value' => 'multiline', 'label' => Mage::helper('eav')->__('Multiline')], + ]); + + return $this; + } + + /** + * Modify customer and customer_address attribute edit forms + * + * @param Varien_Event_Observer $observer + * @return $this + */ + public function attributeEditPrepareForm($observer) + { + /** @var Mage_Customer_Model_Attribute $attribute */ + $attribute = $observer->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', 'select', [ + 'name' => 'is_visible', + 'label' => Mage::helper('adminhtml')->__('Is Visible'), + 'title' => Mage::helper('adminhtml')->__('Is Visible'), + 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(), + ], 'frontend_class'); + + $fieldset->addField('multiline_count', 'number', [ + 'name' => 'multiline_count', + 'label' => Mage::helper('eav')->__('Multiline Count'), + 'title' => Mage::helper('eav')->__('Multiline Count'), + 'min' => 1, + 'max' => 4, + ], 'frontend_input'); + + /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $block */ + $dependenceBlock = $observer->getDependence(); + + $dependenceBlock->addFieldMap('frontend_input', 'frontend_input') + ->addFieldMap('multiline_count', 'multiline_count') + ->addFieldDependence('multiline_count', 'frontend_input', 'multiline'); + + return $this; + } + + /** + * Save extra properties from customer and customer_address attribute edit forms + * + * @param Varien_Event_Observer $observer + * @return $this + */ + public function attributeEditPrepareSave($observer) + { + /** @var Mage_Core_Controller_Request_Http $request */ + $request = $observer->getRequest(); + + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + $attribute = $observer->getObject(); + + // $data = $request->getPost(); + // if ($data) { + // if (!$attribute->getWebsite()->getId()) { + // if (!isset($data['use_in_forms'])) { + // $data['use_in_forms'] = []; + // } + // $attribute->setData('used_in_forms', $data['use_in_forms']); + // } + // } + + return $this; + } +} diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index 97ce541a7..e8e078e39 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -119,6 +119,46 @@ + + + + adminhtml/customer_observer + attributeEditPrepareForm + + + + + + + adminhtml/customer_observer + attributeEditPrepareSave + + + + + + + adminhtml/customer_observer + attributeEditPrepareForm + + + + + + + adminhtml/customer_observer + attributeEditPrepareSave + + + + + + + adminhtml/customer_observer + attributeAddInputTypes + + + 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 c5223770b..662324470 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 @@ -107,12 +107,34 @@ protected function _prepareForm() $fieldset->addField('frontend_input', 'select', [ 'name' => 'frontend_input', - 'label' => Mage::helper('eav')->__('Input Type for Store Owner'), - 'title' => Mage::helper('eav')->__('Input Type for Store Owner'), + 'label' => Mage::helper('eav')->__('Input Type'), + 'title' => Mage::helper('eav')->__('Input Type'), 'value' => 'text', 'values' => $inputTypes ]); + $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($attributeObject->getEntityType()->getEntityTypeCode()) + ]); + + $fieldset->addField('is_required', 'select', [ + 'name' => 'is_required', + 'label' => Mage::helper('eav')->__('Values Required'), + 'title' => Mage::helper('eav')->__('Values Required'), + 'values' => $yesno, + ]); + + $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('default_value_text', 'text', [ 'name' => 'default_value_text', 'label' => Mage::helper('eav')->__('Default Value'), @@ -144,28 +166,6 @@ protected function _prepareForm() '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->getResource()->hasFormTable()) { $attributeObjectTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); $fieldset->addField('used_in_forms', 'multiselect', [ @@ -177,14 +177,6 @@ protected function _prepareForm() ]); } - if ($attributeObject->getId()) { - $form->getElement('attribute_code')->setDisabled(1); - $form->getElement('frontend_input')->setDisabled(1); - if (!$attributeObject->getIsUserDefined()) { - $form->getElement('is_unique')->setDisabled(1); - } - } - $this->setForm($form); return parent::_prepareForm(); @@ -234,12 +226,19 @@ protected function _beforeToHtml() if ($attributeObject->getId()) { $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); } } } 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 index 9ebfb9d4e..ebbceb4e7 100644 --- 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 @@ -55,7 +55,10 @@ protected function _prepareForm() $response = new Varien_Object(); $response->setTypes([]); - Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_types", ['response' => $response]); + Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_types", [ + 'response' => $response, + 'attribute' => $attributeObject + ]); $_disabledTypes = []; $_hiddenFields = []; foreach ($response->getTypes() as $type) { @@ -73,11 +76,18 @@ protected function _prepareForm() $frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes); $frontendInputElm->setValues($frontendInputValues); + // define field dependencies + /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $block */ + $block = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence'); + Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_edit_prepare_form", [ - 'form' => $form, - 'attribute' => $attributeObject + 'form' => $form, + 'attribute' => $attributeObject, + 'dependence' => $block, ]); + $this->setChild('form_after', $block); + return $this; } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php b/lib/Varien/Data/Form/Element/Boolean.php similarity index 53% rename from app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php rename to lib/Varien/Data/Form/Element/Boolean.php index d755f964d..cf8a89ccd 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Helper/Form/Boolean.php +++ b/lib/Varien/Data/Form/Element/Boolean.php @@ -2,31 +2,30 @@ /** * Maho * - * @category Mage - * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) + * @category Varien + * @package Varien_Data * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * Eav form boolean field helper + * Form boolean element * - * @category Mage - * @package Mage_Eav + * @category Varien + * @package Varien_Data */ -class Mage_Eav_Block_Adminhtml_Helper_Form_Boolean extends Varien_Data_Form_Element_Select +class Varien_Data_Form_Element_Boolean extends Varien_Data_Form_Element_Select { public function __construct($attributes = []) { parent::__construct($attributes); $this->setValues([ [ - 'label' => Mage::helper('eav')->__('No'), + 'label' => Mage::helper('core')->__('No'), 'value' => 0, ], [ - 'label' => Mage::helper('eav')->__('Yes'), + 'label' => Mage::helper('core')->__('Yes'), 'value' => 1, ], ]); diff --git a/lib/Varien/Data/Form/Element/Number.php b/lib/Varien/Data/Form/Element/Number.php new file mode 100644 index 000000000..989db3709 --- /dev/null +++ b/lib/Varien/Data/Form/Element/Number.php @@ -0,0 +1,43 @@ +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']; + } +} From 3b14a35e7b04241635994d4a71d2d59ce056a2bc Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 06:42:21 -0700 Subject: [PATCH 042/113] phpstan --- app/code/core/Mage/Adminhtml/Model/Customer/Observer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index 98a0e910e..fd37838fb 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -73,7 +73,7 @@ public function attributeEditPrepareForm($observer) 'max' => 4, ], 'frontend_input'); - /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $block */ + /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $dependenceBlock */ $dependenceBlock = $observer->getDependence(); $dependenceBlock->addFieldMap('frontend_input', 'frontend_input') From 29c94e70a58507002df137010a8f0f00b766c7ff Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 06:52:06 -0700 Subject: [PATCH 043/113] phpcs --- app/code/core/Mage/Adminhtml/Model/Customer/Observer.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index fd37838fb..f827d2e51 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -17,7 +17,6 @@ */ class Mage_Adminhtml_Model_Customer_Observer { - /** * Add input types in customer and customer_address attribute edit forms * From 628a7dec646f9c9bacd8c937eabc7b91db8c98be Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 07:26:07 -0700 Subject: [PATCH 044/113] Multiline max, and allow for customer type --- .../Adminhtml/Model/Customer/Observer.php | 6 ++++- app/code/core/Mage/Adminhtml/etc/config.xml | 24 ++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index f827d2e51..fef05b8bb 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -68,10 +68,14 @@ public function attributeEditPrepareForm($observer) 'name' => 'multiline_count', 'label' => Mage::helper('eav')->__('Multiline Count'), 'title' => Mage::helper('eav')->__('Multiline Count'), + 'value' => 1, 'min' => 1, - 'max' => 4, ], 'frontend_input'); + if ($attribute->getAttributeCode()) { + $form->getElement('multiline_count')->setMax(4); + } + /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $dependenceBlock */ $dependenceBlock = $observer->getDependence(); diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index e8e078e39..9e71b0f9a 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -119,6 +119,14 @@ + + + + adminhtml/customer_observer + attributeAddInputTypes + + + @@ -135,6 +143,14 @@ + + + + adminhtml/customer_observer + attributeAddInputTypes + + + @@ -151,14 +167,6 @@ - - - - adminhtml/customer_observer - attributeAddInputTypes - - - From 12aced377fcb59766cc716671a54bda051529dc1 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 07:27:23 -0700 Subject: [PATCH 045/113] fix --- app/code/core/Mage/Adminhtml/Model/Customer/Observer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index fef05b8bb..b4ddb1416 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -72,7 +72,7 @@ public function attributeEditPrepareForm($observer) 'min' => 1, ], 'frontend_input'); - if ($attribute->getAttributeCode()) { + if ($attribute->getAttributeCode() === 'street') { $form->getElement('multiline_count')->setMax(4); } From f04a969c014691f79a50851745c7dc832d80a6a3 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 11:11:29 -0700 Subject: [PATCH 046/113] Use boolean type --- .../core/Mage/Adminhtml/Model/Customer/Observer.php | 3 +-- .../Block/Adminhtml/Attribute/Edit/Main/Abstract.php | 11 +++-------- lib/Varien/Data/Form/Element/Boolean.php | 8 ++++---- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index b4ddb1416..34889b1f3 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -57,11 +57,10 @@ public function attributeEditPrepareForm($observer) /** @var Varien_Data_Form_Element_Fieldset $fieldset */ $fieldset = $form->getElement('base_fieldset'); - $fieldset->addField('is_visible', 'select', [ + $fieldset->addField('is_visible', 'boolean', [ 'name' => 'is_visible', 'label' => Mage::helper('adminhtml')->__('Is Visible'), 'title' => Mage::helper('adminhtml')->__('Is Visible'), - 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(), ], 'frontend_class'); $fieldset->addField('multiline_count', 'number', [ 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 662324470..ba6afecc8 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 @@ -88,8 +88,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 @@ -120,19 +118,17 @@ protected function _prepareForm() 'values' => Mage::helper('eav')->getFrontendClasses($attributeObject->getEntityType()->getEntityTypeCode()) ]); - $fieldset->addField('is_required', 'select', [ + $fieldset->addField('is_required', 'boolean', [ 'name' => 'is_required', 'label' => Mage::helper('eav')->__('Values Required'), 'title' => Mage::helper('eav')->__('Values Required'), - 'values' => $yesno, ]); - $fieldset->addField('is_unique', 'select', [ + $fieldset->addField('is_unique', 'boolean', [ '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('default_value_text', 'text', [ @@ -142,11 +138,10 @@ protected function _prepareForm() 'value' => $attributeObject->getDefaultValue(), ]); - $fieldset->addField('default_value_yesno', 'select', [ + $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(), ]); diff --git a/lib/Varien/Data/Form/Element/Boolean.php b/lib/Varien/Data/Form/Element/Boolean.php index cf8a89ccd..41fa07de9 100644 --- a/lib/Varien/Data/Form/Element/Boolean.php +++ b/lib/Varien/Data/Form/Element/Boolean.php @@ -20,14 +20,14 @@ public function __construct($attributes = []) { parent::__construct($attributes); $this->setValues([ - [ - 'label' => Mage::helper('core')->__('No'), - 'value' => 0, - ], [ 'label' => Mage::helper('core')->__('Yes'), 'value' => 1, ], + [ + 'label' => Mage::helper('core')->__('No'), + 'value' => 0, + ], ]); } } From 967648d114557a63da7381f08c9dd6a20d62a4e2 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 13:55:51 -0700 Subject: [PATCH 047/113] Testing rendering all fields from group --- .../core/Mage/Customer/Block/Form/Edit.php | 10 ++++++- app/code/core/Mage/Customer/Helper/Data.php | 30 +++++++++++++++++-- .../Resource/Form/Attribute/Collection.php | 19 ------------ .../Resource/Entity/Attribute/Collection.php | 2 +- .../Resource/Form/Attribute/Collection.php | 30 +++++++++++++++++++ .../default/template/customer/form/edit.phtml | 15 ++++++---- 6 files changed, 76 insertions(+), 30 deletions(-) diff --git a/app/code/core/Mage/Customer/Block/Form/Edit.php b/app/code/core/Mage/Customer/Block/Form/Edit.php index 24862c9de..6c89e5b20 100644 --- a/app/code/core/Mage/Customer/Block/Form/Edit.php +++ b/app/code/core/Mage/Customer/Block/Form/Edit.php @@ -17,11 +17,19 @@ */ class Mage_Customer_Block_Form_Edit extends Mage_Customer_Block_Account_Dashboard { + /** + * Return all EAV fields used in this form as groups + */ + public function getGroupedFields(): array + { + return Mage::helper('customer')->getGroupedFields('customer_account_edit', $this->getCustomer()); + } + /** * Return extra EAV fields used in this form */ public function getExtraFields(): array { - return Mage::helper('customer')->getExtraFields('customer_account_edit'); + return Mage::helper('customer')->getExtraFields('customer_account_edit', $this->getCustomer()); } } diff --git a/app/code/core/Mage/Customer/Helper/Data.php b/app/code/core/Mage/Customer/Helper/Data.php index f409e4236..9a5014e56 100644 --- a/app/code/core/Mage/Customer/Helper/Data.php +++ b/app/code/core/Mage/Customer/Helper/Data.php @@ -743,13 +743,37 @@ protected function _getCountryCodeForVatNumber(string $countryCode): string return $countryCode === 'GR' ? 'EL' : $countryCode; } + /** + * Return all EAV fields used in customer forms as groups + */ + public function getGroupedFields(string $formCode, ?Mage_Customer_Model_Customer $customer=null): array + { + $customer ??= Mage::getModel('customer/customer'); + + /** @var Mage_Customer_Model_Form $form */ + $form = Mage::getModel('customer/form'); + $form->setFormCode($formCode) + ->setEntity($customer) + ->initDefaultValues(); + + $groups = []; + $attributes = $form->getAttributes(); + + foreach ($attributes as $code => $attribute) { + $group = $attribute->getAttributeGroupName() ?? 'General'; + $groups[$group] ??= []; + $groups[$group][$code] = $attribute; + } + + return $groups; + } + /** * Return extra EAV fields used in customer forms */ - public function getExtraFields(string $formCode): array + public function getExtraFields(string $formCode, ?Mage_Customer_Model_Customer $customer=null): array { - /** @var Mage_Customer_Model_Customer $customer */ - $customer = Mage::getModel('customer/customer'); + $customer ??= Mage::getModel('customer/customer'); /** @var Mage_Customer_Model_Form $form */ $form = Mage::getModel('customer/form'); diff --git a/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php b/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php index 7f9df9fc1..ed17b3a1f 100644 --- a/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php +++ b/app/code/core/Mage/Customer/Model/Resource/Form/Attribute/Collection.php @@ -52,23 +52,4 @@ protected function _getEavWebsiteTable() { return $this->getTable('customer/eav_attribute_website'); } - - public function filterAttributeSet($attributeSetId) - { - $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'] - ) - ->where('eea.attribute_set_id = ?', $attributeSetId) - ->order(['eag.sort_order', 'eea.sort_order']); - - return $this; - } } 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 8b04ee0e4..b955c8f4f 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 @@ -316,7 +316,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 */ 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 ce5c03a24..ecf526c74 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/design/frontend/rwd/default/template/customer/form/edit.phtml b/app/design/frontend/rwd/default/template/customer/form/edit.phtml index 9bb27285b..dcb9478d8 100644 --- a/app/design/frontend/rwd/default/template/customer/form/edit.phtml +++ b/app/design/frontend/rwd/default/template/customer/form/edit.phtml @@ -42,12 +42,15 @@
    • setGender($this->getCustomer()->getGender())->toHtml() ?>
    • - getExtraFields() as $_code => $_attribute): ?> - getFrontendInput() ?> - getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> - isEnabled()): ?> -
    • setObject($this->getCustomer())->toHtml() ?>
    • - + getGroupedFields() as $_group => $_attributes): ?> +

      __($_group) ?>

      + $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> + isEnabled()): ?> +
    • setObject($this->getCustomer())->toHtml() ?>
    • + +
    • From 9e325eec62caaabae402528aee4390b4634f6916 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 15:10:15 -0700 Subject: [PATCH 048/113] short echo syntax --- .../template/eav/attribute/set/main.phtml | 50 +++++++++---------- .../eav/attribute/set/toolbar/add.phtml | 10 ++-- .../template/checkout/onepage/billing.phtml | 4 +- .../template/customer/address/edit.phtml | 4 +- .../default/template/customer/form/edit.phtml | 2 +- .../template/customer/form/register.phtml | 2 +- .../default/template/eav/widget/boolean.phtml | 6 +-- .../default/template/eav/widget/date.phtml | 10 ++-- .../template/eav/widget/multiselect.phtml | 6 +-- .../default/template/eav/widget/select.phtml | 6 +-- .../default/template/eav/widget/text.phtml | 4 +- .../template/eav/widget/textarea.phtml | 4 +- .../template/customer/address/edit.phtml | 4 +- .../default/template/customer/form/edit.phtml | 2 +- 14 files changed, 57 insertions(+), 57 deletions(-) diff --git a/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml b/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml index 384e3f3a2..36a560c08 100644 --- a/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml +++ b/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml @@ -12,12 +12,12 @@
      - +

      escapeHtml($this->_getHeader()) ?>

      escapeHtml($this->_getHeader()) ?>

      - getBackButtonHtml() ?> - getResetButtonHtml() ?> - getDeleteButtonHtml() ?> - getSaveButtonHtml() ?> + getBackButtonHtml() ?> + getResetButtonHtml() ?> + getDeleteButtonHtml() ?> + getSaveButtonHtml() ?>
      @@ -25,33 +25,33 @@
      - getSetFormHtml() ?> + getSetFormHtml() ?>
      - +

      __('Groups') ?>

      __('Groups') ?>

      getIsReadOnly()): ?> -

      getAddGroupButton() ?> getDeleteGroupButton() ?>

      -

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

      +

      getAddGroupButton() ?> getDeleteGroupButton() ?>

      +

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

      - getSetsFilterHtml() ?> - getGroupTreeHtml() ?> + getSetsFilterHtml() ?> + getGroupTreeHtml() ?>
      - +

      __('Unassigned Attributes') ?>

      __('Unassigned Attributes') ?>

      @@ -59,8 +59,8 @@
      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 4af5edbbf..5cf19a8ec 100644 --- a/app/design/frontend/base/default/template/checkout/onepage/billing.phtml +++ b/app/design/frontend/base/default/template/checkout/onepage/billing.phtml @@ -123,7 +123,7 @@ getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute)->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]') ?> isEnabled()): ?> -
    • setObject($this->getExtraFieldsSession())->toHtml() ?>
    • +
    • setObject($this->getExtraFieldsSession())->toHtml() ?>
    • @@ -154,7 +154,7 @@ getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute)->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]') ?> isEnabled()): ?> -
    • setObject($this->getExtraFieldsSession())->toHtml() ?>
    • +
    • setObject($this->getExtraFieldsSession())->toHtml() ?>
    • 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 7b1b9d234..99302dbe2 100644 --- a/app/design/frontend/base/default/template/customer/address/edit.phtml +++ b/app/design/frontend/base/default/template/customer/address/edit.phtml @@ -138,13 +138,13 @@
      -

      __('Other') ?>

      +

      __('Other') ?>

        getExtraFields() as $_code => $_attribute): ?> getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> isEnabled()): ?> -
      • setObject($this->getAddress())->toHtml() ?>
      • +
      • setObject($this->getAddress())->toHtml() ?>
      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 ac9cbc8cf..c27783e08 100644 --- a/app/design/frontend/base/default/template/customer/form/edit.phtml +++ b/app/design/frontend/base/default/template/customer/form/edit.phtml @@ -45,7 +45,7 @@ getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> isEnabled()): ?> -
    • setObject($this->getCustomer())->toHtml() ?>
    • +
    • setObject($this->getCustomer())->toHtml() ?>
    • diff --git a/app/design/frontend/base/default/template/customer/form/register.phtml b/app/design/frontend/base/default/template/customer/form/register.phtml index 24f070c16..98c4b9fac 100644 --- a/app/design/frontend/base/default/template/customer/form/register.phtml +++ b/app/design/frontend/base/default/template/customer/form/register.phtml @@ -69,7 +69,7 @@ getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> isEnabled()): ?> -
    • setObject($this->getFormData())->toHtml() ?>
    • +
    • setObject($this->getFormData())->toHtml() ?>
    • diff --git a/app/design/frontend/base/default/template/eav/widget/boolean.phtml b/app/design/frontend/base/default/template/eav/widget/boolean.phtml index a279aab51..47b67f725 100644 --- a/app/design/frontend/base/default/template/eav/widget/boolean.phtml +++ b/app/design/frontend/base/default/template/eav/widget/boolean.phtml @@ -11,13 +11,13 @@ ?> getAttribute() ?> getAttributeCode() ?> - +
      - isRequired()):?> class="validate-select" getFieldParams() ?>> getOptions() ?> getObject()->getData($_code) ?> - +
      diff --git a/app/design/frontend/base/default/template/eav/widget/date.phtml b/app/design/frontend/base/default/template/eav/widget/date.phtml index b02d71a7b..921971e33 100644 --- a/app/design/frontend/base/default/template/eav/widget/date.phtml +++ b/app/design/frontend/base/default/template/eav/widget/date.phtml @@ -11,8 +11,8 @@ ?> getAttribute() ?> getAttributeCode() ?> - -
      + +
      setDateInput('d', '
      @@ -35,15 +35,15 @@
      ' ); ?> - getSortedDateInputs() ?> + getSortedDateInputs() ?>
      diff --git a/app/design/frontend/base/default/template/eav/widget/multiselect.phtml b/app/design/frontend/base/default/template/eav/widget/multiselect.phtml index 51af1a047..6989e008c 100644 --- a/app/design/frontend/base/default/template/eav/widget/multiselect.phtml +++ b/app/design/frontend/base/default/template/eav/widget/multiselect.phtml @@ -11,13 +11,13 @@ ?> getAttribute() ?> getAttributeCode() ?> - +
      - isRequired()):?> class="validate-select" getFieldParams() ?>> getOptions() ?> getObject()->getData($_code)) ?> - +
      diff --git a/app/design/frontend/base/default/template/eav/widget/select.phtml b/app/design/frontend/base/default/template/eav/widget/select.phtml index a279aab51..47b67f725 100644 --- a/app/design/frontend/base/default/template/eav/widget/select.phtml +++ b/app/design/frontend/base/default/template/eav/widget/select.phtml @@ -11,13 +11,13 @@ ?> getAttribute() ?> getAttributeCode() ?> - +
      - isRequired()):?> class="validate-select" getFieldParams() ?>> getOptions() ?> getObject()->getData($_code) ?> - +
      diff --git a/app/design/frontend/base/default/template/eav/widget/text.phtml b/app/design/frontend/base/default/template/eav/widget/text.phtml index c960daa13..c08f9aeb8 100644 --- a/app/design/frontend/base/default/template/eav/widget/text.phtml +++ b/app/design/frontend/base/default/template/eav/widget/text.phtml @@ -11,7 +11,7 @@ ?> getAttribute() ?> getAttributeCode() ?> - +
      - getFieldParams() ?> /> + getFieldParams() ?> />
      diff --git a/app/design/frontend/base/default/template/eav/widget/textarea.phtml b/app/design/frontend/base/default/template/eav/widget/textarea.phtml index fd835c75b..b76f9634e 100644 --- a/app/design/frontend/base/default/template/eav/widget/textarea.phtml +++ b/app/design/frontend/base/default/template/eav/widget/textarea.phtml @@ -11,7 +11,7 @@ ?> getAttribute() ?> getAttributeCode() ?> - +
      - +
      diff --git a/app/design/frontend/rwd/default/template/customer/address/edit.phtml b/app/design/frontend/rwd/default/template/customer/address/edit.phtml index ed3e8f90f..efd3b63ad 100644 --- a/app/design/frontend/rwd/default/template/customer/address/edit.phtml +++ b/app/design/frontend/rwd/default/template/customer/address/edit.phtml @@ -140,13 +140,13 @@
      -

      __('Other') ?>

      +

      __('Other') ?>

        getExtraFields() as $_code => $_attribute): ?> getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> isEnabled()): ?> -
      • setObject($this->getAddress())->toHtml() ?>
      • +
      • setObject($this->getAddress())->toHtml() ?>
      diff --git a/app/design/frontend/rwd/default/template/customer/form/edit.phtml b/app/design/frontend/rwd/default/template/customer/form/edit.phtml index dcb9478d8..577c5b1ff 100644 --- a/app/design/frontend/rwd/default/template/customer/form/edit.phtml +++ b/app/design/frontend/rwd/default/template/customer/form/edit.phtml @@ -48,7 +48,7 @@ getFrontendInput() ?> getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> isEnabled()): ?> -
    • setObject($this->getCustomer())->toHtml() ?>
    • +
    • setObject($this->getCustomer())->toHtml() ?>
    • From 487dd3aa9ac2361276feb478ee1e628a4d414863 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 15:13:42 -0700 Subject: [PATCH 049/113] add validation classes (thx empiricompany) --- app/design/frontend/base/default/template/eav/widget/text.phtml | 2 +- .../frontend/base/default/template/eav/widget/textarea.phtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/design/frontend/base/default/template/eav/widget/text.phtml b/app/design/frontend/base/default/template/eav/widget/text.phtml index c08f9aeb8..dbf89da41 100644 --- a/app/design/frontend/base/default/template/eav/widget/text.phtml +++ b/app/design/frontend/base/default/template/eav/widget/text.phtml @@ -13,5 +13,5 @@ getAttributeCode() ?>
      - getFieldParams() ?> /> + getFieldParams() ?> />
      diff --git a/app/design/frontend/base/default/template/eav/widget/textarea.phtml b/app/design/frontend/base/default/template/eav/widget/textarea.phtml index b76f9634e..fe92724d1 100644 --- a/app/design/frontend/base/default/template/eav/widget/textarea.phtml +++ b/app/design/frontend/base/default/template/eav/widget/textarea.phtml @@ -13,5 +13,5 @@ getAttributeCode() ?>
      - +
      From 12680d0dfdae631f9a89854027d7dc5e54500ee7 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 15:16:07 -0700 Subject: [PATCH 050/113] phpcs --- app/code/core/Mage/Customer/Helper/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/Customer/Helper/Data.php b/app/code/core/Mage/Customer/Helper/Data.php index 9a5014e56..7abca14ba 100644 --- a/app/code/core/Mage/Customer/Helper/Data.php +++ b/app/code/core/Mage/Customer/Helper/Data.php @@ -746,7 +746,7 @@ protected function _getCountryCodeForVatNumber(string $countryCode): string /** * Return all EAV fields used in customer forms as groups */ - public function getGroupedFields(string $formCode, ?Mage_Customer_Model_Customer $customer=null): array + public function getGroupedFields(string $formCode, ?Mage_Customer_Model_Customer $customer = null): array { $customer ??= Mage::getModel('customer/customer'); @@ -771,7 +771,7 @@ public function getGroupedFields(string $formCode, ?Mage_Customer_Model_Customer /** * Return extra EAV fields used in customer forms */ - public function getExtraFields(string $formCode, ?Mage_Customer_Model_Customer $customer=null): array + public function getExtraFields(string $formCode, ?Mage_Customer_Model_Customer $customer = null): array { $customer ??= Mage::getModel('customer/customer'); From 71aa6427410314c62e728a09091a73ac959b7991 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 16:36:59 -0700 Subject: [PATCH 051/113] validation class fix --- app/design/frontend/base/default/template/eav/widget/text.phtml | 2 +- .../frontend/base/default/template/eav/widget/textarea.phtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/design/frontend/base/default/template/eav/widget/text.phtml b/app/design/frontend/base/default/template/eav/widget/text.phtml index dbf89da41..8ea20e7e5 100644 --- a/app/design/frontend/base/default/template/eav/widget/text.phtml +++ b/app/design/frontend/base/default/template/eav/widget/text.phtml @@ -13,5 +13,5 @@ getAttributeCode() ?>
      - getFieldParams() ?> /> + getFieldParams() ?> />
      diff --git a/app/design/frontend/base/default/template/eav/widget/textarea.phtml b/app/design/frontend/base/default/template/eav/widget/textarea.phtml index fe92724d1..bf81798a3 100644 --- a/app/design/frontend/base/default/template/eav/widget/textarea.phtml +++ b/app/design/frontend/base/default/template/eav/widget/textarea.phtml @@ -13,5 +13,5 @@ getAttributeCode() ?>
      - +
      From ed1ebaade7b0083fb57f6899f29fe956b2430fe4 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 15 Oct 2024 16:59:13 -0700 Subject: [PATCH 052/113] Testing rendering all fields from group part 2 --- .../default/template/customer/form/edit.phtml | 61 +++++++------------ 1 file changed, 21 insertions(+), 40 deletions(-) diff --git a/app/design/frontend/rwd/default/template/customer/form/edit.phtml b/app/design/frontend/rwd/default/template/customer/form/edit.phtml index 577c5b1ff..1feeb2c27 100644 --- a/app/design/frontend/rwd/default/template/customer/form/edit.phtml +++ b/app/design/frontend/rwd/default/template/customer/form/edit.phtml @@ -15,44 +15,30 @@
      getMessagesBlock()->toHtml() ?>
      + getBlockHtml('formkey') ?> + +getGroupedFields() ?> + $_group): ?>
      - getBlockHtml('formkey') ?> -

      __('Account Information') ?>

      +

      __($_group) ?>

      +

      __('* 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() ?>
      • + $_attribute): ?> + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> + isEnabled()): ?> +
      • setObject($this->getCustomer())->toHtml() ?>
      • + +
      +
      + - getGroupedFields() as $_group => $_attributes): ?> -

      __($_group) ?>

      - $_attribute): ?> - getFrontendInput() ?> - getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> - isEnabled()): ?> -
    • setObject($this->getCustomer())->toHtml() ?>
    • - - - - +
      +

      __('Password Information') ?>

      +
      • @@ -64,12 +50,7 @@
      • getCustomer()->getChangePassword()==1): ?> checked="checked" class="checkbox" />
      • -
      -
      -
      -
      - -
    • -
      - -
      - -
      -
      -
      - -
      - getCountryHtmlSelect() ?> -
      -
      -
    • - - + +getGroupedFieldsAddress() ?> + $_group): ?> +
      +

      __($_group) ?>

      + +

      __('* Required Fields') ?>

      +
        + $_attribute): ?> + + +
      • +
        + +
        + + + +
        +
        +
      • + + getFrontendInput() ?> + getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> + isEnabled()): ?> +
      • setObject($this->getAddress())->toHtml() ?>
      • + + + +
      +
      + + + +
      -

      __('Login Information') ?>

      +

      __('Password Information') ?>

      • @@ -179,6 +123,16 @@
      • getChildHtml('form.additional.info') ?> getChildHtml('remember.me') ?> + isNewsletterEnabled()): ?> +
      • +
        + getFormData()->getIsSubscribed()): ?> checked="checked" class="checkbox" /> +
        + + + getChildHtml('customer.form.register.newsletter') ?> +
      • +
      @@ -193,7 +147,7 @@ //getShowAddressFields()): ?> - new RegionUpdater('country', 'region', 'region_id', getRegionJsonByStore() ?>, undefined, 'zip'); + new RegionUpdater('country_id', 'region', 'region_id', getRegionJsonByStore() ?>, undefined, 'postcode'); //]]> From 30b13107f9a80e2b19ab99c3b146c360bbdad186 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 22 Oct 2024 05:56:39 -0700 Subject: [PATCH 069/113] Created new Mage_Eav_Block_Widget_Form in the spirit of Mage_Adminhtml_Block_Widget_Form --- .../Mage/Checkout/Block/Onepage/Billing.php | 75 ++++--- .../core/Mage/Customer/Block/Address/Edit.php | 56 +++-- .../core/Mage/Customer/Block/Form/Edit.php | 24 ++- .../Mage/Customer/Block/Form/Register.php | 154 +++++++------- .../Mage/Customer/Block/Widget/Abstract.php | 2 + .../core/Mage/Customer/Helper/Address.php | 65 ------ app/code/core/Mage/Customer/Helper/Data.php | 49 ----- app/code/core/Mage/Customer/Model/Form.php | 7 +- .../core/Mage/Eav/Block/Widget/Abstract.php | 81 -------- app/code/core/Mage/Eav/Block/Widget/Form.php | 195 ++++++++++++++++++ .../Block/Widget/Form/Element/Abstract.php | 96 +++++++++ .../Widget/{ => Form/Element}/Boolean.php | 14 +- .../Eav/Block/Widget/Form/Element/Country.php | 45 ++++ .../{ => Form/Element}/Customselect.php | 15 +- .../Block/Widget/{ => Form/Element}/Date.php | 42 ++-- .../Block/Widget/Form/Element/Fieldset.php | 59 ++++++ .../Widget/{ => Form/Element}/Hidden.php | 8 +- .../Widget/{ => Form/Element}/Multiline.php | 18 +- .../Widget/{ => Form/Element}/Multiselect.php | 10 +- .../Block/Widget/Form/Element/Postcode.php | 23 +++ .../Eav/Block/Widget/Form/Element/Region.php | 22 ++ .../Widget/{ => Form/Element}/Select.php | 8 +- .../Block/Widget/{ => Form/Element}/Text.php | 8 +- .../Widget/{ => Form/Element}/Textarea.php | 8 +- app/code/core/Mage/Eav/Model/Form.php | 15 ++ .../template/checkout/onepage/billing.phtml | 154 ++------------ .../template/customer/address/edit.phtml | 44 +--- .../default/template/customer/form/edit.phtml | 19 +- .../template/customer/form/register.phtml | 84 ++------ .../default/template/eav/widget/boolean.phtml | 23 --- .../template/eav/widget/customselect.phtml | 24 --- .../default/template/eav/widget/date.phtml | 49 ----- .../default/template/eav/widget/form.phtml | 12 ++ .../eav/widget/form/element/boolean.phtml | 20 ++ .../eav/widget/form/element/country.phtml | 15 ++ .../widget/form/element/customselect.phtml | 20 ++ .../eav/widget/form/element/date.phtml | 52 +++++ .../eav/widget/form/element/fieldset.phtml | 25 +++ .../eav/widget/form/element/hidden.phtml | 15 ++ .../widget/{ => form/element}/multiline.phtml | 6 +- .../eav/widget/form/element/multiselect.phtml | 20 ++ .../eav/widget/form/element/postcode.phtml | 15 ++ .../eav/widget/form/element/region.phtml | 18 ++ .../eav/widget/form/element/select.phtml | 20 ++ .../eav/widget/form/element/text.phtml | 15 ++ .../eav/widget/form/element/textarea.phtml | 15 ++ .../default/template/eav/widget/hidden.phtml | 17 -- .../template/eav/widget/multiselect.phtml | 23 --- .../default/template/eav/widget/select.phtml | 23 --- .../default/template/eav/widget/text.phtml | 17 -- .../template/eav/widget/textarea.phtml | 17 -- .../skin/frontend/rwd/default/css/styles.css | 10 + 52 files changed, 1024 insertions(+), 847 deletions(-) delete mode 100644 app/code/core/Mage/Eav/Block/Widget/Abstract.php create mode 100644 app/code/core/Mage/Eav/Block/Widget/Form.php create mode 100644 app/code/core/Mage/Eav/Block/Widget/Form/Element/Abstract.php rename app/code/core/Mage/Eav/Block/Widget/{ => Form/Element}/Boolean.php (50%) create mode 100644 app/code/core/Mage/Eav/Block/Widget/Form/Element/Country.php rename app/code/core/Mage/Eav/Block/Widget/{ => Form/Element}/Customselect.php (63%) rename app/code/core/Mage/Eav/Block/Widget/{ => Form/Element}/Date.php (66%) create mode 100644 app/code/core/Mage/Eav/Block/Widget/Form/Element/Fieldset.php rename app/code/core/Mage/Eav/Block/Widget/{ => Form/Element}/Hidden.php (59%) rename app/code/core/Mage/Eav/Block/Widget/{ => Form/Element}/Multiline.php (75%) rename app/code/core/Mage/Eav/Block/Widget/{ => Form/Element}/Multiselect.php (64%) create mode 100644 app/code/core/Mage/Eav/Block/Widget/Form/Element/Postcode.php create mode 100644 app/code/core/Mage/Eav/Block/Widget/Form/Element/Region.php rename app/code/core/Mage/Eav/Block/Widget/{ => Form/Element}/Select.php (66%) rename app/code/core/Mage/Eav/Block/Widget/{ => Form/Element}/Text.php (60%) rename app/code/core/Mage/Eav/Block/Widget/{ => Form/Element}/Textarea.php (59%) delete mode 100644 app/design/frontend/base/default/template/eav/widget/boolean.phtml delete mode 100644 app/design/frontend/base/default/template/eav/widget/customselect.phtml delete mode 100644 app/design/frontend/base/default/template/eav/widget/date.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/boolean.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/country.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/customselect.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/date.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/fieldset.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/hidden.phtml rename app/design/frontend/base/default/template/eav/widget/{ => form/element}/multiline.phtml (53%) create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/multiselect.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/postcode.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/region.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/select.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/text.phtml create mode 100644 app/design/frontend/base/default/template/eav/widget/form/element/textarea.phtml delete mode 100644 app/design/frontend/base/default/template/eav/widget/hidden.phtml delete mode 100644 app/design/frontend/base/default/template/eav/widget/multiselect.phtml delete mode 100644 app/design/frontend/base/default/template/eav/widget/select.phtml delete mode 100644 app/design/frontend/base/default/template/eav/widget/text.phtml delete mode 100644 app/design/frontend/base/default/template/eav/widget/textarea.phtml diff --git a/app/code/core/Mage/Checkout/Block/Onepage/Billing.php b/app/code/core/Mage/Checkout/Block/Onepage/Billing.php index 4db3d11a5..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 */ @@ -204,29 +254,4 @@ public function getTaxvatHtml() ->setFieldNameFormat('billing[%s]') ->toHtml(); } - - /** - * Return extra EAV fields used in this form - */ - public function getExtraCustomerFields(): array - { - return Mage::helper('customer')->getExtraFields('checkout_register'); - } - - /** - * Return extra EAV fields used in this form - */ - public function getExtraCustomerAddressFields(): array - { - return Mage::helper('customer/address')->getExtraFields('checkout_address_create'); - } - - /** - * Return extra EAV fields from incomplete checkout session - */ - public function getExtraFieldsSession(): Varien_Object - { - // TODO, need to separate from customer and customer address - return new Varien_Object($this->getCheckout()->getExtraFields()); - } } diff --git a/app/code/core/Mage/Customer/Block/Address/Edit.php b/app/code/core/Mage/Customer/Block/Address/Edit.php index f32543f16..9176debfe 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; /** * @inheritDoc @@ -62,10 +60,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() { @@ -125,19 +150,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() { @@ -211,12 +247,4 @@ public function getBackButtonUrl() return $this->getUrl('customer/account/'); } } - - /** - * Return all EAV fields used in this form as groups - */ - public function getGroupedFields(): array - { - return Mage::helper('customer/address')->getGroupedFields('customer_address_edit', $this->getAddress()); - } } diff --git a/app/code/core/Mage/Customer/Block/Form/Edit.php b/app/code/core/Mage/Customer/Block/Form/Edit.php index f296e3b65..45bdba43f 100644 --- a/app/code/core/Mage/Customer/Block/Form/Edit.php +++ b/app/code/core/Mage/Customer/Block/Form/Edit.php @@ -18,10 +18,28 @@ class Mage_Customer_Block_Form_Edit extends Mage_Customer_Block_Account_Dashboard { /** - * Return all EAV fields used in this form as groups + * Create form block for template file */ - public function getGroupedFields(): array + #[\Override] + protected function _beforeToHtml() { - return Mage::helper('customer')->getGroupedFields('customer_account_edit', $this->getCustomer()); + /** @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 1ca023b6f..97f080b6d 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 @@ -40,6 +40,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 * @@ -96,45 +136,21 @@ public function getFormData() } /** - * Retrieve customer country identifier - * - * @return int - */ - #[\Override] - public function getCountryId() - { - $countryId = $this->getFormData()->getCountryId(); - if ($countryId) { - return $countryId; - } - return parent::getCountryId(); - } - - /** - * Retrieve customer region identifier + * Restore entity data from session + * Entity and form code must be defined for the form * - * @return string|int|null + * @param string|null $scope + * @return $this */ - public function getRegion() + public function restoreSessionData(Mage_Customer_Model_Form $form, $scope = null) { - if (($region = $this->getFormData()->getRegion()) !== false) { - return $region; - } - - if (($region = $this->getFormData()->getRegionId()) !== false) { - return $region; + if ($this->getFormData()->getCustomerData()) { + $request = $form->prepareRequest($this->getFormData()->getData()); + $data = $form->extractData($request, $scope, false); + $form->restoreData($data); } - return null; - } - /** - * Newsletter module availability - * - * @return bool - */ - public function isNewsletterEnabled() - { - return Mage::helper('core')->isModuleOutputEnabled('Mage_Newsletter'); + return $this; } /** @@ -152,60 +168,56 @@ public function getAddress() } /** - * Restore entity data from session - * Entity and form code must be defined for the form - * - * @param string|null $scope - * @return $this + * @return string + * @deprecated */ - public function restoreSessionData(Mage_Customer_Model_Form $form, $scope = null) + public function getCountryId() { - if ($this->getFormData()->getCustomerData()) { - $request = $form->prepareRequest($this->getFormData()->getData()); - $data = $form->extractData($request, $scope, false); - $form->restoreData($data); + if ($countryId = $this->getFormData()->getCountryId()) { + return $countryId; } - - return $this; + return Mage::helper('core')->getDefaultCountry(); } /** - * Retrieve minimum length of customer password - * - * @return int + * @return string + * @deprecated */ - public function getMinPasswordLength() + public function getCountryHtmlSelect() { - return Mage::getModel('customer/customer')->getMinPasswordLength(); + return $this->getLayout()->createBlock('directory/data') + ->getCountryHtmlSelect($this->getCountryId()); } /** - * Return all EAV fields used in this form as groups + * @return string|int|null + * @deprecated */ - public function getGroupedFields(): array + public function getRegion() { - return Mage::helper('customer')->getGroupedFields('customer_account_create'); + if (($region = $this->getFormData()->getRegion()) !== false) { + return $region; + } + return null; } /** - * Return all EAV fields used in this form as groups + * Newsletter module availability + * + * @return bool */ - public function getGroupedFieldsAddress(): array + public function isNewsletterEnabled() { - $customerFields = $this->getGroupedFields(); - $addressFields = Mage::helper('customer/address')->getGroupedFields('customer_address_edit'); - - foreach ($addressFields as $group => $fields) { - foreach (array_keys($fields) as $code) { - if (isset($customerFields[$group][$code])) { - unset($addressFields[$group][$code]); - } - } - if (empty($addressFields[$group])) { - unset($addressFields[$group]); - } - } + return Mage::helper('core')->isModuleOutputEnabled('Mage_Newsletter'); + } - return $addressFields; + /** + * Retrieve minimum length of customer password + * + * @return int + */ + public function getMinPasswordLength() + { + return Mage::getModel('customer/customer')->getMinPasswordLength(); } } diff --git a/app/code/core/Mage/Customer/Block/Widget/Abstract.php b/app/code/core/Mage/Customer/Block/Widget/Abstract.php index 5de95d8bc..a1daece5c 100644 --- a/app/code/core/Mage/Customer/Block/Widget/Abstract.php +++ b/app/code/core/Mage/Customer/Block/Widget/Abstract.php @@ -17,6 +17,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 809f87e06..8a054e1d3 100644 --- a/app/code/core/Mage/Customer/Helper/Address.php +++ b/app/code/core/Mage/Customer/Helper/Address.php @@ -326,69 +326,4 @@ public function isVatAttributeVisible() { return Mage::getStoreConfigFlag(self::XML_PATH_VAT_FRONTEND_VISIBILITY); } - - /** - * Return all EAV fields used in customer forms as groups - */ - public function getGroupedFields(string $formCode, Mage_Customer_Model_Address|int|null $addressId = null): array - { - if ($addressId instanceof Mage_Customer_Model_Address) { - $address = $addressId; - } elseif (is_int($addressId)) { - /** @var Mage_Customer_Model_Customer $customer */ - $customer = Mage::getModel('customer/customer'); - $address = $customer->getAddressById($addressId); - } else { - $address = Mage::getModel('customer/address'); - } - - /** @var Mage_Customer_Model_Form $form */ - $form = Mage::getModel('customer/form'); - $form->setFormCode($formCode) - ->setEntity($address) - ->initDefaultValues(); - - $groups = []; - $attributes = $form->getAttributes(); - - foreach ($attributes as $code => $attribute) { - $group = $attribute->getAttributeGroupName() ?? 'General'; - $groups[$group] ??= []; - $groups[$group][$code] = $attribute; - } - - return $groups; - } - - /** - * Return extra EAV fields used in customer address forms - */ - public function getExtraFields(string $formCode, Mage_Customer_Model_Address|int|null $addressId = null): array - { - if ($addressId instanceof Mage_Customer_Model_Address) { - $address = $addressId; - } elseif (is_int($addressId)) { - /** @var Mage_Customer_Model_Customer $customer */ - $customer = Mage::getModel('customer/customer'); - $address = $customer->getAddressById($addressId); - } else { - $address = Mage::getModel('customer/address'); - } - - /** @var Mage_Customer_Model_Form $form */ - $form = Mage::getModel('customer/form'); - $form->setFormCode($formCode) - ->setEntity($address) - ->initDefaultValues(); - - $attributes = $form->getAttributes(); - - foreach ($attributes as $code => $attribute) { - if (!$attribute->getIsUserDefined()) { - unset($attributes[$code]); - } - } - - return $attributes; - } } diff --git a/app/code/core/Mage/Customer/Helper/Data.php b/app/code/core/Mage/Customer/Helper/Data.php index 954bae748..8a1d54f5b 100644 --- a/app/code/core/Mage/Customer/Helper/Data.php +++ b/app/code/core/Mage/Customer/Helper/Data.php @@ -741,53 +741,4 @@ protected function _getCountryCodeForVatNumber(string $countryCode): string return $countryCode === 'GR' ? 'EL' : $countryCode; } - - /** - * Return all EAV fields used in customer forms as groups - */ - public function getGroupedFields(string $formCode, ?Mage_Customer_Model_Customer $customer = null): array - { - $customer ??= Mage::getModel('customer/customer'); - - /** @var Mage_Customer_Model_Form $form */ - $form = Mage::getModel('customer/form'); - $form->setFormCode($formCode) - ->setEntity($customer) - ->initDefaultValues(); - - $groups = []; - $attributes = $form->getAttributes(); - - foreach ($attributes as $code => $attribute) { - $group = $attribute->getAttributeGroupName() ?? 'General'; - $groups[$group] ??= []; - $groups[$group][$code] = $attribute; - } - - return $groups; - } - - /** - * Return extra EAV fields used in customer forms - */ - public function getExtraFields(string $formCode, ?Mage_Customer_Model_Customer $customer = null): array - { - $customer ??= Mage::getModel('customer/customer'); - - /** @var Mage_Customer_Model_Form $form */ - $form = Mage::getModel('customer/form'); - $form->setFormCode($formCode) - ->setEntity($customer) - ->initDefaultValues(); - - $attributes = $form->getAttributes(); - - foreach ($attributes as $code => $attribute) { - if (!$attribute->getIsUserDefined()) { - unset($attributes[$code]); - } - } - - return $attributes; - } } diff --git a/app/code/core/Mage/Customer/Model/Form.php b/app/code/core/Mage/Customer/Model/Form.php index e6e87734d..682c877c6 100644 --- a/app/code/core/Mage/Customer/Model/Form.php +++ b/app/code/core/Mage/Customer/Model/Form.php @@ -44,14 +44,15 @@ protected function _getFormAttributeCollection() $collection = parent::_getFormAttributeCollection() ->addFieldToFilter('ea.attribute_code', ['neq' => 'created_at']); - $entity = $this->getEntity(); $attributeSetId = null; + $entity = $this->getEntity(); + $entityTypeCode = $this->getEntityType()->getEntityTypeCode(); - if ($entity instanceof Mage_Customer_Model_Customer) { + if ($entityTypeCode === 'customer') { $group = Mage::getModel('customer/group') ->load($entity->getGroupId()); $attributeSetId = $group->getCustomerAttributeSetId(); - } elseif ($entity instanceof Mage_Customer_Model_Address) { + } elseif ($entityTypeCode === 'customer_address') { $customer = $entity->getCustomer(); if ($customer) { $group = Mage::getModel('customer/group') diff --git a/app/code/core/Mage/Eav/Block/Widget/Abstract.php b/app/code/core/Mage/Eav/Block/Widget/Abstract.php deleted file mode 100644 index 84bc45fc1..000000000 --- a/app/code/core/Mage/Eav/Block/Widget/Abstract.php +++ /dev/null @@ -1,81 +0,0 @@ -getAttribute()->getIsVisible(); - } - - /** - * Check if attribute marked as required - * - * @return bool - */ - public function isRequired() - { - return (bool)$this->getAttribute()->getIsRequired(); - } - - /** - * @return string - */ - public function getFieldIdFormat() - { - if (!$this->hasData('field_id_format')) { - $this->setData('field_id_format', '%s'); - } - return $this->getData('field_id_format'); - } - - /** - * @return string - */ - public function getFieldNameFormat() - { - if (!$this->hasData('field_name_format')) { - $this->setData('field_name_format', '%s'); - } - return $this->getData('field_name_format'); - } - - /** - * @param string $field - * @return string - */ - public function getFieldId($field) - { - return sprintf($this->getFieldIdFormat(), $field); - } - - /** - * @param string $field - * @return string - */ - public function getFieldName($field) - { - return sprintf($this->getFieldNameFormat(), $field); - } -} 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..65e4ebc9e --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form.php @@ -0,0 +1,195 @@ +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) { + $this->attributes[$code] ??= $attribute; + } + } + + 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->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/Boolean.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Boolean.php similarity index 50% rename from app/code/core/Mage/Eav/Block/Widget/Boolean.php rename to app/code/core/Mage/Eav/Block/Widget/Form/Element/Boolean.php index 556c81cc1..53ebdf984 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Boolean.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Boolean.php @@ -4,32 +4,28 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Block to render boolean attribute - * - * @category Mage - * @package Mage_Eav */ -class Mage_Eav_Block_Widget_Boolean extends Mage_Eav_Block_Widget_Abstract +class Mage_Eav_Block_Widget_Form_Element_Boolean extends Mage_Eav_Block_Widget_Form_Element_Abstract { #[\Override] public function _construct() { parent::_construct(); - $this->setTemplate('eav/widget/boolean.phtml'); + $this->setTemplate('eav/widget/form/element/boolean.phtml'); } public function getOptions(): array { $options = [ - ['value' => '', 'label' => Mage::helper('eav')->__('')], - ['value' => '1', 'label' => Mage::helper('eav')->__('Yes')], - ['value' => '0', 'label' => Mage::helper('eav')->__('No')] + ['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/Customselect.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Customselect.php similarity index 63% rename from app/code/core/Mage/Eav/Block/Widget/Customselect.php rename to app/code/core/Mage/Eav/Block/Widget/Form/Element/Customselect.php index b4eb65b2c..ba38974bb 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Customselect.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Customselect.php @@ -4,29 +4,25 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Block to render select with custom option attribute - * - * @category Mage - * @package Mage_Eav */ -class Mage_Eav_Block_Widget_Customselect extends Mage_Eav_Block_Widget_Abstract +class Mage_Eav_Block_Widget_Form_Element_Customselect extends Mage_Eav_Block_Widget_Form_Element_Abstract { #[\Override] public function _construct() { parent::_construct(); - $this->setTemplate('eav/widget/customselect.phtml'); + $this->setTemplate('eav/widget/form/element/customselect.phtml'); } public function getOptions(): array { - return $this->getAttribute()->getSource()->getAllOptions(); + return $this->getAttribute()->getSource()->getAllOptions(false); } public function getDatalistIdFormat(): string @@ -37,8 +33,9 @@ public function getDatalistIdFormat(): string return $this->getData('datalist_id_format'); } - public function getDatalistId(string $field): string + public function getDatalistId(?string $attributeCode = null): string { - return sprintf($this->getDatalistIdFormat(), $field); + $fieldName = $attributeCode ?? $this->fieldName ?? $this->getAttribute()->getAttributeCode(); + return sprintf($this->getDatalistIdFormat(), $fieldName); } } diff --git a/app/code/core/Mage/Eav/Block/Widget/Date.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Date.php similarity index 66% rename from app/code/core/Mage/Eav/Block/Widget/Date.php rename to app/code/core/Mage/Eav/Block/Widget/Form/Element/Date.php index 26e031305..64dc02b18 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Date.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Date.php @@ -5,15 +5,16 @@ * @category Mage * @package Mage_Eav * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) + * @copyright Copyright (c) 2020-2023 The OpenMage Contributors (https://www.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) */ /** - * @method string getTime() + * @method DateTime getTime() * @method $this setTime(string $value) */ -class Mage_Eav_Block_Widget_Date extends Mage_Eav_Block_Widget_Abstract +class Mage_Eav_Block_Widget_Form_Element_Date extends Mage_Eav_Block_Widget_Form_Element_Abstract { /** * @var array @@ -24,9 +25,7 @@ class Mage_Eav_Block_Widget_Date extends Mage_Eav_Block_Widget_Abstract public function _construct() { parent::_construct(); - - // default template location - $this->setTemplate('eav/widget/date.phtml'); + $this->setTemplate('eav/widget/form/element/date.phtml'); } /** @@ -35,33 +34,50 @@ public function _construct() */ public function setDate($date) { - $this->setTime($date ? strtotime($date) : false); + if ($date) { + try { + $dateTime = new DateTime($date); + $this->setTime($dateTime); + } catch (Exception $e) { + Mage::logException($e); + } + } + $this->setData('date', $date); + return $this; } /** - * @return false|string + * @return bool + */ + public function hasTime() + { + return $this->getTime() instanceof DateTime; + } + + /** + * @return string */ public function getDay() { - return $this->getTime() ? date('d', $this->getTime()) : ''; + return $this->hasTime() ? $this->getTime()->format('d') : ''; } /** - * @return false|string + * @return string */ public function getMonth() { - return $this->getTime() ? date('m', $this->getTime()) : ''; + return $this->hasTime() ? $this->getTime()->format('m') : ''; } /** - * @return false|string + * @return string */ public function getYear() { - return $this->getTime() ? date('Y', $this->getTime()) : ''; + return $this->hasTime() ? $this->getTime()->format('Y') : ''; } /** @@ -82,7 +98,7 @@ public function getDateFormat() */ public function setDateInput($code, $html) { - $this->_dateInputs[$code] = $html; + $this->_dateInputs[$code] = $html . "\n"; } /** 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..ba86423a6 --- /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/Hidden.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Hidden.php similarity index 59% rename from app/code/core/Mage/Eav/Block/Widget/Hidden.php rename to app/code/core/Mage/Eav/Block/Widget/Form/Element/Hidden.php index fe0e65771..ae9a9fd6b 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Hidden.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Hidden.php @@ -4,23 +4,19 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Block to render hidden attribute - * - * @category Mage - * @package Mage_Eav */ -class Mage_Eav_Block_Widget_Hidden extends Mage_Eav_Block_Widget_Abstract +class Mage_Eav_Block_Widget_Form_Element_Hidden extends Mage_Eav_Block_Widget_Form_Element_Abstract { #[\Override] public function _construct() { parent::_construct(); - $this->setTemplate('eav/widget/hidden.phtml'); + $this->setTemplate('eav/widget/form/element/hidden.phtml'); } } diff --git a/app/code/core/Mage/Eav/Block/Widget/Multiline.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiline.php similarity index 75% rename from app/code/core/Mage/Eav/Block/Widget/Multiline.php rename to app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiline.php index 46971c272..cf703348d 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Multiline.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiline.php @@ -4,24 +4,20 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Block to render multiline attribute - * - * @category Mage - * @package Mage_Eav */ -class Mage_Eav_Block_Widget_Multiline extends Mage_Eav_Block_Widget_Abstract +class Mage_Eav_Block_Widget_Form_Element_Multiline extends Mage_Eav_Block_Widget_Form_Element_Abstract { #[\Override] public function _construct() { parent::_construct(); - $this->setTemplate('eav/widget/multiline.phtml'); + $this->setTemplate('eav/widget/form/element/multiline.phtml'); } public function getFields(): array @@ -38,13 +34,15 @@ public function getFields(): array $field->setValue($values[$i - 1] ?? null); if ($i === 1) { - $field->setStoreLabel($attribute->getStoreLabel()); - $field->setClass($attribute->getFrontend()->getClass()); $field->setIsRequired($this->isRequired()); + $field->setClass($attribute->getFrontend()->getClass()); + $field->setLabel($this->__($attribute->getStoreLabel())); + $field->setLabelClass($this->isRequired()); } else { - $field->setStoreLabel($attribute->getStoreLabel() . ' %s'); - $field->setClass(trim(str_replace('required-entry', '', $attribute->getFrontend()->getClass()))); $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; } diff --git a/app/code/core/Mage/Eav/Block/Widget/Multiselect.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiselect.php similarity index 64% rename from app/code/core/Mage/Eav/Block/Widget/Multiselect.php rename to app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiselect.php index 0c62eba16..9128106d6 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Multiselect.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Multiselect.php @@ -4,24 +4,20 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * Block to render select attribute - * - * @category Mage - * @package Mage_Eav + * Block to render multiselect attribute */ -class Mage_Eav_Block_Widget_Multiselect extends Mage_Eav_Block_Widget_Abstract +class Mage_Eav_Block_Widget_Form_Element_Multiselect extends Mage_Eav_Block_Widget_Form_Element_Abstract { #[\Override] public function _construct() { parent::_construct(); - $this->setTemplate('eav/widget/multiselect.phtml'); + $this->setTemplate('eav/widget/form/element/multiselect.phtml'); } public function getFieldParams(): string 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..8751fb2ef --- /dev/null +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Region.php @@ -0,0 +1,22 @@ +setTemplate('eav/widget/form/element/region.phtml'); + } +} diff --git a/app/code/core/Mage/Eav/Block/Widget/Select.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Select.php similarity index 66% rename from app/code/core/Mage/Eav/Block/Widget/Select.php rename to app/code/core/Mage/Eav/Block/Widget/Form/Element/Select.php index 7d76cd5bf..67469ba56 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Select.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Select.php @@ -4,24 +4,20 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Block to render select attribute - * - * @category Mage - * @package Mage_Eav */ -class Mage_Eav_Block_Widget_Select extends Mage_Eav_Block_Widget_Abstract +class Mage_Eav_Block_Widget_Form_Element_Select extends Mage_Eav_Block_Widget_Form_Element_Abstract { #[\Override] public function _construct() { parent::_construct(); - $this->setTemplate('eav/widget/select.phtml'); + $this->setTemplate('eav/widget/form/element/select.phtml'); } public function getOptions(): array diff --git a/app/code/core/Mage/Eav/Block/Widget/Text.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Text.php similarity index 60% rename from app/code/core/Mage/Eav/Block/Widget/Text.php rename to app/code/core/Mage/Eav/Block/Widget/Form/Element/Text.php index 34b97e0a1..4cdd692a0 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Text.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Text.php @@ -4,23 +4,19 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Block to render textfield attribute - * - * @category Mage - * @package Mage_Eav */ -class Mage_Eav_Block_Widget_Text extends Mage_Eav_Block_Widget_Abstract +class Mage_Eav_Block_Widget_Form_Element_Text extends Mage_Eav_Block_Widget_Form_Element_Abstract { #[\Override] public function _construct() { parent::_construct(); - $this->setTemplate('eav/widget/text.phtml'); + $this->setTemplate('eav/widget/form/element/text.phtml'); } } diff --git a/app/code/core/Mage/Eav/Block/Widget/Textarea.php b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Textarea.php similarity index 59% rename from app/code/core/Mage/Eav/Block/Widget/Textarea.php rename to app/code/core/Mage/Eav/Block/Widget/Form/Element/Textarea.php index 335d37f53..6465a4783 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Textarea.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Textarea.php @@ -4,23 +4,19 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Block to render textarea attribute - * - * @category Mage - * @package Mage_Eav */ -class Mage_Eav_Block_Widget_Textarea extends Mage_Eav_Block_Widget_Abstract +class Mage_Eav_Block_Widget_Form_Element_Textarea extends Mage_Eav_Block_Widget_Form_Element_Abstract { #[\Override] public function _construct() { parent::_construct(); - $this->setTemplate('eav/widget/textarea.phtml'); + $this->setTemplate('eav/widget/form/element/textarea.phtml'); } } 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/design/frontend/base/default/template/checkout/onepage/billing.phtml b/app/design/frontend/base/default/template/checkout/onepage/billing.phtml index 5cf19a8ec..39560eed1 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,140 +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') ?> -
          -
          -
        • -
        • -
          - -
          - -
          -
          -
          - -
          - -
          -
          -
        • - - getExtraCustomerAddressFields() as $_code => $_attribute): ?> - getFrontendInput() ?> - getLayout()->createBlock($_block)->setData('attribute', $_attribute)->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]') ?> - isEnabled()): ?> -
        • setObject($this->getExtraFieldsSession())->toHtml() ?>
        • - - - - 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() ?> -
          - -
        • - - - isTaxvatEnabled()):?> -
        • getTaxvatHtml() ?>
        • - + getChildHtml('form_checkout_address_create') ?> - getExtraCustomerFields() as $_code => $_attribute): ?> - getFrontendInput() ?> - getLayout()->createBlock($_block)->setData('attribute', $_attribute)->setFieldIdFormat('billing:%s')->setFieldNameFormat('billing[%s]') ?> - isEnabled()): ?> -
        • setObject($this->getExtraFieldsSession())->toHtml() ?>
        • - - +
          +
            + isCustomerLoggedIn()): ?>
          • @@ -182,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 9d7e2b593..d1a70cce0 100644 --- a/app/design/frontend/base/default/template/customer/address/edit.phtml +++ b/app/design/frontend/base/default/template/customer/address/edit.phtml @@ -28,42 +28,7 @@ -getGroupedFields() ?> - $_group): ?> -
          -

          __($_group) ?>

          - -

          __('* Required Fields') ?>

          - -
            - $_attribute): ?> - - -
          • -
            - -
            - - - -
            -
            -
          • - - getFrontendInput() ?> - getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> - isEnabled()): ?> -
          • setObject($this->getAddress())->toHtml() ?>
          • - - - -
          -
          - + getChildHtml('form_customer_address_edit') ?>
            @@ -89,10 +54,11 @@
          - +
          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 706d8995b..d13d561bd 100644 --- a/app/design/frontend/base/default/template/customer/form/edit.phtml +++ b/app/design/frontend/base/default/template/customer/form/edit.phtml @@ -17,24 +17,7 @@
          getBlockHtml('formkey') ?> -getGroupedFields() ?> - $_group): ?> -
          -

          __($_group) ?>

          - -

          __('* Required Fields') ?>

          - -
            - $_attribute): ?> - getFrontendInput() ?> - getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> - isEnabled()): ?> -
          • setObject($this->getCustomer())->toHtml() ?>
          • - - -
          -
          - + getChildHtml('form_customer_account_edit') ?>

          __('Password Information') ?>

          diff --git a/app/design/frontend/base/default/template/customer/form/register.phtml b/app/design/frontend/base/default/template/customer/form/register.phtml index 6350f0395..e7cf5fb01 100644 --- a/app/design/frontend/base/default/template/customer/form/register.phtml +++ b/app/design/frontend/base/default/template/customer/form/register.phtml @@ -30,70 +30,7 @@ - - getGroupedFields() ?> - $_group): ?> -
          -

          __($_group) ?>

          - -

          __('* Required Fields') ?>

          - -
            - $_attribute): ?> - getFrontendInput() ?> - getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> - isEnabled()): ?> -
          • setObject($this->getFormData())->toHtml() ?>
          • - - -
          -
          - - - getShowAddressFields()): ?> - - - - - -getGroupedFieldsAddress() ?> - $_group): ?> -
          -

          __($_group) ?>

          - -

          __('* Required Fields') ?>

          - -
            - $_attribute): ?> - - -
          • -
            - -
            - - - -
            -
            -
          • - - getFrontendInput() ?> - getLayout()->createBlock($_block)->setData('attribute', $_attribute) ?> - isEnabled()): ?> -
          • setObject($this->getAddress())->toHtml() ?>
          • - - - -
          -
          - - - + getChildHtml('form_customer_account_create') ?>

          __('Password Information') ?>

          @@ -139,16 +76,21 @@
          - isContextCheckout()): ?> - - + + getShowAddressFields()): ?> + + + + + isContextCheckout()): ?> + +
          diff --git a/app/design/frontend/base/default/template/eav/widget/boolean.phtml b/app/design/frontend/base/default/template/eav/widget/boolean.phtml deleted file mode 100644 index 47b67f725..000000000 --- a/app/design/frontend/base/default/template/eav/widget/boolean.phtml +++ /dev/null @@ -1,23 +0,0 @@ - -getAttribute() ?> -getAttributeCode() ?> - -
          - -
          diff --git a/app/design/frontend/base/default/template/eav/widget/customselect.phtml b/app/design/frontend/base/default/template/eav/widget/customselect.phtml deleted file mode 100644 index 8e6c03ea9..000000000 --- a/app/design/frontend/base/default/template/eav/widget/customselect.phtml +++ /dev/null @@ -1,24 +0,0 @@ - -getAttribute() ?> -getAttributeCode() ?> - -
          - getFieldParams() ?> /> - - getOptions() ?> - getObject()->getData($_code) ?> - - - - -
          diff --git a/app/design/frontend/base/default/template/eav/widget/date.phtml b/app/design/frontend/base/default/template/eav/widget/date.phtml deleted file mode 100644 index 921971e33..000000000 --- a/app/design/frontend/base/default/template/eav/widget/date.phtml +++ /dev/null @@ -1,49 +0,0 @@ - -getAttribute() ?> -getAttributeCode() ?> - -
          -setDateInput('d', - '
          - getFieldParams() . ' /> - -
          ' - ); - - $this->setDateInput('m', - '
          - getFieldParams() . ' /> - -
          ' - ); - - $this->setDateInput('y', - '
          - getFieldParams() . ' /> - -
          ' - ); -?> - getSortedDateInputs() ?> - - - -
          - diff --git a/app/design/frontend/base/default/template/eav/widget/form.phtml b/app/design/frontend/base/default/template/eav/widget/form.phtml new file mode 100644 index 000000000..1460370fe --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form.phtml @@ -0,0 +1,12 @@ + +getChildHtml() ?> diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/boolean.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/boolean.phtml new file mode 100644 index 000000000..0875736d4 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/boolean.phtml @@ -0,0 +1,20 @@ + +getValue() ?> + +
          + +
          diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/country.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/country.phtml new file mode 100644 index 000000000..a92c7632a --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/country.phtml @@ -0,0 +1,15 @@ + + +
          + getCountryHtmlSelect() ?> +
          diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/customselect.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/customselect.phtml new file mode 100644 index 000000000..50c4269a6 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/customselect.phtml @@ -0,0 +1,20 @@ + + +
          + getFieldParams() ?> /> + + getOptions() as $option): ?> + + + +
          diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml new file mode 100644 index 000000000..03c3c73ba --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml @@ -0,0 +1,52 @@ + + +
          +setDateInput('d', << + getFieldParams()} /> +
          + HTML); + + $this->setDateInput('m', << + getFieldParams()} /> +
        + HTML); + + $this->setDateInput('y', << + getFieldParams()} /> +
      + 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..000611d5a --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/fieldset.phtml @@ -0,0 +1,25 @@ + +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..0ce4a4f82 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/hidden.phtml @@ -0,0 +1,15 @@ + + +
      + getFieldParams() ?> /> +
      diff --git a/app/design/frontend/base/default/template/eav/widget/multiline.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/multiline.phtml similarity index 53% rename from app/design/frontend/base/default/template/eav/widget/multiline.phtml rename to app/design/frontend/base/default/template/eav/widget/form/element/multiline.phtml index 57beab5eb..35fbd5d63 100644 --- a/app/design/frontend/base/default/template/eav/widget/multiline.phtml +++ b/app/design/frontend/base/default/template/eav/widget/form/element/multiline.phtml @@ -9,11 +9,11 @@ * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> -getFields() as $_i => $_field): ?> +getFields() as $_field): ?>
      - +
      - getFieldParams() ?> /> + 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..8ad4eaa49 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/multiselect.phtml @@ -0,0 +1,20 @@ + +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..9ebba227e --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/postcode.phtml @@ -0,0 +1,15 @@ + + +
      + 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..2caaf7548 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/region.phtml @@ -0,0 +1,18 @@ + + +
      + + 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..0875736d4 --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/select.phtml @@ -0,0 +1,20 @@ + +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..1e044833c --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/text.phtml @@ -0,0 +1,15 @@ + + +
      + 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..08f83633c --- /dev/null +++ b/app/design/frontend/base/default/template/eav/widget/form/element/textarea.phtml @@ -0,0 +1,15 @@ + + +
      + +
      diff --git a/app/design/frontend/base/default/template/eav/widget/hidden.phtml b/app/design/frontend/base/default/template/eav/widget/hidden.phtml deleted file mode 100644 index 803e2a2e1..000000000 --- a/app/design/frontend/base/default/template/eav/widget/hidden.phtml +++ /dev/null @@ -1,17 +0,0 @@ - -getAttribute() ?> -getAttributeCode() ?> - -
      - getFieldParams() ?> /> -
      diff --git a/app/design/frontend/base/default/template/eav/widget/multiselect.phtml b/app/design/frontend/base/default/template/eav/widget/multiselect.phtml deleted file mode 100644 index 6989e008c..000000000 --- a/app/design/frontend/base/default/template/eav/widget/multiselect.phtml +++ /dev/null @@ -1,23 +0,0 @@ - -getAttribute() ?> -getAttributeCode() ?> - -
      - -
      diff --git a/app/design/frontend/base/default/template/eav/widget/select.phtml b/app/design/frontend/base/default/template/eav/widget/select.phtml deleted file mode 100644 index 47b67f725..000000000 --- a/app/design/frontend/base/default/template/eav/widget/select.phtml +++ /dev/null @@ -1,23 +0,0 @@ - -getAttribute() ?> -getAttributeCode() ?> - -
      - -
      diff --git a/app/design/frontend/base/default/template/eav/widget/text.phtml b/app/design/frontend/base/default/template/eav/widget/text.phtml deleted file mode 100644 index 8ea20e7e5..000000000 --- a/app/design/frontend/base/default/template/eav/widget/text.phtml +++ /dev/null @@ -1,17 +0,0 @@ - -getAttribute() ?> -getAttributeCode() ?> - -
      - getFieldParams() ?> /> -
      diff --git a/app/design/frontend/base/default/template/eav/widget/textarea.phtml b/app/design/frontend/base/default/template/eav/widget/textarea.phtml deleted file mode 100644 index bf81798a3..000000000 --- a/app/design/frontend/base/default/template/eav/widget/textarea.phtml +++ /dev/null @@ -1,17 +0,0 @@ - -getAttribute() ?> -getAttributeCode() ?> - -
      - -
      diff --git a/public/skin/frontend/rwd/default/css/styles.css b/public/skin/frontend/rwd/default/css/styles.css index 34cce7174..763a232d9 100644 --- a/public/skin/frontend/rwd/default/css/styles.css +++ b/public/skin/frontend/rwd/default/css/styles.css @@ -2317,6 +2317,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, From ef361ed2ecc775fbf09c07f183abaa5748005ec7 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 23 Oct 2024 13:32:21 -0700 Subject: [PATCH 070/113] phpstan --- .phpstan.baseline.neon | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/.phpstan.baseline.neon b/.phpstan.baseline.neon index b94e7fdac..3bc1ea8b8 100644 --- a/.phpstan.baseline.neon +++ b/.phpstan.baseline.neon @@ -2230,26 +2230,6 @@ parameters: count: 2 path: app/code/core/Mage/Customer/Block/Account/Navigation.php - - - message: "#^Method Mage_Customer_Block_Address_Edit\\:\\:getCountryId\\(\\) should return int but returns string\\.$#" - 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\\(\\)$#" - 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\\.$#" - count: 1 - path: app/code/core/Mage/Customer/Block/Form/Register.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\\(\\)$#" - count: 1 - path: app/code/core/Mage/Customer/Block/Form/Register.php - - message: "#^Method Mage_Customer_Block_Newsletter\\:\\:getAction\\(\\) should return Mage_Core_Controller_Varien_Action but returns string\\.$#" count: 1 From c94a43218c78a5bc9aa412d9eb2c7c76b4e82ca2 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 23 Oct 2024 13:37:24 -0700 Subject: [PATCH 071/113] Fix Varien.DateElement call, however value isn't saving, will investigate later --- .../base/default/template/eav/widget/form/element/date.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml index 03c3c73ba..9e9713dbf 100644 --- a/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml +++ b/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml @@ -47,6 +47,6 @@ full: el.querySelector('.date-full input'), advice: el.querySelector('.validation-advice') }; - new Varien.DateElementHelper('container', container, isRequired() ? 'true' : 'false' ?>, 'getDateFormat() ?>'); + new Varien.DateElement('container', container, isRequired() ? 'true' : 'false' ?>, 'getDateFormat() ?>'); })(); From c2db77b9f05116ae364c22c80f5702235b8b423d Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 23 Oct 2024 13:40:19 -0700 Subject: [PATCH 072/113] phpcs --- .../Block/Widget/Form/Element/Fieldset.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) 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 index ba86423a6..fba0c1216 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Fieldset.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Fieldset.php @@ -38,22 +38,22 @@ public function setType(string $type): self 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 [ - ['
        ', '
      '], - ['
    • ', '
    • '], - ]; + 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 [ + ['
        ', '
      '], + ['
    • ', '
    • '], + ]; } } } From 8663a04874f362a889a119c727fcee72ce054942 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Wed, 23 Oct 2024 14:17:41 -0700 Subject: [PATCH 073/113] Fieldset CSS spacing --- public/skin/frontend/rwd/default/css/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/skin/frontend/rwd/default/css/styles.css b/public/skin/frontend/rwd/default/css/styles.css index d51180d7d..e28d3d7d8 100644 --- a/public/skin/frontend/rwd/default/css/styles.css +++ b/public/skin/frontend/rwd/default/css/styles.css @@ -2082,7 +2082,7 @@ body.customer-account .data-table .show-details .summary-collapse:hover:before { } .fieldset + .fieldset { - margin-top: 5px; + margin-top: 30px; } form .legend { From cd09a2d45736fc42e25eead1447b24c798ef15fe Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 29 Oct 2024 06:04:02 -0700 Subject: [PATCH 074/113] Fix region select, support use of data attribute --- app/code/core/Mage/Eav/Block/Widget/Form/Element/Region.php | 5 +++++ .../default/template/eav/widget/form/element/region.phtml | 2 +- public/js/varien/form.js | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) 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 index 8751fb2ef..be4c535a5 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Form/Element/Region.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form/Element/Region.php @@ -19,4 +19,9 @@ public function _construct() parent::_construct(); $this->setTemplate('eav/widget/form/element/region.phtml'); } + + public function getRegionId(): int + { + return $this->getObject()->getRegionId(); + } } 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 index 2caaf7548..5da7d5940 100644 --- 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 @@ -11,7 +11,7 @@ ?>
      - isRequired() ? ' class="validate-select"' : '' ?> getFieldParams() ?> data-default-value="escapeHtml($this->getRegionId()) ?>" style="display:none;"> getFieldParams() ?> /> diff --git a/public/js/varien/form.js b/public/js/varien/form.js index 51333f57b..3b285aafc 100644 --- a/public/js/varien/form.js +++ b/public/js/varien/form.js @@ -203,7 +203,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(); @@ -363,4 +363,4 @@ class ZipUpdater { } } } -} \ No newline at end of file +} From f6bf9923241b17ed06f298b8659460ea6d7eb028 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 29 Oct 2024 06:22:05 -0700 Subject: [PATCH 075/113] Fix date input --- .../base/default/template/eav/widget/form/element/date.phtml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml b/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml index 9e9713dbf..ba3f67ad6 100644 --- a/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml +++ b/app/design/frontend/base/default/template/eav/widget/form/element/date.phtml @@ -12,6 +12,8 @@
      setDate($this->getValue()); + $this->setDateInput('d', << getFieldParams()} /> From 0f587b6915c84e9b5c65ccbde4c049a441dfd4bc Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 29 Oct 2024 07:16:45 -0700 Subject: [PATCH 076/113] Allow set attribute set for not logged in customer --- .../Block/Customer/Group/Edit/Form.php | 55 +++++++++---------- .../controllers/Customer/GroupController.php | 44 ++++++--------- 2 files changed, 43 insertions(+), 56 deletions(-) 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 de4eac53d..e060f21a5 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 @@ -64,38 +64,35 @@ protected function _prepareLayout() ] ); - // show attribute set fields for all groups except not logged in - if (is_null($customerGroup->getId()) || (int)$customerGroup->getId() !== Mage_Customer_Model_Group::NOT_LOGGED_IN_ID) { - $setsCustomer = Mage::getResourceModel('eav/entity_attribute_set_collection') - ->setEntityTypeFilter(Mage::getResourceModel('customer/customer')->getEntityType()->getId()) - ->setOrder('attribute_set_name', 'asc') - ->load() - ->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 - ]); + $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(); + $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 - ]); - } + $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 diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php index dd6f7c96b..0744adb7e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php @@ -108,35 +108,25 @@ public function saveAction() $customerGroup->load((int)$id); } - // save these fields for all groups except not logged in - if (is_null($id) || (int)$id !== Mage_Customer_Model_Group::NOT_LOGGED_IN_ID) { - $customerGroup->setCode((string)$this->getRequest()->getParam('code')); - $customerGroup->setCustomerAttributeSetId((int)$this->getRequest()->getParam('customer_attribute_set')); - $customerGroup->setCustomerAddressAttributeSetId((int)$this->getRequest()->getParam('customer_address_attribute_set')); - } - - $taxClass = (int)$this->getRequest()->getParam('tax_class'); - - if ($taxClass) { - try { - $customerGroupCode = (string)$this->getRequest()->getParam('code'); + try { + $customerGroupCode = (string)$this->getRequest()->getParam('code'); - if (!empty($customerGroupCode)) { - $customerGroup->setCode($customerGroupCode); - } - - $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])); } } From be74bff93f7330a22b336613eded4df25321538a Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 29 Oct 2024 07:16:59 -0700 Subject: [PATCH 077/113] Move install script to maho_setup --- app/code/core/Mage/Customer/etc/config.xml | 2 +- .../maho-24.10.0.php} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename app/code/core/Mage/Customer/sql/{customer_setup/upgrade-1.6.2.0.7-1.6.2.0.8.php => maho_setup/maho-24.10.0.php} (95%) diff --git a/app/code/core/Mage/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index 0a266ec03..2c730c47a 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -13,7 +13,7 @@ - 1.6.2.0.8 + 1.6.2.0.7 diff --git a/app/code/core/Mage/Customer/sql/customer_setup/upgrade-1.6.2.0.7-1.6.2.0.8.php b/app/code/core/Mage/Customer/sql/maho_setup/maho-24.10.0.php similarity index 95% rename from app/code/core/Mage/Customer/sql/customer_setup/upgrade-1.6.2.0.7-1.6.2.0.8.php rename to app/code/core/Mage/Customer/sql/maho_setup/maho-24.10.0.php index 158bb0ba3..261dc6a78 100644 --- a/app/code/core/Mage/Customer/sql/customer_setup/upgrade-1.6.2.0.7-1.6.2.0.8.php +++ b/app/code/core/Mage/Customer/sql/maho_setup/maho-24.10.0.php @@ -17,7 +17,7 @@ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, 'unsigned' => true, 'nullable' => false, - 'default' => 0, + 'default' => 1, 'comment' => 'Customer Group Attribute Set ID', ]); @@ -26,7 +26,7 @@ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, 'unsigned' => true, 'nullable' => false, - 'default' => 0, + 'default' => 1, 'comment' => 'Customer Group Address Attribute Set ID', ]); From 23d6ab241a406b4b823e6690347c28b55e978acf Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 29 Oct 2024 13:10:04 -0700 Subject: [PATCH 078/113] Misc customer group edit changes --- .../Adminhtml/Block/Customer/Group/Edit.php | 2 +- .../Block/Customer/Group/Edit/Form.php | 54 ++++++++----------- .../controllers/Customer/GroupController.php | 7 ++- 3 files changed, 25 insertions(+), 38 deletions(-) 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 e060f21a5..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,35 +34,27 @@ 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()) @@ -96,14 +88,10 @@ protected function _prepareLayout() 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/controllers/Customer/GroupController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/GroupController.php index 0744adb7e..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(); } From 3ef4244a98d32b3faf4505fb052cc88bde6e6437 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 29 Oct 2024 13:42:58 -0700 Subject: [PATCH 079/113] Fix for using the correct object in merged forms --- app/code/core/Mage/Eav/Block/Widget/Form.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/Eav/Block/Widget/Form.php b/app/code/core/Mage/Eav/Block/Widget/Form.php index 65e4ebc9e..32de670b8 100644 --- a/app/code/core/Mage/Eav/Block/Widget/Form.php +++ b/app/code/core/Mage/Eav/Block/Widget/Form.php @@ -31,6 +31,7 @@ class Mage_Eav_Block_Widget_Form extends Mage_Core_Block_Template protected array $excludedForms = []; protected ?array $attributes = null; + protected array $attributeObjects = []; protected ?string $defaultLabel = null; protected string $groupMode = self::GROUP_MODE_ATTRIBUTE_SET; @@ -91,7 +92,10 @@ public function getAttributes(): array foreach ($this->mergedForms as $form) { foreach ($form->getAttributes() as $code => $attribute) { - $this->attributes[$code] ??= $attribute; + if (!isset($this->attributes[$code])) { + $this->attributes[$code] = $attribute; + $this->attributeObjects[$code] = $form->getEntity(); + } } } @@ -179,7 +183,7 @@ protected function _beforeToHtml() foreach ($attributes as $code => $attribute) { if ($element = $this->getFieldsetElementRenderer($attribute)) { $element->setData('attribute', $attribute); - $element->setObject($this->form->getEntity()); + $element->setObject($this->attributeObjects[$code] ?? $this->form->getEntity()); $element->setTranslationHelper($this->getTranslationHelper()); $element->setFieldIdFormat($this->getFieldIdFormat()); $element->setFieldNameFormat($this->getFieldNameFormat()); From 63e50345bb5db184eec74dcfe41feec786ee7243 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 29 Oct 2024 13:48:01 -0700 Subject: [PATCH 080/113] safer attribute set id getter --- .../core/Mage/Customer/Model/Customer.php | 32 ++++++++++++- app/code/core/Mage/Customer/Model/Form.php | 20 +++----- app/code/core/Mage/Customer/Model/Group.php | 47 +++++++++++++++++-- .../Customer/sql/maho_setup/maho-24.10.0.php | 4 +- 4 files changed, 82 insertions(+), 21 deletions(-) diff --git a/app/code/core/Mage/Customer/Model/Customer.php b/app/code/core/Mage/Customer/Model/Customer.php index 9f32136cf..956038d55 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) * @@ -942,6 +944,34 @@ public function getTaxClassId() return $this->getData('tax_class_id'); } + /** + * Retrieve customer attribute set identifier + * + * @return int + * @throws Mage_Core_Model_Store_Exception + */ + 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 + * @throws Mage_Core_Model_Store_Exception + */ + 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 * diff --git a/app/code/core/Mage/Customer/Model/Form.php b/app/code/core/Mage/Customer/Model/Form.php index 682c877c6..c9a9dedec 100644 --- a/app/code/core/Mage/Customer/Model/Form.php +++ b/app/code/core/Mage/Customer/Model/Form.php @@ -44,24 +44,18 @@ protected function _getFormAttributeCollection() $collection = parent::_getFormAttributeCollection() ->addFieldToFilter('ea.attribute_code', ['neq' => 'created_at']); - $attributeSetId = null; $entity = $this->getEntity(); $entityTypeCode = $this->getEntityType()->getEntityTypeCode(); + $attributeSetId = null; - if ($entityTypeCode === 'customer') { - $group = Mage::getModel('customer/group') - ->load($entity->getGroupId()); - $attributeSetId = $group->getCustomerAttributeSetId(); - } elseif ($entityTypeCode === 'customer_address') { - $customer = $entity->getCustomer(); - if ($customer) { - $group = Mage::getModel('customer/group') - ->load($customer->getGroupId()); - $attributeSetId = $group->getCustomerAddressAttributeSetId(); - } + if ($entityTypeCode === Mage_Customer_Model_Customer::ENTITY) { + $attributeSetId = $entity->getAttributeSetId(); + } elseif ($entityTypeCode === Mage_Customer_Model_Address::ENTITY) { + $customer = $entity->getCustomer() ?: Mage::getModel('customer/customer'); + $attributeSetId = $customer->getAddressAttributeSetId(); } - if (!is_null($attributeSetId) && $attributeSetId != 0) { + if ($attributeSetId !== null) { $collection->filterAttributeSet($attributeSetId); } diff --git a/app/code/core/Mage/Customer/Model/Group.php b/app/code/core/Mage/Customer/Model/Group.php index 0e492ab02..eae0f92a3 100644 --- a/app/code/core/Mage/Customer/Model/Group.php +++ b/app/code/core/Mage/Customer/Model/Group.php @@ -30,14 +30,17 @@ 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 DEFAULT_ATTRIBUTE_SET_ID = 1; + public const DEFAULT_ADDRESS_ATTRIBUTE_SET_ID = 1; - 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 @@ -56,6 +59,8 @@ class Mage_Customer_Model_Group extends Mage_Core_Model_Abstract protected $_eventObject = 'object'; protected static $_taxClassIds = []; + protected static $_attributeSetIds = []; + protected static $_addressAttributeSetIds = []; #[\Override] protected function _construct() @@ -100,6 +105,38 @@ public function getTaxClassId($groupId = null) return $this->getData('tax_class_id'); } + /** + * @param int|null $groupId + * @return int + */ + public function getCustomerAttributeSetId($groupId = null) + { + if (!is_null($groupId)) { + if (empty(self::$_attributeSetIds[$groupId])) { + $this->load($groupId); + self::$_attributeSetIds[$groupId] = $this->getData('customer_attribute_set_id'); + } + $this->setData('customer_attribute_set_id', self::$_attributeSetIds[$groupId]); + } + return $this->getData('customer_attribute_set_id') ?? self::DEFAULT_ATTRIBUTE_SET_ID; + } + + /** + * @param int|null $groupId + * @return int + */ + public function getCustomerAddressAttributeSetId($groupId = null) + { + if (!is_null($groupId)) { + if (empty(self::$_addressAttributeSetIds[$groupId])) { + $this->load($groupId); + self::$_addressAttributeSetIds[$groupId] = $this->getData('customer_address_attribute_set_id'); + } + $this->setData('customer_address_attribute_set_id', self::$_addressAttributeSetIds[$groupId]); + } + return $this->getData('customer_address_attribute_set_id') ?? self::DEFAULT_ADDRESS_ATTRIBUTE_SET_ID; + } + /** * @return bool */ 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 index 261dc6a78..8a5f245b3 100644 --- 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 @@ -17,7 +17,7 @@ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, 'unsigned' => true, 'nullable' => false, - 'default' => 1, + 'default' => Mage_Customer_Model_Group::DEFAULT_ATTRIBUTE_SET_ID, 'comment' => 'Customer Group Attribute Set ID', ]); @@ -26,7 +26,7 @@ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, 'unsigned' => true, 'nullable' => false, - 'default' => 1, + 'default' => Mage_Customer_Model_Group::DEFAULT_ADDRESS_ATTRIBUTE_SET_ID, 'comment' => 'Customer Group Address Attribute Set ID', ]); From d052306792ca7c20ec9988cab83fb9979e9d33af Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 29 Oct 2024 15:26:13 -0700 Subject: [PATCH 081/113] move some logic around --- app/code/core/Mage/Customer/Model/Address.php | 11 ++++++ .../core/Mage/Customer/Model/Customer.php | 3 -- app/code/core/Mage/Customer/Model/Form.php | 22 ++---------- app/code/core/Mage/Customer/Model/Group.php | 29 +++++----------- .../Mage/Customer/Model/Resource/Group.php | 34 +++++++++++++++++++ 5 files changed, 57 insertions(+), 42 deletions(-) diff --git a/app/code/core/Mage/Customer/Model/Address.php b/app/code/core/Mage/Customer/Model/Address.php index ad7334322..104929a44 100644 --- a/app/code/core/Mage/Customer/Model/Address.php +++ b/app/code/core/Mage/Customer/Model/Address.php @@ -90,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 956038d55..a71c5ec59 100644 --- a/app/code/core/Mage/Customer/Model/Customer.php +++ b/app/code/core/Mage/Customer/Model/Customer.php @@ -934,7 +934,6 @@ public function getGroupId() * Retrieve customer tax class identifier * * @return int - * @throws Mage_Core_Model_Store_Exception */ public function getTaxClassId() { @@ -948,7 +947,6 @@ public function getTaxClassId() * Retrieve customer attribute set identifier * * @return int - * @throws Mage_Core_Model_Store_Exception */ public function getAttributeSetId() { @@ -962,7 +960,6 @@ public function getAttributeSetId() * Retrieve customer address attribute set identifier * * @return int - * @throws Mage_Core_Model_Store_Exception */ public function getAddressAttributeSetId() { diff --git a/app/code/core/Mage/Customer/Model/Form.php b/app/code/core/Mage/Customer/Model/Form.php index c9a9dedec..e28f3fcd9 100644 --- a/app/code/core/Mage/Customer/Model/Form.php +++ b/app/code/core/Mage/Customer/Model/Form.php @@ -41,24 +41,8 @@ class Mage_Customer_Model_Form extends Mage_Eav_Model_Form #[\Override] protected function _getFormAttributeCollection() { - $collection = parent::_getFormAttributeCollection() - ->addFieldToFilter('ea.attribute_code', ['neq' => 'created_at']); - - $entity = $this->getEntity(); - $entityTypeCode = $this->getEntityType()->getEntityTypeCode(); - $attributeSetId = null; - - if ($entityTypeCode === Mage_Customer_Model_Customer::ENTITY) { - $attributeSetId = $entity->getAttributeSetId(); - } elseif ($entityTypeCode === Mage_Customer_Model_Address::ENTITY) { - $customer = $entity->getCustomer() ?: Mage::getModel('customer/customer'); - $attributeSetId = $customer->getAddressAttributeSetId(); - } - - if ($attributeSetId !== null) { - $collection->filterAttributeSet($attributeSetId); - } - - return $collection; + return parent::_getFormAttributeCollection() + ->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 eae0f92a3..bbde382a5 100644 --- a/app/code/core/Mage/Customer/Model/Group.php +++ b/app/code/core/Mage/Customer/Model/Group.php @@ -36,7 +36,7 @@ class Mage_Customer_Model_Group extends Mage_Core_Model_Abstract public const NOT_LOGGED_IN_ID = 0; public const DEFAULT_ATTRIBUTE_SET_ID = 1; - public const DEFAULT_ADDRESS_ATTRIBUTE_SET_ID = 1; + public const DEFAULT_ADDRESS_ATTRIBUTE_SET_ID = 2; public const CUST_GROUP_ALL = 32000; @@ -58,9 +58,8 @@ class Mage_Customer_Model_Group extends Mage_Core_Model_Abstract */ protected $_eventObject = 'object'; + /** @deprecated */ protected static $_taxClassIds = []; - protected static $_attributeSetIds = []; - protected static $_addressAttributeSetIds = []; #[\Override] protected function _construct() @@ -96,11 +95,9 @@ 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'); } @@ -112,13 +109,9 @@ public function getTaxClassId($groupId = null) public function getCustomerAttributeSetId($groupId = null) { if (!is_null($groupId)) { - if (empty(self::$_attributeSetIds[$groupId])) { - $this->load($groupId); - self::$_attributeSetIds[$groupId] = $this->getData('customer_attribute_set_id'); - } - $this->setData('customer_attribute_set_id', self::$_attributeSetIds[$groupId]); + return $this->getResource()->loadGroupTableData($groupId)['customer_attribute_set_id']; } - return $this->getData('customer_attribute_set_id') ?? self::DEFAULT_ATTRIBUTE_SET_ID; + return $this->getData('customer_attribute_set_id'); } /** @@ -128,13 +121,9 @@ public function getCustomerAttributeSetId($groupId = null) public function getCustomerAddressAttributeSetId($groupId = null) { if (!is_null($groupId)) { - if (empty(self::$_addressAttributeSetIds[$groupId])) { - $this->load($groupId); - self::$_addressAttributeSetIds[$groupId] = $this->getData('customer_address_attribute_set_id'); - } - $this->setData('customer_address_attribute_set_id', self::$_addressAttributeSetIds[$groupId]); + return $this->getResource()->loadGroupTableData($groupId)['customer_address_attribute_set_id']; } - return $this->getData('customer_address_attribute_set_id') ?? self::DEFAULT_ADDRESS_ATTRIBUTE_SET_ID; + return $this->getData('customer_address_attribute_set_id'); } /** diff --git a/app/code/core/Mage/Customer/Model/Resource/Group.php b/app/code/core/Mage/Customer/Model/Resource/Group.php index a31c1c9ad..72753a601 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() { @@ -41,6 +46,24 @@ protected function _initUniqueFields() return $this; } + /** + * Set default attribute set ids + * + * @return Mage_Core_Model_Resource_Db_Abstract + */ + #[\Override] + protected function _afterLoad(Mage_Core_Model_Abstract $group) + { + parent::_afterLoad($group); + if (!$group->hasData('customer_attribute_set_id')) { + $group->setData('customer_attribute_set_id', Mage_Customer_Model_Group::DEFAULT_ATTRIBUTE_SET_ID); + } + if (!$group->hasData('customer_address_attribute_set_id')) { + $group->setData('customer_address_attribute_set_id', Mage_Customer_Model_Group::DEFAULT_ADDRESS_ATTRIBUTE_SET_ID); + } + return $this; + } + /** * Check if group uses as default * @@ -76,4 +99,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]; + } } From 58d73ff36c981b130d57342a461bf464834ac4cb Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 29 Oct 2024 16:49:49 -0700 Subject: [PATCH 082/113] phpstan baseline --- .phpstan.baseline.neon | 169 ++++++++++++++++++++++------------------- 1 file changed, 92 insertions(+), 77 deletions(-) diff --git a/.phpstan.baseline.neon b/.phpstan.baseline.neon index a32d5a6ea..2678dfad5 100644 --- a/.phpstan.baseline.neon +++ b/.phpstan.baseline.neon @@ -4432,7 +4432,7 @@ parameters: - message: "#^Variable \\$this might not be defined\\.$#" - count: 24 + count: 23 path: app/design/adminhtml/default/default/template/customer/tab/addresses.phtml - @@ -4530,6 +4530,21 @@ parameters: count: 63 path: app/design/adminhtml/default/default/template/downloadable/sales/order/view/items/renderer/downloadable.phtml + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 6 + path: app/design/adminhtml/default/default/template/eav/attribute/edit/renderer/fieldset/element.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 17 + path: app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 5 + path: app/design/adminhtml/default/default/template/eav/attribute/set/toolbar/add.phtml + - message: "#^Variable \\$this might not be defined\\.$#" count: 10 @@ -5575,6 +5590,11 @@ parameters: count: 4 path: app/design/adminhtml/default/default/template/tax/toolbar/rule/save.phtml + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 14 + path: app/design/adminhtml/default/default/template/website/switcher.phtml + - message: "#^Variable \\$this might not be defined\\.$#" count: 9 @@ -6300,11 +6320,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\\.$#" - count: 4 - path: app/design/frontend/base/default/template/checkout/onepage/billing.phtml - - message: "#^Variable \\$this might not be defined\\.$#" count: 7 @@ -6540,36 +6555,6 @@ parameters: count: 4 path: app/design/frontend/base/default/template/customer/balance.phtml - - - message: "#^Variable \\$action might not be defined\\.$#" - count: 1 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - - - message: "#^Variable \\$address might not be defined\\.$#" - count: 2 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - - - message: "#^Variable \\$countries might not be defined\\.$#" - count: 1 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - - - message: "#^Variable \\$data might not be defined\\.$#" - count: 12 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - - - message: "#^Variable \\$primaryTypes might not be defined\\.$#" - count: 1 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - - - message: "#^Variable \\$this might not be defined\\.$#" - count: 51 - path: app/design/frontend/base/default/template/customer/form/address.phtml - - message: "#^Variable \\$action might not be defined\\.$#" count: 1 @@ -6587,7 +6572,7 @@ parameters: - message: "#^Variable \\$this might not be defined\\.$#" - count: 36 + count: 23 path: app/design/frontend/base/default/template/customer/form/edit.phtml - @@ -6600,11 +6585,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\\.$#" - count: 3 - path: app/design/frontend/base/default/template/customer/form/register.phtml - - message: "#^PHPDoc tag @var contains unresolvable type\\.$#" count: 1 @@ -6730,6 +6710,76 @@ parameters: count: 190 path: app/design/frontend/base/default/template/downloadable/sales/order/items/renderer/downloadable.phtml + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 1 + path: app/design/frontend/base/default/template/eav/widget/form.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 12 + path: app/design/frontend/base/default/template/eav/widget/form/element/boolean.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 4 + path: app/design/frontend/base/default/template/eav/widget/form/element/country.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 14 + path: app/design/frontend/base/default/template/eav/widget/form/element/customselect.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 32 + path: app/design/frontend/base/default/template/eav/widget/form/element/date.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 6 + path: app/design/frontend/base/default/template/eav/widget/form/element/fieldset.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 11 + path: app/design/frontend/base/default/template/eav/widget/form/element/hidden.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 4 + path: app/design/frontend/base/default/template/eav/widget/form/element/multiline.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 12 + path: app/design/frontend/base/default/template/eav/widget/form/element/multiselect.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 11 + path: app/design/frontend/base/default/template/eav/widget/form/element/postcode.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 20 + path: app/design/frontend/base/default/template/eav/widget/form/element/region.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 12 + path: app/design/frontend/base/default/template/eav/widget/form/element/select.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 11 + path: app/design/frontend/base/default/template/eav/widget/form/element/text.phtml + + - + message: "#^Variable \\$this might not be defined\\.$#" + count: 11 + path: app/design/frontend/base/default/template/eav/widget/form/element/textarea.phtml + - message: "#^Variable \\$this might not be defined\\.$#" count: 8 @@ -7615,36 +7665,6 @@ parameters: count: 3 path: app/design/frontend/rwd/default/template/customer/account/navigation.phtml - - - message: "#^Variable \\$action might not be defined\\.$#" - count: 1 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - - - message: "#^Variable \\$address might not be defined\\.$#" - count: 2 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - - - message: "#^Variable \\$countries might not be defined\\.$#" - count: 1 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - - - message: "#^Variable \\$data might not be defined\\.$#" - count: 12 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - - - message: "#^Variable \\$primaryTypes might not be defined\\.$#" - count: 1 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - - - message: "#^Variable \\$this might not be defined\\.$#" - count: 52 - path: app/design/frontend/rwd/default/template/customer/form/address.phtml - - message: "#^Variable \\$action might not be defined\\.$#" count: 1 @@ -7660,11 +7680,6 @@ parameters: count: 13 path: app/design/frontend/rwd/default/template/customer/form/confirmation.phtml - - - message: "#^Variable \\$this might not be defined\\.$#" - count: 36 - path: app/design/frontend/rwd/default/template/customer/form/edit.phtml - - message: "#^Variable \\$this might not be defined\\.$#" count: 14 From 2618a34568ae8b703c5abad308305b71a1b2a919 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Thu, 31 Oct 2024 14:08:46 +0000 Subject: [PATCH 083/113] updated baseline --- .phpstan.baseline.neon | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/.phpstan.baseline.neon b/.phpstan.baseline.neon index 457f166c4..a44e78159 100644 --- a/.phpstan.baseline.neon +++ b/.phpstan.baseline.neon @@ -4345,26 +4345,6 @@ parameters: count: 2 path: app/design/adminhtml/default/default/template/customer/tab/addresses.phtml - - - message: "#^Variable \\$this might not be defined\\.$#" - count: 23 - path: app/design/adminhtml/default/default/template/customer/tab/addresses.phtml - - - - message: "#^Variable \\$this might not be defined\\.$#" - count: 2 - path: app/design/adminhtml/default/default/template/customer/tab/newsletter.phtml - - - - message: "#^Variable \\$this might not be defined\\.$#" - count: 13 - path: app/design/adminhtml/default/default/template/customer/tab/view/sales.phtml - - - - message: "#^Variable \\$this might not be defined\\.$#" - count: 8 - path: app/design/adminhtml/default/default/template/customer/tab/wishlist.phtml - - message: "#^Variable \\$this might not be defined\\.$#" count: 9 From c6d3c76026629f1577dd909d6b589255870bf625 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Thu, 31 Oct 2024 08:11:14 -0700 Subject: [PATCH 084/113] remove hardcoded attribute set ids --- app/code/core/Mage/Customer/Model/Group.php | 12 ++--- .../Mage/Customer/Model/Resource/Group.php | 18 ------- .../Customer/sql/maho_setup/maho-24.10.0.php | 48 ++++++++++++------- 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/app/code/core/Mage/Customer/Model/Group.php b/app/code/core/Mage/Customer/Model/Group.php index bbde382a5..873781c57 100644 --- a/app/code/core/Mage/Customer/Model/Group.php +++ b/app/code/core/Mage/Customer/Model/Group.php @@ -30,17 +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 ENTITY = 'customer_group'; + public const ENTITY = 'customer_group'; - public const NOT_LOGGED_IN_ID = 0; - public const DEFAULT_ATTRIBUTE_SET_ID = 1; - public const DEFAULT_ADDRESS_ATTRIBUTE_SET_ID = 2; + public const NOT_LOGGED_IN_ID = 0; - public const CUST_GROUP_ALL = 32000; + public const CUST_GROUP_ALL = 32000; - public const GROUP_CODE_MAX_LENGTH = 32; + public const GROUP_CODE_MAX_LENGTH = 32; /** * Prefix of model events names diff --git a/app/code/core/Mage/Customer/Model/Resource/Group.php b/app/code/core/Mage/Customer/Model/Resource/Group.php index 72753a601..93baea73f 100644 --- a/app/code/core/Mage/Customer/Model/Resource/Group.php +++ b/app/code/core/Mage/Customer/Model/Resource/Group.php @@ -46,24 +46,6 @@ protected function _initUniqueFields() return $this; } - /** - * Set default attribute set ids - * - * @return Mage_Core_Model_Resource_Db_Abstract - */ - #[\Override] - protected function _afterLoad(Mage_Core_Model_Abstract $group) - { - parent::_afterLoad($group); - if (!$group->hasData('customer_attribute_set_id')) { - $group->setData('customer_attribute_set_id', Mage_Customer_Model_Group::DEFAULT_ATTRIBUTE_SET_ID); - } - if (!$group->hasData('customer_address_attribute_set_id')) { - $group->setData('customer_address_attribute_set_id', Mage_Customer_Model_Group::DEFAULT_ADDRESS_ATTRIBUTE_SET_ID); - } - return $this; - } - /** * Check if group uses as default * 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 index 8a5f245b3..bf11e3e00 100644 --- 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 @@ -12,22 +12,36 @@ $installer = $this; $installer->startSetup(); -$installer->getConnection() - ->addColumn($installer->getTable('customer/customer_group'), 'customer_attribute_set_id', [ - 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, - 'unsigned' => true, - 'nullable' => false, - 'default' => Mage_Customer_Model_Group::DEFAULT_ATTRIBUTE_SET_ID, - 'comment' => 'Customer Group Attribute Set ID', - ]); - -$installer->getConnection() - ->addColumn($installer->getTable('customer/customer_group'), 'customer_address_attribute_set_id', [ - 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, - 'unsigned' => true, - 'nullable' => false, - 'default' => Mage_Customer_Model_Group::DEFAULT_ADDRESS_ATTRIBUTE_SET_ID, - 'comment' => 'Customer Group Address Attribute Set ID', - ]); +$defs = [ + [ 'model' => 'customer/customer', 'column' => 'customer_attribute_set_id' ], + [ 'model' => 'customer/address', 'column' => 'customer_address_attribute_set_id' ], +]; + +foreach ($defs as $info) { + + $entityTypeId = Mage::getResourceModel($info['model']) + ->getEntityType() + ->getId(); + + $defaultSet = Mage::getResourceModel('eav/entity_attribute_set_collection') + ->setEntityTypeFilter($entityTypeId) + ->getFirstItem(); + + if ($defaultSet->getAttributeSetId() === null) { + $defaultSet = Mage::getModel('eav/entity_attribute_set') + ->setEntityTypeId($entityTypeId) + ->setAttributeSetName('Default') + ->save(); + } + + $installer->getConnection() + ->addColumn($installer->getTable('customer/customer_group'), $info['column'], [ + 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, + 'unsigned' => true, + 'nullable' => false, + 'default' => $defaultSet->getAttributeSetId(), + 'comment' => 'Customer Group Attribute Set ID', + ]); +} $installer->endSetup(); From b450e39905bf9e8cae020420ae2b9dc515ce3283 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Thu, 31 Oct 2024 22:27:05 +0000 Subject: [PATCH 085/113] PHPCS --- app/code/core/Mage/Customer/sql/maho_setup/maho-24.10.0.php | 1 - 1 file changed, 1 deletion(-) 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 index bf11e3e00..a796ca188 100644 --- 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 @@ -18,7 +18,6 @@ ]; foreach ($defs as $info) { - $entityTypeId = Mage::getResourceModel($info['model']) ->getEntityType() ->getId(); From b2668f18a446455cba90527b3683190cff911998 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Fri, 1 Nov 2024 07:34:28 -0700 Subject: [PATCH 086/113] Install script --- .../Customer/sql/maho_setup/maho-24.10.0.php | 52 +++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) 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 index a796ca188..3470d6107 100644 --- 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 @@ -12,25 +12,59 @@ $installer = $this; $installer->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) { - $entityTypeId = Mage::getResourceModel($info['model']) - ->getEntityType() - ->getId(); + /** @var Mage_Eav_Model_Entity_Type $entityType */ + $entityType = Mage::getResourceModel($info['model'])->getEntityType(); - $defaultSet = Mage::getResourceModel('eav/entity_attribute_set_collection') - ->setEntityTypeFilter($entityTypeId) - ->getFirstItem(); + /** $var Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection $collection */ + $collection = Mage::getResourceModel('eav/entity_attribute_set_collection') + ->setEntityTypeFilter($entityType->getId()); - if ($defaultSet->getAttributeSetId() === null) { + /** @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($entityTypeId) + ->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() @@ -38,7 +72,7 @@ 'type' => Varien_Db_Ddl_Table::TYPE_SMALLINT, 'unsigned' => true, 'nullable' => false, - 'default' => $defaultSet->getAttributeSetId(), + 'default' => $defaultSet->getId(), 'comment' => 'Customer Group Attribute Set ID', ]); } From 3c5130fdc73b6adf9f64f7679a77dc50227514f4 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 2 Nov 2024 12:14:10 -0700 Subject: [PATCH 087/113] Integrating changes since PR was originally created in OM --- .../Catalog/Category/SetController.php | 1 - .../core/Mage/Eav/Block/Adminhtml/Attribute.php | 6 ------ .../Mage/Eav/Block/Adminhtml/Attribute/Edit.php | 6 ------ .../Mage/Eav/Block/Adminhtml/Attribute/Set.php | 6 ------ .../Eav/Block/Adminhtml/Attribute/Set/Main.php | 15 +++++---------- .../Adminhtml/Attribute/Set/Toolbar/Add.php | 17 ++++++++++++++++- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php index f711fce9f..14754381e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php @@ -13,7 +13,6 @@ * * @category Mage * @package Mage_Adminhtml - * @author Magento Core Team */ class Mage_Adminhtml_Catalog_Category_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php index ef4b4bf6a..b35ca0fc4 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php @@ -29,10 +29,4 @@ public function __construct() $this->_addButtonLabel = Mage::helper('eav')->__('Add New Attribute'); parent::__construct(); } - - #[\Override] - public function getHeaderCssClass() - { - return 'icon-head head-eav-attribute'; - } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php index 61cd3b086..93f0c55ff 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php @@ -67,10 +67,4 @@ public function getSaveUrl() { return $this->getUrl('*/*/save', ['_current' => true, 'back' => null]); } - - #[\Override] - public function getHeaderCssClass() - { - return 'icon-head head-eav-attribute'; - } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php index 36304cc19..b7082fac6 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php @@ -35,10 +35,4 @@ public function getCreateUrl() { return $this->getUrl('*/*/add'); } - - #[\Override] - public function getHeaderCssClass() - { - return 'icon-head head-eav-attribute-sets'; - } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php index 2c6e47ff7..0a90eec08 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php @@ -65,7 +65,7 @@ protected function _prepareLayout() 'back_button', $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ 'label' => Mage::helper('eav')->__('Back'), - 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/') . '\')', + 'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/')), 'class' => 'back' ]) ); @@ -87,19 +87,14 @@ protected function _prepareLayout() ]) ); - if ($entity_type = Mage::registry('entity_type')) { - $deleteConfirmMessage = $this->jsQuoteEscape(Mage::helper('eav') - ->__('All %s of this set will be deleted! Are you sure you want to delete this attribute set?')); - } else { - $deleteConfirmMessage = $this->jsQuoteEscape(Mage::helper('eav') - ->__('All items of this set will be deleted! Are you sure you want to delete this attribute set?')); - } - $deleteUrl = $this->getUrlSecure('*/*/delete', ['id' => $setId]); $this->setChild( 'delete_button', $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ 'label' => Mage::helper('eav')->__('Delete Attribute Set'), - 'onclick' => 'deleteConfirm(\'' . $deleteConfirmMessage . '\', \'' . $deleteUrl . '\')', + 'onclick' => Mage::helper('core/js')->getDeleteConfirmJs( + $this->getUrlSecure('*/*/delete', ['id' => $setId]), + Mage::helper('eav')->__('Are you sure you want to delete this attribute set?') + ), 'class' => 'delete' ]) ); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php index 1d5bcf1b3..58a71b353 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php @@ -38,7 +38,7 @@ protected function _prepareLayout() $this->getLayout()->createBlock('adminhtml/widget_button') ->setData([ 'label' => Mage::helper('eav')->__('Back'), - 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/') . '\')', + 'onclick' => Mage::helper('core/js')->getSetLocationJs($this->getUrl('*/*/')), 'class' => 'back' ]) ); @@ -50,26 +50,41 @@ protected function _prepareLayout() return parent::_prepareLayout(); } + /** + * @return string + */ protected function _getHeader() { return Mage::helper('eav')->__('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'); } + /** + * @return string + */ protected function getFormId() { return $this->getChild('setForm')->getForm()->getId(); From cee5600d9ad87604e46cc4ece52ba9e9ff9ca5f2 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 2 Nov 2024 13:51:05 -0700 Subject: [PATCH 088/113] Integrating changes since PR was originally created in OM --- .../Block/Adminhtml/Attribute/Set/Main.php | 4 +- .../Attribute/Set/Main/Formgroup.php | 55 ++++++++----------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php index 0a90eec08..7256702fc 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php @@ -385,7 +385,9 @@ public function getIsCurrentSetDefault() { $isDefault = $this->getData('is_current_set_default'); if (is_null($isDefault)) { - $defaultSetId = Mage::registry('entity_type')->getDefaultAttributeSetId(); + $defaultSetId = Mage::getSingleton('eav/config') + ->getEntityType(Mage::registry('entity_type')) + ->getDefaultAttributeSetId(); $isDefault = $this->_getSetId() == $defaultSetId; $this->setData('is_current_set_default', $isDefault); } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php index eae16c075..1d19b661f 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php @@ -27,38 +27,26 @@ protected function _prepareForm() $fieldset = $form->addFieldset('set_fieldset', ['legend' => Mage::helper('eav')->__('Add New Group')]); - $fieldset->addField( - 'attribute_group_name', - 'text', - [ - 'label' => Mage::helper('eav')->__('Name'), - 'name' => 'attribute_group_name', - 'required' => true, - ] - ); + $fieldset->addField('attribute_group_name', 'text', [ + 'label' => Mage::helper('eav')->__('Name'), + 'name' => 'attribute_group_name', + 'required' => true, + ]); - $fieldset->addField( - 'submit', - 'note', - [ - 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData([ - 'label' => Mage::helper('eav')->__('Add Group'), - 'onclick' => 'this.form.submit();', - 'class' => 'add' - ]) - ->toHtml(), - ] - ); + $fieldset->addField('submit', 'note', [ + 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') + ->setData([ + 'label' => Mage::helper('eav')->__('Add Group'), + 'onclick' => 'this.form.submit();', + 'class' => 'add' + ]) + ->toHtml(), + ]); - $fieldset->addField( - 'attribute_set_id', - 'hidden', - [ - 'name' => 'attribute_set_id', - 'value' => $this->_getSetId(), - ] - ); + $fieldset->addField('attribute_set_id', 'hidden', [ + 'name' => 'attribute_set_id', + 'value' => $this->_getSetId(), + ]); $form->setUseContainer(true); $form->setMethod('post'); @@ -69,8 +57,9 @@ protected function _prepareForm() protected function _getSetId() { - return ((int) ($this->getRequest()->getParam('id')) > 0) - ? (int) ($this->getRequest()->getParam('id')) - : Mage::registry('entity_type')->getDefaultAttributeSetId(); + return ((int) $this->getRequest()->getParam('id') > 0) + ? (int) $this->getRequest()->getParam('id') + : Mage::getSingleton('eav/config')->getEntityType(Mage::registry('entity_type')) + ->getDefaultAttributeSetId(); } } From e7985807954dda081d0cc76a46ecd964ed3ce332 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 2 Nov 2024 15:21:04 -0700 Subject: [PATCH 089/113] Make Mage_Adminhtml_Catalog_Product_SetController more like generic one --- .../Catalog/Product/SetController.php | 63 ++++++------------- 1 file changed, 19 insertions(+), 44 deletions(-) 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..7354c90ea 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php @@ -24,14 +24,30 @@ class Mage_Adminhtml_Catalog_Product_SetController extends Mage_Adminhtml_Contro */ public const ADMIN_RESOURCE = 'catalog/attributes/sets'; + /** + * Controller predispatch method + * + * @return Mage_Adminhtml_Controller_Action + */ + #[\Override] + public function preDispatch() + { + $this->_setForcedFormKeyActions('delete'); + $this->_entityType = Mage::getModel('catalog/product')->getResource()->getEntityType(); + if (!Mage::registry('entity_type')) { + Mage::register('entity_type', $this->_entityType); + } + // For backwards compatibility set camelCase registry key with type id + Mage::register('entityType', $this->_entityType->getEntityTypeId()); + return parent::preDispatch(); + } + public function indexAction() { $this->_title($this->__('Catalog')) ->_title($this->__('Attributes')) ->_title($this->__('Manage Attribute Sets')); - $this->_setTypeId(); - $this->loadLayout(); $this->_setActiveMenu('catalog/attributes/sets'); @@ -53,7 +69,6 @@ public function editAction() ->_title($this->__('Attributes')) ->_title($this->__('Manage Attribute Sets')); - $this->_setTypeId(); $attributeSet = Mage::getModel('eav/entity_attribute_set') ->load($this->getRequest()->getParam('id')); @@ -83,7 +98,6 @@ public function editAction() public function setGridAction() { - $this->_setTypeId(); $this->getResponse()->setBody( $this->getLayout() ->createBlock('adminhtml/catalog_product_attribute_set_grid') @@ -100,7 +114,7 @@ public function setGridAction() */ public function saveAction() { - $entityTypeId = $this->_getEntityTypeId(); + $entityTypeId = $this->_entityType->getEntityTypeId(); $hasError = false; $attributeSetId = $this->getRequest()->getParam('id', false); $isNewSet = $this->getRequest()->getParam('gotoEdit', false) == '1'; @@ -177,8 +191,6 @@ public function addAction() ->_title($this->__('Manage Attribute Sets')) ->_title($this->__('New Set')); - $this->_setTypeId(); - $this->loadLayout(); $this->_setActiveMenu('catalog/sets'); @@ -202,41 +214,4 @@ public function deleteAction() $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() - ); - } - - /** - * Retrieve catalog product entity type id - * - * @return int - */ - protected function _getEntityTypeId() - { - if (is_null(Mage::registry('entityType'))) { - $this->_setTypeId(); - } - return Mage::registry('entityType'); - } } From f4bc67f69e867639cd03e178ace7bf614a9827a2 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 2 Nov 2024 15:29:47 -0700 Subject: [PATCH 090/113] use consistent registry key --- .../Catalog/Product/Attribute/Set/Grid.php | 2 +- .../Catalog/Product/Attribute/Set/Main.php | 4 +-- .../Product/Attribute/Set/Main/Formgroup.php | 33 +++++++++---------- .../Product/Attribute/Set/Main/Formset.php | 2 +- .../Eav/Block/Adminhtml/Attribute/Edit.php | 22 ++++++++----- .../Block/Adminhtml/Attribute/Set/Main.php | 4 +-- .../Attribute/Set/Main/Formgroup.php | 3 +- 7 files changed, 35 insertions(+), 35 deletions(-) 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 fd4230f2b..a8bee476d 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 @@ -41,7 +41,7 @@ public function __construct() protected function _prepareCollection() { $collection = Mage::getResourceModel('eav/entity_attribute_set_collection') - ->setEntityTypeFilter(Mage::registry('entityType')); + ->setEntityTypeFilter(Mage::registry('entity_type')->getEntityTypeId()); $this->setCollection($collection); return parent::_prepareCollection(); 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..5a3b2b140 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 @@ -382,9 +382,7 @@ public function getIsCurrentSetDefault() { $isDefault = $this->getData('is_current_set_default'); if (is_null($isDefault)) { - $defaultSetId = Mage::getSingleton('eav/config') - ->getEntityType(Mage::registry('entityType')) - ->getDefaultAttributeSetId(); + $defaultSetId = Mage::registry('entity_type')->getDefaultAttributeSetId(); $isDefault = $this->_getSetId() == $defaultSetId; $this->setData('is_current_set_default', $isDefault); } 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 index 0dc0a57f8..616bb39e1 100644 --- 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 @@ -27,33 +27,33 @@ protected function _prepareForm() 'attribute_group_name', 'text', [ - 'label' => Mage::helper('catalog')->__('Name'), - 'name' => 'attribute_group_name', - 'required' => true, - ] + '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(), - ] + '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(), - ] + 'name' => 'attribute_set_id', + 'value' => $this->_getSetId(), + ] ); $form->setUseContainer(true); @@ -67,7 +67,6 @@ protected function _getSetId() { return ((int) $this->getRequest()->getParam('id') > 0) ? (int) $this->getRequest()->getParam('id') - : Mage::getSingleton('eav/config')->getEntityType(Mage::registry('entityType')) - ->getDefaultAttributeSetId(); + : Mage::registry('entity_type')->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..7efe518b4 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 @@ -45,7 +45,7 @@ protected function _prepareForm() $sets = Mage::getModel('eav/entity_attribute_set') ->getResourceCollection() - ->setEntityTypeFilter(Mage::registry('entityType')) + ->setEntityTypeFilter(Mage::registry('entity_type')->getEntityTypeId()) ->setOrder('attribute_set_name', 'asc') ->load() ->toOptionArray(); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php index 93f0c55ff..17bac8d84 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php @@ -43,25 +43,31 @@ public function __construct() } } + /** + * @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('eav')->__('Edit %s Attribute "%s"', Mage::helper('eav')->formatTypeCode(Mage::registry('entity_type')), $this->escapeHtml($frontendLabel)); - } else { - return Mage::helper('eav')->__('New %s Attribute', Mage::helper('eav')->formatTypeCode(Mage::registry('entity_type'))); + $entityType = Mage::registry('entity_type'); + $entityAttribute = Mage::registry('entity_attribute'); + if ($entityAttribute->getId()) { + return Mage::helper('eav')->__('Edit %s Attribute "%s"', Mage::helper('eav')->formatTypeCode($entityType), $entityAttribute->getFrontendLabel()); } + return Mage::helper('eav')->__('New %s Attribute', Mage::helper('eav')->formatTypeCode($entityType)); } + /** + * @return string + */ public function getValidationUrl() { return $this->getUrl('*/*/validate', ['_current' => true]); } + /** + * @return string + */ #[\Override] public function getSaveUrl() { diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php index 7256702fc..0a90eec08 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php @@ -385,9 +385,7 @@ public function getIsCurrentSetDefault() { $isDefault = $this->getData('is_current_set_default'); if (is_null($isDefault)) { - $defaultSetId = Mage::getSingleton('eav/config') - ->getEntityType(Mage::registry('entity_type')) - ->getDefaultAttributeSetId(); + $defaultSetId = Mage::registry('entity_type')->getDefaultAttributeSetId(); $isDefault = $this->_getSetId() == $defaultSetId; $this->setData('is_current_set_default', $isDefault); } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php index 1d19b661f..0ad40703f 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php @@ -59,7 +59,6 @@ protected function _getSetId() { return ((int) $this->getRequest()->getParam('id') > 0) ? (int) $this->getRequest()->getParam('id') - : Mage::getSingleton('eav/config')->getEntityType(Mage::registry('entity_type')) - ->getDefaultAttributeSetId(); + : Mage::registry('entity_type')->getDefaultAttributeSetId(); } } From a9f7ae7f5e8986c9ede004de10cc41b670be1dc3 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 2 Nov 2024 15:33:39 -0700 Subject: [PATCH 091/113] PHPStan --- .../Adminhtml/controllers/Catalog/Product/SetController.php | 3 +++ 1 file changed, 3 insertions(+) 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 7354c90ea..2208884a6 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php @@ -24,6 +24,9 @@ class Mage_Adminhtml_Catalog_Product_SetController extends Mage_Adminhtml_Contro */ public const ADMIN_RESOURCE = 'catalog/attributes/sets'; + /** @var Mage_Eav_Model_Entity_Type $_entityType */ + protected $_entityType; + /** * Controller predispatch method * From 8f2097722a90966fc6ca5befa957cfb195fc90db Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 2 Nov 2024 15:33:46 -0700 Subject: [PATCH 092/113] camelCase --- .../Mage/Eav/Block/Adminhtml/Attribute.php | 4 ++-- .../Eav/Block/Adminhtml/Attribute/Set.php | 4 ++-- .../Block/Adminhtml/Attribute/Set/Main.php | 22 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php index b35ca0fc4..c0507a863 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php @@ -21,8 +21,8 @@ public function __construct() { $this->_blockGroup = 'eav'; $this->_controller = 'adminhtml_attribute'; - if ($entity_type = Mage::registry('entity_type')) { - $this->_headerText = Mage::helper('eav')->__('Manage %s Attributes', Mage::helper('eav')->formatTypeCode($entity_type)); + if ($entityType = Mage::registry('entity_type')) { + $this->_headerText = Mage::helper('eav')->__('Manage %s Attributes', Mage::helper('eav')->formatTypeCode($entityType)); } else { $this->_headerText = Mage::helper('eav')->__('Manage Attributes'); } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php index b7082fac6..64178d0ce 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php @@ -21,8 +21,8 @@ public function __construct() { $this->_blockGroup = 'eav'; $this->_controller = 'adminhtml_attribute_set'; - if ($entity_type = Mage::registry('entity_type')) { - $this->_headerText = Mage::helper('eav')->__('Manage %s Attribute Sets', Mage::helper('eav')->formatTypeCode($entity_type)); + if ($entityType = Mage::registry('entity_type')) { + $this->_headerText = Mage::helper('eav')->__('Manage %s Attribute Sets', Mage::helper('eav')->formatTypeCode($entityType)); } else { $this->_headerText = Mage::helper('eav')->__('Manage Attribute Sets'); } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php index 0a90eec08..fbdc107e1 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php @@ -177,10 +177,10 @@ public function getGroupTreeJson() ->setSortOrder() ->load(); - /* @var $entity_type Mage_Eav_Model_Entity_Type */ - $entity_type = Mage::registry('entity_type'); + /* @var $entityType Mage_Eav_Model_Entity_Type */ + $entityType = Mage::registry('entity_type'); - $hiddenAttributes = Mage::helper('eav')->getHiddenAttributes($entity_type->getEntityTypeCode()); + $hiddenAttributes = Mage::helper('eav')->getHiddenAttributes($entityType->getEntityTypeCode()); /* @var $node Mage_Eav_Model_Entity_Attribute_Group */ foreach ($groups as $node) { @@ -192,8 +192,8 @@ public function getGroupTreeJson() $item['allowDrag'] = true; /** @var Mage_Eav_Model_Entity_Attribute $nodeChildren */ - $nodeChildren = Mage::getResourceModel($entity_type->getEntityAttributeCollection()); - $nodeChildren->setEntityTypeFilter($entity_type->getEntityTypeId()) + $nodeChildren = Mage::getResourceModel($entityType->getEntityAttributeCollection()); + $nodeChildren->setEntityTypeFilter($entityType->getEntityTypeId()) ->setNotCodeFilter($hiddenAttributes) ->setAttributeGroupFilter($node->getId()) ->load(); @@ -233,12 +233,12 @@ public function getAttributeTreeJson() $items = []; $setId = $this->_getSetId(); - /* @var $entity_type Mage_Eav_Model_Entity_Type */ - $entity_type = Mage::registry('entity_type'); + /* @var $entityType Mage_Eav_Model_Entity_Type */ + $entityType = Mage::registry('entity_type'); /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection */ - $collection = Mage::getResourceModel($entity_type->getEntityAttributeCollection()); - $collection->setEntityTypeFilter($entity_type->getEntityTypeId()) + $collection = Mage::getResourceModel($entityType->getEntityAttributeCollection()); + $collection->setEntityTypeFilter($entityType->getEntityTypeId()) ->setAttributeSetFilter($setId) ->load(); @@ -249,8 +249,8 @@ public function getAttributeTreeJson() } /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $attributes */ - $attributes = Mage::getResourceModel($entity_type->getEntityAttributeCollection()); - $attributes->setEntityTypeFilter($entity_type->getEntityTypeId()) + $attributes = Mage::getResourceModel($entityType->getEntityAttributeCollection()); + $attributes->setEntityTypeFilter($entityType->getEntityTypeId()) ->setAttributesExcludeFilter($attributesIds) ->setOrder('attribute_code', 'asc') ->load(); From ece827909877bc93a19440e0bea4d5d7f3023390 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 2 Nov 2024 16:10:25 -0700 Subject: [PATCH 093/113] Use ADMIN_RESOURCE const --- .../Catalog/Category/AttributeController.php | 12 ++++++------ .../controllers/Catalog/Category/SetController.php | 12 ++++++------ .../Customer/Address/AttributeController.php | 12 ++++++------ .../controllers/Customer/Address/SetController.php | 12 ++++++------ .../controllers/Customer/AttributeController.php | 12 ++++++------ .../Adminhtml/controllers/Customer/SetController.php | 12 ++++++------ 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php index bf6f95cb9..07f0b193f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php @@ -17,6 +17,12 @@ */ class Mage_Adminhtml_Catalog_Category_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { + /** + * ACL resource + * @see Mage_Adminhtml_Controller_Action::_isAllowed() + */ + public const ADMIN_RESOURCE = 'catalog/attributes/category_attributes'; + #[\Override] protected function _construct() { @@ -44,10 +50,4 @@ protected function _initAction() return $this; } - - #[\Override] - protected function _isAllowed() - { - return Mage::getSingleton('admin/session')->isAllowed('catalog/attributes/category_attributes'); - } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php index 14754381e..d45518348 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php @@ -16,6 +16,12 @@ */ class Mage_Adminhtml_Catalog_Category_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { + /** + * ACL resource + * @see Mage_Adminhtml_Controller_Action::_isAllowed() + */ + public const ADMIN_RESOURCE = 'catalog/attributes/category_sets'; + #[\Override] protected function _construct() { @@ -43,10 +49,4 @@ protected function _initAction() return $this; } - - #[\Override] - protected function _isAllowed() - { - return Mage::getSingleton('admin/session')->isAllowed('catalog/attributes/category_sets'); - } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php index 52dca41c3..a8b1d7d86 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php @@ -17,6 +17,12 @@ */ class Mage_Adminhtml_Customer_Address_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { + /** + * ACL resource + * @see Mage_Adminhtml_Controller_Action::_isAllowed() + */ + public const ADMIN_RESOURCE = 'customer/attributes/customer_address_attributes'; + #[\Override] protected function _construct() { @@ -44,10 +50,4 @@ protected function _initAction() return $this; } - - #[\Override] - protected function _isAllowed() - { - return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_address_attributes'); - } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php index dafe69888..f6b9c8309 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php @@ -17,6 +17,12 @@ */ class Mage_Adminhtml_Customer_Address_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { + /** + * ACL resource + * @see Mage_Adminhtml_Controller_Action::_isAllowed() + */ + public const ADMIN_RESOURCE = 'customer/attributes/customer_address_sets'; + #[\Override] protected function _construct() { @@ -44,10 +50,4 @@ protected function _initAction() return $this; } - - #[\Override] - protected function _isAllowed() - { - return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_address_sets'); - } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php index 75fa81be2..4c862ddb9 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php @@ -17,6 +17,12 @@ */ class Mage_Adminhtml_Customer_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { + /** + * ACL resource + * @see Mage_Adminhtml_Controller_Action::_isAllowed() + */ + public const ADMIN_RESOURCE = 'customer/attributes/customer_attributes'; + #[\Override] protected function _construct() { @@ -44,10 +50,4 @@ protected function _initAction() return $this; } - - #[\Override] - protected function _isAllowed() - { - return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_attributes'); - } } diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php index 44f35c3a0..faef84fb9 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php @@ -17,6 +17,12 @@ */ class Mage_Adminhtml_Customer_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { + /** + * ACL resource + * @see Mage_Adminhtml_Controller_Action::_isAllowed() + */ + public const ADMIN_RESOURCE = 'customer/attributes/customer_sets'; + #[\Override] protected function _construct() { @@ -44,10 +50,4 @@ protected function _initAction() return $this; } - - #[\Override] - protected function _isAllowed() - { - return Mage::getSingleton('admin/session')->isAllowed('customer/attributes/customer_sets'); - } } From ed37d4cc5d3a6e9c4eaf34531fb51afc10a97513 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 2 Nov 2024 16:10:32 -0700 Subject: [PATCH 094/113] misc --- .../core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php | 4 +--- .../Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php | 10 +++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php index a29039a07..dab56cd2c 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php @@ -16,9 +16,7 @@ class Mage_Eav_Block_Adminhtml_Attribute_Grid extends Mage_Eav_Block_Adminhtml_Attribute_Grid_Abstract { /** - * Prepare grid collection object - * - * @return $this + * @inheritDoc */ #[\Override] protected function _prepareCollection() 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 index 91a4065ea..be661823e 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php @@ -33,6 +33,9 @@ public function __construct() $this->setSaveParametersInSession(true); } + /** + * @inheritDoc + */ #[\Override] protected function _prepareCollection() { @@ -45,19 +48,24 @@ protected function _prepareCollection() return parent::_prepareCollection(); } + /** + * @inheritDoc + */ #[\Override] protected function _prepareColumns() { $this->addColumn('set_name', [ 'header' => Mage::helper('eav')->__('Set Name'), 'align' => 'left', - 'sortable' => true, 'index' => 'attribute_set_name', ]); return $this; } + /** + * @inheritDoc + */ #[\Override] public function getRowUrl($row) { From 56a14374f7fdf5bb5ded996d3f109875f7de38a3 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 2 Nov 2024 16:25:39 -0700 Subject: [PATCH 095/113] ref OM 1544 --- .../core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php index e9fc80bd1..ef1b74aea 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -262,7 +262,7 @@ public function saveAction() $data['backend_model'] = $helper->getAttributeBackendModelByInputType($data['frontend_input']); } - if (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0) { + if (!$model->getBackendType() && (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0)) { $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']); } From 303c2e6826ef2b528ea6ffc26866a36563457dda Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 2 Nov 2024 16:35:47 -0700 Subject: [PATCH 096/113] Make Mage_Adminhtml_Catalog_Product_AttributeController more like generic one --- .../Catalog/Product/AttributeController.php | 24 +++++++++++++------ .../Catalog/Product/SetController.php | 7 ++++-- .../Adminhtml/Attribute/Abstract.php | 4 ++-- .../Eav/Controller/Adminhtml/Set/Abstract.php | 4 ++-- 4 files changed, 26 insertions(+), 13 deletions(-) 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..57fd7195f 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php @@ -18,8 +18,6 @@ */ class Mage_Adminhtml_Catalog_Product_AttributeController extends Mage_Adminhtml_Controller_Action { - protected $_entityTypeId; - /** * ACL resource * @see Mage_Adminhtml_Controller_Action::_isAllowed() @@ -27,10 +25,19 @@ class Mage_Adminhtml_Catalog_Product_AttributeController extends Mage_Adminhtml_ public const ADMIN_RESOURCE = 'catalog/attributes/attributes'; /** - * List of tags from setting - */ + * List of tags from setting + */ public const XML_PATH_ALLOWED_TAGS = 'system/catalog/frontend/allowed_html_tags_list'; + /** @var string */ + protected $_entityCode = Mage_Catalog_Model_Product::ENTITY; + + /** @var Mage_Eav_Model_Entity_Type */ + protected $_entityType; + + /** @var int */ + protected $_entityTypeId; + /** * Get list of allowed text formatted as array * @@ -45,9 +52,12 @@ protected function _getAllowedTags() public function preDispatch() { $this->_setForcedFormKeyActions('delete'); - parent::preDispatch(); - $this->_entityTypeId = Mage::getModel('eav/entity')->setType(Mage_Catalog_Model_Product::ENTITY)->getTypeId(); - return $this; + $this->_entityType = Mage::getModel('eav/entity')->setType($this->_entityCode)->getEntityType(); + if (!Mage::registry('entity_type')) { + Mage::register('entity_type', $this->_entityType); + } + $this->_entityTypeId = $this->_entityType->getEntityTypeId(); + return parent::preDispatch(); } protected function _initAction() 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 2208884a6..5bb30ef67 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/SetController.php @@ -24,7 +24,10 @@ class Mage_Adminhtml_Catalog_Product_SetController extends Mage_Adminhtml_Contro */ public const ADMIN_RESOURCE = 'catalog/attributes/sets'; - /** @var Mage_Eav_Model_Entity_Type $_entityType */ + /** @var string */ + protected $_entityCode = Mage_Catalog_Model_Product::ENTITY; + + /** @var Mage_Eav_Model_Entity_Type */ protected $_entityType; /** @@ -36,7 +39,7 @@ class Mage_Adminhtml_Catalog_Product_SetController extends Mage_Adminhtml_Contro public function preDispatch() { $this->_setForcedFormKeyActions('delete'); - $this->_entityType = Mage::getModel('catalog/product')->getResource()->getEntityType(); + $this->_entityType = Mage::getModel('eav/entity')->setType($this->_entityCode)->getEntityType(); if (!Mage::registry('entity_type')) { Mage::register('entity_type', $this->_entityType); } diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php index ef1b74aea..0001ebcd8 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -17,10 +17,10 @@ */ abstract class Mage_Eav_Controller_Adminhtml_Attribute_Abstract extends Mage_Adminhtml_Controller_Action { - /** @var string $_entityCode */ + /** @var string */ protected $_entityCode; - /** @var Mage_Eav_Model_Entity_Type $_entityType */ + /** @var Mage_Eav_Model_Entity_Type */ protected $_entityType; /** diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php index 4e157dc56..f87a697af 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php @@ -17,10 +17,10 @@ */ abstract class Mage_Eav_Controller_Adminhtml_Set_Abstract extends Mage_Adminhtml_Controller_Action { - /** @var string $_entityCode */ + /** @var string */ protected $_entityCode; - /** @var Mage_Eav_Model_Entity_Type $_entityType */ + /** @var Mage_Eav_Model_Entity_Type */ protected $_entityType; /** From 011261fd6c849d1c87f35ad07d8483de9f860283 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sun, 3 Nov 2024 06:51:15 -0800 Subject: [PATCH 097/113] Ref OM 2875 + simplify logic --- .../Catalog/Product/AttributeController.php | 31 +++++++------------ .../Adminhtml/Attribute/Abstract.php | 12 ++----- 2 files changed, 15 insertions(+), 28 deletions(-) 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 57fd7195f..3f3253303 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php @@ -261,6 +261,7 @@ public function saveAction() $data['backend_model'] = $model->getBackendModel(); $data['attribute_code'] = $model->getAttributeCode(); $data['is_user_defined'] = $model->getIsUserDefined(); + $data['entity_type_id'] = $model->getEntityTypeId(); $data['frontend_input'] = $model->getFrontendInput(); } else { /** @@ -268,6 +269,17 @@ public function saveAction() */ $data['source_model'] = $helper->getAttributeSourceModelByInputType($data['frontend_input']); $data['backend_model'] = $helper->getAttributeBackendModelByInputType($data['frontend_input']); + $data['entity_type_id'] = $this->_entityType->getEntityTypeId(); + $data['is_user_defined'] = 1; + } + + 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['is_configurable'])) { @@ -280,33 +292,14 @@ public function saveAction() $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')); diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php index 0001ebcd8..39e220fc2 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -253,6 +253,7 @@ public function saveAction() $data['backend_model'] = $model->getBackendModel(); $data['attribute_code'] = $model->getAttributeCode(); $data['is_user_defined'] = $model->getIsUserDefined(); + $data['entity_type_id'] = $model->getEntityTypeId(); $data['frontend_input'] = $model->getFrontendInput(); } else { /** @@ -260,6 +261,8 @@ public function saveAction() */ $data['source_model'] = $helper->getAttributeSourceModelByInputType($data['frontend_input']); $data['backend_model'] = $helper->getAttributeBackendModelByInputType($data['frontend_input']); + $data['entity_type_id'] = $this->_entityType->getEntityTypeId(); + $data['is_user_defined'] = 1; } if (!$model->getBackendType() && (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0)) { @@ -271,10 +274,6 @@ public function saveAction() $data['default_value'] = $this->getRequest()->getParam($defaultValueField); } - if ($model) { - $data['entity_type_id'] = $model->getEntityTypeId(); - } - // filter $data = $this->_filterPostData($data); @@ -306,11 +305,6 @@ public function saveAction() $model->addData($data); - if (!$id) { - $model->setEntityTypeId($this->_entityType->getEntityTypeId()); - $model->setIsUserDefined(1); - } - Mage::dispatchEvent( "adminhtml_{$this->_entityCode}_attribute_edit_prepare_save", ['object' => $model, 'request' => $this->getRequest()] From 4a9c44f44598f7d77b6c3e9ec15cac9e51c8ae32 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sun, 3 Nov 2024 09:49:37 -0800 Subject: [PATCH 098/113] Consolidate logic in eav helper, deprecate methods --- app/code/core/Mage/Catalog/Helper/Product.php | 37 ++------ app/code/core/Mage/Eav/Helper/Data.php | 90 ++++++++++++++---- .../core/Mage/Eav/Model/Entity/Attribute.php | 92 ++++--------------- 3 files changed, 101 insertions(+), 118 deletions(-) diff --git a/app/code/core/Mage/Catalog/Helper/Product.php b/app/code/core/Mage/Catalog/Helper/Product.php index a68d47679..3ae4f96d7 100644 --- a/app/code/core/Mage/Catalog/Helper/Product.php +++ b/app/code/core/Mage/Catalog/Helper/Product.php @@ -217,59 +217,40 @@ public function canUseCanonicalTag($store = null) * 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 * + * @deprecated Instead use Mage::helper('eav')->getAttributeInputTypes() + * @see Mage_Eav_Helper_Data::getAttributeInputTypes() * @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)) { - return $inputTypes; - } elseif (isset($inputTypes[$inputType])) { - return $inputTypes[$inputType]; - } - return []; + return Mage::helper('eav')->getAttributeInputTypes($inputType); } /** * Return default attribute backend model by input type * + * @deprecated Instead use Mage::helper('eav')->getAttributeBackendModelByInputType() + * @see Mage_Eav_Helper_Data::getAttributeBackendModelByInputType() * @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')->getAttributeBackendModelByInputType($inputType); } /** * Return default attribute source model by input type * + * @deprecated Instead use Mage::helper('eav')->getAttributeSourceModelByInputType() + * @see Mage_Eav_Helper_Data::getAttributeSourceModelByInputType() * @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')->getAttributeSourceModelByInputType($inputType); } /** diff --git a/app/code/core/Mage/Eav/Helper/Data.php b/app/code/core/Mage/Eav/Helper/Data.php index fac674d7c..1aef8f338 100644 --- a/app/code/core/Mage/Eav/Helper/Data.php +++ b/app/code/core/Mage/Eav/Helper/Data.php @@ -180,12 +180,42 @@ 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' + 'text' => [ + 'backend_type' => 'varchar', + ], + 'textarea' => [ + 'backend_type' => 'text', + ], + 'select' => [ + 'backend_type' => 'int', + ], + 'multiselect' => [ + 'backend_model' => 'eav/entity_attribute_backend_array', + 'backend_type' => 'text', + ], + 'customselect' => [ + 'backend_type' => 'varchar', + 'source_model' => 'eav/entity_attribute_source_table', + ], + 'boolean' => [ + 'backend_type' => 'int', + 'source_model' => 'eav/entity_attribute_source_boolean', + ], + 'date' => [ + 'backend_type' => 'datetime', + ], + 'price' => [ + 'backend_type' => 'decimal', + ], + 'image' => [ + 'backend_type' => 'text', + ], + 'gallery' => [ + 'backend_type' => 'varchar', + ], + 'media_image' => [ + 'backend_type' => 'varchar', ], - 'boolean' => [ - 'source_model' => 'eav/entity_attribute_source_boolean' - ] ]; if (is_null($inputType)) { @@ -197,33 +227,61 @@ public function getAttributeInputTypes($inputType = null) } /** - * Return default attribute backend model by input type + * Return default attribute backend type by frontend input type + * + * @param string $inputType + * @return string|null + */ + public function getAttributeBackendTypeByInputType($inputType) + { + return $this->getAttributeInputTypes($inputType)['backend_type'] ?? null; + } + + /** + * Return default attribute backend model by frontend input type * * @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 $this->getAttributeInputTypes($inputType)['backend_model'] ?? null; } /** - * Return default attribute source model by input type + * Return default attribute source model by frontend input type * * @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 $this->getAttributeInputTypes($inputType)['source_model'] ?? null; + } + + /** + * Return default value field by frontend input type + * + * @param string $inputType + * @return string|null + */ + public function getDefaultValueFieldByInputType($inputType) + { + switch ($inputType) { + case 'text': + case 'price': + case 'image': + case 'weight': + return 'default_value_text'; + case 'textarea': + return 'default_value_textarea'; + case 'date': + return 'default_value_date'; + case 'boolean': + return 'default_value_yesno'; + default: + return null; } - return null; } /** diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Entity/Attribute.php index 519bec5ac..22e35f0f7 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute.php @@ -219,96 +219,40 @@ 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': - case 'customselect': - $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; + return Mage::helper('eav')->getAttributeBackendTypeByInputType($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 'customselect': - 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; + return Mage::helper('eav')->getDefaultValueFieldByInputType($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); } /** From ed8e6dfaf79d0570f9da9aa2156e23acc369c95b Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Tue, 5 Nov 2024 13:32:32 -0800 Subject: [PATCH 099/113] Big refactor --- .../Product/Attribute/Edit/Tab/Main.php | 113 +---- .../Adminhtml/Model/Customer/Observer.php | 60 +-- .../Catalog/Category/AttributeController.php | 6 +- .../Catalog/Category/SetController.php | 5 +- .../Catalog/Product/AttributeController.php | 61 +-- .../Customer/Address/AttributeController.php | 6 +- .../Customer/Address/SetController.php | 6 +- .../Customer/AttributeController.php | 6 +- .../controllers/Customer/SetController.php | 6 +- app/code/core/Mage/Adminhtml/etc/config.xml | 32 -- app/code/core/Mage/Catalog/Helper/Data.php | 16 +- app/code/core/Mage/Catalog/Helper/Product.php | 26 +- .../Catalog/Model/Product/Attribute/Api.php | 28 +- .../Product/Attribute/Source/Inputtype.php | 39 +- app/code/core/Mage/Catalog/etc/config.xml | 34 ++ app/code/core/Mage/Customer/etc/config.xml | 84 ++-- .../Mage/Eav/Block/Adminhtml/Attribute.php | 21 +- .../Eav/Block/Adminhtml/Attribute/Edit.php | 43 +- .../Attribute/Edit/Main/Abstract.php | 49 +- .../Adminhtml/Attribute/Edit/Tab/Main.php | 53 +- .../Eav/Block/Adminhtml/Attribute/Grid.php | 17 +- .../Eav/Block/Adminhtml/Attribute/Set.php | 18 +- .../Adminhtml/Attribute/Abstract.php | 362 +++++++------- .../Eav/Controller/Adminhtml/Set/Abstract.php | 169 +++---- app/code/core/Mage/Eav/Helper/Data.php | 468 ++++++++++-------- .../System/Config/Source/Inputtype.php | 17 +- .../Config/Source/Inputtype/Validator.php | 5 +- .../Mage/Eav/Model/Config/Source/Form.php | 49 -- .../core/Mage/Eav/Model/Entity/Attribute.php | 97 ++-- app/code/core/Mage/Eav/etc/config.xml | 86 +++- app/locale/en_US/Mage_Core.csv | 1 - app/locale/en_US/Mage_Eav.csv | 4 +- 32 files changed, 932 insertions(+), 1055 deletions(-) delete mode 100644 app/code/core/Mage/Eav/Model/Config/Source/Form.php 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 b7adffe65..8d2251cab 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 @@ -12,86 +12,39 @@ /** * Product attribute add/edit form main tab - * - * @category Mage - * @package Mage_Adminhtml */ 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]); } @@ -114,10 +67,9 @@ protected function _prepareForm() 'required' => true ]); - $fieldset->addField('is_configurable', 'select', [ + $fieldset->addField('is_configurable', 'boolean', [ 'name' => 'is_configurable', 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'), - 'values' => $yesnoSource, ]); $form->getElement('frontend_input') @@ -131,25 +83,22 @@ protected function _prepareForm() // 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', [ @@ -164,19 +113,17 @@ 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', [ @@ -187,43 +134,38 @@ protected function _prepareForm() 'class' => 'validate-digits', ]); - $fieldset->addField('is_wysiwyg_enabled', 'select', [ + $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', [ + $htmlAllowed = $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'), - 'values' => $yesnoSource, ]); 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); @@ -235,7 +177,6 @@ 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'); @@ -257,15 +198,13 @@ protected function _prepareForm() } /** - * 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/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php index f6ad7e59d..3b7bad6c7 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php @@ -11,34 +11,9 @@ /** * Customer EAV Observer - * - * @category Mage - * @package Mage_Adminhtml */ class Mage_Adminhtml_Model_Customer_Observer { - /** - * Add input types in customer and customer_address attribute edit forms - * - * @param Varien_Event_Observer $observer - * @return $this - */ - public function attributeAddInputTypes($observer) - { - /** @var Mage_Customer_Model_Attribute $attribute */ - $attribute = $observer->getAttribute(); - $attributeTypeCode = $attribute->getEntityType()->getEntityTypeCode(); - - /** @var Varien_Object $response */ - $response = $observer->getResponse(); - - $response->setTypes([ - ['value' => 'multiline', 'label' => Mage::helper('eav')->__('Multiline')], - ]); - - return $this; - } - /** * Modify customer and customer_address attribute edit forms * @@ -73,43 +48,16 @@ public function attributeEditPrepareForm($observer) if ($attribute->getAttributeCode() === 'street') { $form->getElement('multiline_count') - ->setMin(Mage_Customer_Helper_Address::STREET_LINES_MIN) - ->setMax(Mage_Customer_Helper_Address::STREET_LINES_MAX); + ->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; - } - - /** - * Save extra properties from customer and customer_address attribute edit forms - * - * @param Varien_Event_Observer $observer - * @return $this - */ - public function attributeEditPrepareSave($observer) - { - /** @var Mage_Core_Controller_Request_Http $request */ - $request = $observer->getRequest(); - - /** @var Mage_Eav_Model_Entity_Attribute $attribute */ - $attribute = $observer->getObject(); - - // $data = $request->getPost(); - // if ($data) { - // if (!$attribute->getWebsite()->getId()) { - // if (!isset($data['use_in_forms'])) { - // $data['use_in_forms'] = []; - // } - // $attribute->setData('used_in_forms', $data['use_in_forms']); - // } - // } + ->addFieldMap('multiline_count', 'multiline_count') + ->addFieldDependence('multiline_count', 'frontend_input', 'multiline'); return $this; } diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php index 07f0b193f..a0f8276ed 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/AttributeController.php @@ -4,16 +4,12 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Catalog category attribute controller - * - * @category Mage - * @package Mage_Adminhtml */ class Mage_Adminhtml_Catalog_Category_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { @@ -26,7 +22,7 @@ class Mage_Adminhtml_Catalog_Category_AttributeController extends Mage_Eav_Contr #[\Override] protected function _construct() { - $this->_entityCode = Mage_Catalog_Model_Category::ENTITY; + $this->entityTypeCode = Mage_Catalog_Model_Category::ENTITY; } #[\Override] diff --git a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php index d45518348..c761e58b7 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Category/SetController.php @@ -10,9 +10,6 @@ /** * Catalog category attribute sets controller - * - * @category Mage - * @package Mage_Adminhtml */ class Mage_Adminhtml_Catalog_Category_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { @@ -25,7 +22,7 @@ class Mage_Adminhtml_Catalog_Category_SetController extends Mage_Eav_Controller_ #[\Override] protected function _construct() { - $this->_entityCode = Mage_Catalog_Model_Category::ENTITY; + $this->entityTypeCode = Mage_Catalog_Model_Category::ENTITY; } #[\Override] 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 3f3253303..47b60da25 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php @@ -173,23 +173,19 @@ public function validateAction() protected function _filterPostData($data) { if ($data) { - /** @var Mage_Catalog_Helper_Data $helperCatalog */ - $helperCatalog = Mage::helper('catalog'); - //labels + // Labels $data['frontend_label'] = (array) $data['frontend_label']; foreach ($data['frontend_label'] as & $value) { if ($value) { - $value = $helperCatalog->stripTags($value); + $value = Mage::helper('catalog')->stripTags($value); } } - + // Options 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; + $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] - = $helperCatalog->stripTags($storeLabel, $allowableTags); + $data['option']['value'][$key][$storeId] = Mage::helper('catalog')->stripTags($storeLabel, $allowedTags); } } } @@ -203,16 +199,12 @@ public function saveAction() 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 + // 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'])) { @@ -224,7 +216,7 @@ public function saveAction() } } - //validate frontend_input + // 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'); @@ -239,6 +231,7 @@ public function saveAction() if ($id) { $model->load($id); + $inputType = $model->getFrontendInput(); if (!$model->getId()) { $session->addError( @@ -248,8 +241,8 @@ public function saveAction() return; } - // entity type check - if ($model->getEntityTypeId() != $this->_entityTypeId) { + // Entity type check + if ($model->getEntityTypeId() !== $this->_entityTypeId) { $session->addError( Mage::helper('catalog')->__('This attribute cannot be updated.') ); @@ -257,29 +250,17 @@ public function saveAction() $this->_redirect('*/*/'); return; } - - $data['backend_model'] = $model->getBackendModel(); - $data['attribute_code'] = $model->getAttributeCode(); - $data['is_user_defined'] = $model->getIsUserDefined(); - $data['entity_type_id'] = $model->getEntityTypeId(); - $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']); + $inputType = $data['frontend_input']; + + // Setup default values for new attribute $data['entity_type_id'] = $this->_entityType->getEntityTypeId(); $data['is_user_defined'] = 1; } - if (!$model->getBackendType() && (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0)) { - $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']); - } - - $defaultValueField = $model->getDefaultValueByInput($data['frontend_input']); + $defaultValueField = Mage::helper('eav')->getAttributeDefaultValueField($this->_entityCode, $inputType); if ($defaultValueField) { - $data['default_value'] = $this->getRequest()->getParam($defaultValueField); + $data['default_value'] = $data[$defaultValueField]; } if (!isset($data['is_configurable'])) { @@ -291,17 +272,16 @@ public function saveAction() if (!isset($data['is_filterable_in_search'])) { $data['is_filterable_in_search'] = 0; } - if (!isset($data['apply_to'])) { $data['apply_to'] = []; } - //filter + // Filter $data = $this->_filterPostData($data); $model->addData($data); + // For creating product attribute on product page we need specify attribute set and group 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')); } @@ -312,10 +292,9 @@ public function saveAction() Mage::helper('catalog')->__('The product attribute has been saved.') ); - /** - * 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]); + $session->setAttributeData(false); if ($this->getRequest()->getParam('popup')) { $this->_redirect('adminhtml/catalog_product/addAttribute', [ @@ -323,7 +302,7 @@ public function saveAction() 'attribute' => $model->getId(), '_current' => true ]); - } elseif ($redirectBack) { + } elseif ($this->getRequest()->getParam('back')) { $this->_redirect('*/*/edit', ['attribute_id' => $model->getId(),'_current' => true]); } else { $this->_redirect('*/*/', []); diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php index a8b1d7d86..d1428cb33 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php @@ -4,16 +4,12 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Customer address attribute controller - * - * @category Mage - * @package Mage_Adminhtml */ class Mage_Adminhtml_Customer_Address_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { @@ -26,7 +22,7 @@ class Mage_Adminhtml_Customer_Address_AttributeController extends Mage_Eav_Contr #[\Override] protected function _construct() { - $this->_entityCode = Mage_Customer_Model_Address::ENTITY; + $this->entityTypeCode = Mage_Customer_Model_Customer::ENTITY; } #[\Override] diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php index f6b9c8309..84674bf0e 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php @@ -4,16 +4,12 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Customer address attribute sets controller - * - * @category Mage - * @package Mage_Adminhtml */ class Mage_Adminhtml_Customer_Address_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { @@ -26,7 +22,7 @@ class Mage_Adminhtml_Customer_Address_SetController extends Mage_Eav_Controller_ #[\Override] protected function _construct() { - $this->_entityCode = Mage_Customer_Model_Address::ENTITY; + $this->entityTypeCode = Mage_Customer_Model_Customer::ENTITY; } #[\Override] diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php index 4c862ddb9..88340faa5 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/AttributeController.php @@ -4,16 +4,12 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Customer attribute controller - * - * @category Mage - * @package Mage_Adminhtml */ class Mage_Adminhtml_Customer_AttributeController extends Mage_Eav_Controller_Adminhtml_Attribute_Abstract { @@ -26,7 +22,7 @@ class Mage_Adminhtml_Customer_AttributeController extends Mage_Eav_Controller_Ad #[\Override] protected function _construct() { - $this->_entityCode = Mage_Customer_Model_Customer::ENTITY; + $this->entityTypeCode = Mage_Customer_Model_Customer::ENTITY; } #[\Override] diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php index faef84fb9..e19465d56 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/SetController.php @@ -4,16 +4,12 @@ * * @category Mage * @package Mage_Adminhtml - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Customer attribute sets controller - * - * @category Mage - * @package Mage_Adminhtml */ class Mage_Adminhtml_Customer_SetController extends Mage_Eav_Controller_Adminhtml_Set_Abstract { @@ -26,7 +22,7 @@ class Mage_Adminhtml_Customer_SetController extends Mage_Eav_Controller_Adminhtm #[\Override] protected function _construct() { - $this->_entityCode = Mage_Customer_Model_Customer::ENTITY; + $this->entityTypeCode = Mage_Customer_Model_Customer::ENTITY; } #[\Override] diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index e30d3e300..f0c4c9ffb 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -127,14 +127,6 @@ - - - - adminhtml/customer_observer - attributeAddInputTypes - - - @@ -143,22 +135,6 @@ - - - - adminhtml/customer_observer - attributeEditPrepareSave - - - - - - - adminhtml/customer_observer - attributeAddInputTypes - - - @@ -167,14 +143,6 @@ - - - - adminhtml/customer_observer - attributeEditPrepareSave - - - diff --git a/app/code/core/Mage/Catalog/Helper/Data.php b/app/code/core/Mage/Catalog/Helper/Data.php index 8c3afb100..56d747fcf 100644 --- a/app/code/core/Mage/Catalog/Helper/Data.php +++ b/app/code/core/Mage/Catalog/Helper/Data.php @@ -184,29 +184,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 3ae4f96d7..20bb00844 100644 --- a/app/code/core/Mage/Catalog/Helper/Product.php +++ b/app/code/core/Mage/Catalog/Helper/Product.php @@ -213,44 +213,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')->getAttributeInputTypes() - * @see Mage_Eav_Helper_Data::getAttributeInputTypes() + * @deprecated Instead use Mage::helper('eav')->getInputTypes() + * @see Mage_Eav_Helper_Data::getInputTypes() * @param string $inputType * @return array */ public function getAttributeInputTypes($inputType = null) { - return Mage::helper('eav')->getAttributeInputTypes($inputType); + $inputTypes = Mage::helper('eav')->getInputTypes(Mage_Catalog_Model_Product::ENTITY); + if ($inputType === null) { + return $inputTypes; + } + return $inputTypes[$inputType] ?? []; } /** * Return default attribute backend model by input type * - * @deprecated Instead use Mage::helper('eav')->getAttributeBackendModelByInputType() - * @see Mage_Eav_Helper_Data::getAttributeBackendModelByInputType() + * @deprecated Instead use Mage::helper('eav')->getAttributeBackendModel() + * @see Mage_Eav_Helper_Data::getAttributeBackendModel() * @param string $inputType * @return string|null */ public function getAttributeBackendModelByInputType($inputType) { - return Mage::helper('eav')->getAttributeBackendModelByInputType($inputType); + 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')->getAttributeSourceModelByInputType() - * @see Mage_Eav_Helper_Data::getAttributeSourceModelByInputType() + * @deprecated Instead use Mage::helper('eav')->getAttributeSourceModel() + * @see Mage_Eav_Helper_Data::getAttributeSourceModel() * @param string $inputType * @return string|null */ public function getAttributeSourceModelByInputType($inputType) { - return Mage::helper('eav')->getAttributeSourceModelByInputType($inputType); + 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 38ec508f4..62173c81a 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php +++ b/app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php @@ -116,7 +116,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 +129,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 +158,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/etc/config.xml b/app/code/core/Mage/Catalog/etc/config.xml index 0b606ee56..9c286715b 100644 --- a/app/code/core/Mage/Catalog/etc/config.xml +++ b/app/code/core/Mage/Catalog/etc/config.xml @@ -653,6 +653,40 @@ + + + + + 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/Customer/etc/config.xml b/app/code/core/Mage/Customer/etc/config.xml index 2c730c47a..855adb817 100644 --- a/app/code/core/Mage/Customer/etc/config.xml +++ b/app/code/core/Mage/Customer/etc/config.xml @@ -454,39 +454,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -569,6 +536,57 @@ + + + + + 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 + + + diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php index c0507a863..682d365f1 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php @@ -4,29 +4,30 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** - * Adminhtml attributes block - * - * @category Mage - * @package Mage_Eav + * Adminhtml attribute block */ class Mage_Eav_Block_Adminhtml_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Container { public function __construct() { + /** @var Mage_Eav_Model_Entity_Type $entityType */ + $entityType = Mage::registry('entity_type'); + $this->_blockGroup = 'eav'; $this->_controller = 'adminhtml_attribute'; - if ($entityType = Mage::registry('entity_type')) { - $this->_headerText = Mage::helper('eav')->__('Manage %s Attributes', Mage::helper('eav')->formatTypeCode($entityType)); - } else { - $this->_headerText = Mage::helper('eav')->__('Manage Attributes'); - } + + $this->_headerText = $this->__( + 'Manage %s Attributes', + Mage::helper('eav')->formatTypeCode($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 index 17bac8d84..0e965c244 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php @@ -15,31 +15,33 @@ */ class Mage_Eav_Block_Adminhtml_Attribute_Edit extends Mage_Adminhtml_Block_Widget_Form_Container { + protected Mage_Eav_Model_Entity_Type $entityType; + protected Mage_Eav_Model_Attribute $entityAttribute; + public function __construct() { + $this->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' => Mage::helper('eav')->__('Save and Continue Edit'), - 'onclick' => 'saveAndContinueEdit()', - 'class' => 'save' - ], - 100 - ); + $this->_addButton('save_and_edit_button', [ + 'label' => $this->__('Save and Continue Edit'), + 'onclick' => 'saveAndContinueEdit()', + 'class' => 'save' + ], 100); - $this->_updateButton('save', 'label', Mage::helper('eav')->__('Save Attribute')); + $this->_updateButton('save', 'label', $this->__('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('eav')->__('Delete Attribute')); + $this->_removeButton('delete'); } } @@ -49,12 +51,17 @@ public function __construct() #[\Override] public function getHeaderText() { - $entityType = Mage::registry('entity_type'); - $entityAttribute = Mage::registry('entity_attribute'); - if ($entityAttribute->getId()) { - return Mage::helper('eav')->__('Edit %s Attribute "%s"', Mage::helper('eav')->formatTypeCode($entityType), $entityAttribute->getFrontendLabel()); + if ($this->entityAttribute->getId()) { + return $this->__( + 'Edit %s Attribute "%s"', + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()), + $this->entityAttribute->getFrontendLabel() + ); } - return Mage::helper('eav')->__('New %s Attribute', Mage::helper('eav')->formatTypeCode($entityType)); + return $this->__( + 'New %s Attribute', + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()), + ); } /** 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 ba6afecc8..1e977d71c 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 @@ -67,6 +67,7 @@ protected function _prepareLayout() protected function _prepareForm() { $attributeObject = $this->getAttributeObject(); + $entityTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); $form = new Varien_Data_Form([ 'id' => 'edit_form', @@ -96,78 +97,80 @@ 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')->__('Input Type'), - 'title' => Mage::helper('eav')->__('Input Type'), - '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($attributeObject->getEntityType()->getEntityTypeCode()) + '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', + 'name' => 'is_required', 'label' => Mage::helper('eav')->__('Values Required'), 'title' => Mage::helper('eav')->__('Values Required'), ]); $fieldset->addField('is_unique', 'boolean', [ - 'name' => 'is_unique', + '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'), + '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', 'boolean', [ - 'name' => 'default_value_yesno', + 'name' => 'default_value_yesno', 'label' => Mage::helper('eav')->__('Default Value'), 'title' => Mage::helper('eav')->__('Default Value'), '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(), ]); if ($attributeObject->getResource()->hasFormTable()) { - $attributeObjectTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); $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::getModel('eav/config_source_form')->toOptionArray($attributeObjectTypeCode), + 'values' => Mage::helper('eav')->getForms($entityTypeCode), 'value' => $attributeObject->getUsedInForms(), ]); } 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 index ebbceb4e7..15ce9c140 100644 --- 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 @@ -24,59 +24,10 @@ protected function _prepareForm() parent::_prepareForm(); $attributeObject = $this->getAttributeObject(); $attributeTypeCode = $attributeObject->getEntityType()->getEntityTypeCode(); - /* @var $form Varien_Data_Form */ - $form = $this->getForm(); - /* @var $fieldset Varien_Data_Form_Element_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.') - ); - - $fieldset->getElements() - ->searchById('is_unique') - ->setData( - 'title', - Mage::helper('eav')->__('Unique Value (not shared with other %s)', strtolower(Mage::helper('eav')->formatTypeCode($attributeTypeCode))) - )->setData( - 'note', - Mage::helper('eav')->__('Not shared with other %s', strtolower(Mage::helper('eav')->formatTypeCode($attributeTypeCode))) - ); - - $frontendInputElm = $form->getElement('frontend_input'); - $additionalTypes = []; - $response = new Varien_Object(); - $response->setTypes([]); - Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_types", [ - 'response' => $response, - 'attribute' => $attributeObject - ]); - $_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']; - } - } - Mage::register('attribute_type_hidden_fields', $_hiddenFields); - Mage::register('attribute_type_disabled_types', $_disabledTypes); - - $frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes); - $frontendInputElm->setValues($frontendInputValues); + /** @var Varien_Data_Form $form */ + $form = $this->getForm(); - // define field dependencies /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $block */ $block = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence'); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php index dab56cd2c..1a85968c4 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php @@ -21,17 +21,18 @@ class Mage_Eav_Block_Adminhtml_Attribute_Grid extends Mage_Eav_Block_Adminhtml_A #[\Override] protected function _prepareCollection() { - if ($entityType = Mage::registry('entity_type')) { - $hiddenAttributes = Mage::helper('eav')->getHiddenAttributes($entityType->getEntityTypeCode()); + /** @var Mage_Eav_Model_Entity_Type $entityType */ + $entityType = Mage::registry('entity_type'); - /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection */ - $collection = Mage::getResourceModel($entityType->getEntityAttributeCollection()); + /** TODO additionally use customer_eav_attribute is_visible */ + $hiddenAttributes = Mage::helper('eav')->getHiddenAttributes($entityType->getEntityTypeCode()); - $collection->setEntityTypeFilter($entityType->getEntityTypeId()) - ->setNotCodeFilter($hiddenAttributes); + /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection */ + $collection = Mage::getResourceModel($entityType->getEntityAttributeCollection()); + $collection->setEntityTypeFilter($entityType->getEntityTypeId()) + ->setNotCodeFilter($hiddenAttributes); - $this->setCollection($collection); - } + $this->setCollection($collection); return parent::_prepareCollection(); } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php index 64178d0ce..471f6ce2b 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php @@ -4,28 +4,28 @@ * * @category Mage * @package Mage_Eav - * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2024 Maho (https://mahocommerce.com) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Adminhtml attribute sets block - * - * @category Mage - * @package Mage_Eav */ class Mage_Eav_Block_Adminhtml_Attribute_Set extends Mage_Adminhtml_Block_Widget_Grid_Container { public function __construct() { + /** @var Mage_Eav_Model_Entity_Type $entityType */ + $entityType = Mage::registry('entity_type'); + $this->_blockGroup = 'eav'; $this->_controller = 'adminhtml_attribute_set'; - if ($entityType = Mage::registry('entity_type')) { - $this->_headerText = Mage::helper('eav')->__('Manage %s Attribute Sets', Mage::helper('eav')->formatTypeCode($entityType)); - } else { - $this->_headerText = Mage::helper('eav')->__('Manage Attribute Sets'); - } + + $this->_headerText = $this->__( + 'Manage %s Attribute Sets', + Mage::helper('eav')->formatTypeCode($entityType->getEntityTypeCode()) + ); + $this->_addButtonLabel = Mage::helper('eav')->__('Add New Set'); parent::__construct(); } diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php index 39e220fc2..f625cf1ab 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -10,18 +10,12 @@ */ /** - * Attribute controller - * - * @category Mage - * @package Mage_Eav + * Abstract attribute controller */ abstract class Mage_Eav_Controller_Adminhtml_Attribute_Abstract extends Mage_Adminhtml_Controller_Action { - /** @var string */ - protected $_entityCode; - - /** @var Mage_Eav_Model_Entity_Type */ - protected $_entityType; + protected string $entityTypeCode; + protected Mage_Eav_Model_Entity_Type $entityType; /** * Controller predispatch method @@ -31,11 +25,10 @@ abstract class Mage_Eav_Controller_Adminhtml_Attribute_Abstract extends Mage_Adm #[\Override] public function preDispatch() { + $this->entityType = Mage::getSingleton('eav/config')->getEntityType($this->entityTypeCode); + Mage::register('entity_type', $this->entityType, true); + $this->_setForcedFormKeyActions('delete'); - $this->_entityType = Mage::getModel('eav/entity')->setType($this->_entityCode)->getEntityType(); - if (!Mage::registry('entity_type')) { - Mage::register('entity_type', $this->_entityType); - } return parent::preDispatch(); } @@ -59,62 +52,73 @@ public function newAction() public function editAction() { $id = $this->getRequest()->getParam('attribute_id'); - $model = Mage::getModel($this->_entityType->getAttributeModel()) - ->setEntityTypeId($this->_entityType->getEntityTypeId()); + + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + $attribute = Mage::getModel($this->entityType->getAttributeModel()); + if ($id) { if ($websiteId = $this->getRequest()->getParam('website')) { - $model->setWebsite($websiteId); + $attribute->setWebsite($websiteId); } - $model->load($id); + $attribute->load($id); - if (!$model->getId()) { + if (!$attribute->getId()) { Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('eav')->__('This attribute no longer exists') + $this->__('This attribute no longer exists') ); $this->_redirect('*/*/'); return; } - // entity type check - if ($model->getEntityTypeId() != $this->_entityType->getEntityTypeId()) { + // Entity type check + if ($attribute->getEntityTypeId() != $this->entityType->getEntityTypeId()) { Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('eav')->__('This attribute cannot be edited.') + $this->__('This attribute cannot be edited.') ); $this->_redirect('*/*/'); return; } + } else { + $attribute->setEntityTypeId($this->entityType->getEntityTypeId()); } - // set entered data if was error when we do save + // 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 ($model->getWebsite() && (int)$model->getWebsite()->getId()) { - foreach ($model->getResource()->getScopeFields($model) as $field) { + 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]); } } } - $model->addData($data); + $attribute->addData($data); } - Mage::register('entity_attribute', $model); + Mage::register('entity_attribute', $attribute); $this->_initAction(); - $this->_title($id ? $model->getName() : $this->__('New Attribute')); - - $item = $id ? Mage::helper('eav')->__('Edit Attribute') - : Mage::helper('eav')->__('New Attribute'); - - $this->_addBreadcrumb($item, $item); + 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 && $model->getResource()->hasScopeTable()) { + if ($id && $attribute->getResource()->hasScopeTable()) { $this->_addLeft( $this->getLayout()->createBlock('adminhtml/website_switcher') ->setDefaultWebsiteName($this->__('Default Values')) @@ -135,19 +139,19 @@ public function editAction() public function validateAction() { + $attributeId = $this->getRequest()->getParam('attribute_id'); + $attributeCode = $this->getRequest()->getParam('attribute_code'); + $response = new Varien_Object(); $response->setError(false); - $attributeCode = $this->getRequest()->getParam('attribute_code'); - $attributeId = $this->getRequest()->getParam('attribute_id'); - /** @var Mage_Eav_Model_Entity_Attribute $attribute */ - $attribute = Mage::getModel($this->_entityType->getAttributeModel()); - $attribute->loadByCode($this->_entityType->getEntityTypeId(), $attributeCode); + $attribute = Mage::getModel($this->entityType->getAttributeModel()); + $attribute->loadByCode($this->entityType->getEntityTypeId(), $attributeCode); if ($attribute->getId() && !$attributeId) { Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('eav')->__('Attribute with the same code already exists') + $this->__('Attribute with the same code already exists') ); $this->_initLayoutMessages('adminhtml/session'); $response->setError(true); @@ -166,14 +170,14 @@ public function validateAction() protected function _filterPostData($data) { if ($data) { - // labels + // Labels $data['frontend_label'] = (array) $data['frontend_label']; foreach ($data['frontend_label'] as & $value) { if ($value) { $value = Mage::helper('eav')->stripTags($value); } } - + // Options 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) { @@ -187,187 +191,157 @@ protected function _filterPostData($data) public function saveAction() { - $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_Eav_Model_Entity_Attribute $model */ - $model = Mage::getModel($this->_entityType->getAttributeModel()); - /** @var Mage_Eav_Helper_Data $helper */ - $helper = Mage::helper('eav'); - - $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('eav')->__('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; - } - } + $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()); - // 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; - } - } + /** @var Mage_Admin_Model_Session $session */ + $session = Mage::getSingleton('adminhtml/session'); - if ($id) { - if ($websiteId = $this->getRequest()->getParam('website')) { - $model->setWebsite($websiteId); - } - $model->load($id); - - if (!$model->getId()) { - $session->addError( - Mage::helper('eav')->__('This Attribute no longer exists') - ); - $this->_redirect('*/*/'); - return; - } + /** @var Mage_Eav_Helper_Data $helper */ + $helper = Mage::helper('eav'); - // entity type check - if ($model->getEntityTypeId() != $this->_entityType->getEntityTypeId()) { - $session->addError( - Mage::helper('eav')->__('This attribute cannot be updated.') - ); - $session->setAttributeData($data); - $this->_redirect('*/*/'); - return; - } + // 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; + } + } - $data['backend_model'] = $model->getBackendModel(); - $data['attribute_code'] = $model->getAttributeCode(); - $data['is_user_defined'] = $model->getIsUserDefined(); - $data['entity_type_id'] = $model->getEntityTypeId(); - $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']); - $data['entity_type_id'] = $this->_entityType->getEntityTypeId(); - $data['is_user_defined'] = 1; + if ($id) { + if ($websiteId = $this->getRequest()->getParam('website')) { + $attribute->setWebsite($websiteId); } + $attribute->load($id); + $inputType = $attribute->getFrontendInput(); - if (!$model->getBackendType() && (is_null($model->getIsUserDefined()) || $model->getIsUserDefined() != 0)) { - $data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']); + if (!$attribute->getId()) { + $session->addError( + $this->__('This Attribute no longer exists') + ); + $this->_redirect('*/*/'); + return; } - $defaultValueField = $model->getDefaultValueByInput($data['frontend_input']); - if ($defaultValueField) { - $data['default_value'] = $this->getRequest()->getParam($defaultValueField); + // 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; + } - // filter - $data = $this->_filterPostData($data); + $defaultValueField = $helper->getAttributeDefaultValueField($this->entityTypeCode, $inputType); + if ($defaultValueField) { + $data['default_value'] = $data[$defaultValueField]; + } - if ($model->getWebsite() && (int)$model->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; - } + 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; } - // Prefix relevant fields in POST data - foreach ($model->getResource()->getScopeFields($model) as $field) { - if (array_key_exists($field, $data)) { - $data['scope_' . $field] = $data[$field]; - unset($data[$field]); - } + if (in_array($defaultValueField, $useDefaults)) { + $data['default_value'] = null; } - } else { - // Check for no forms selected and set to empty array - if ($model->getResource()->hasFormTable()) { - if (!isset($data['used_in_forms'])) { - $data['used_in_forms'] = []; - } + } + // 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'] = []; + } + } + } - $model->addData($data); + $attribute->addData($data); - Mage::dispatchEvent( - "adminhtml_{$this->_entityCode}_attribute_edit_prepare_save", - ['object' => $model, 'request' => $this->getRequest()] + 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.') ); - try { - $model->save(); - $session->addSuccess( - Mage::helper('eav')->__('The attribute has been saved.') - ); + // Clear translation cache because attribute labels are stored in translation + Mage::app()->cleanCache([Mage_Core_Model_Translate::CACHE_TAG]); - /** - * Clear translation cache because attribute labels are stored in translation - */ - Mage::app()->cleanCache([Mage_Core_Model_Translate::CACHE_TAG]); - $session->setAttributeData(false); - if ($redirectBack) { - $this->_redirect('*/*/edit', ['attribute_id' => $model->getId(),'_current' => true]); - } else { - $this->_redirect('*/*/', []); - } - return; - } catch (Exception $e) { - $session->addError($e->getMessage()); - $session->setAttributeData($data); - $this->_redirect('*/*/edit', ['attribute_id' => $id, '_current' => true]); - return; + $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]); } - $this->_redirect('*/*/'); } public function deleteAction() { - if ($id = $this->getRequest()->getParam('attribute_id')) { - $model = Mage::getModel($this->_entityType->getAttributeModel()); + $id = $this->getRequest()->getParam('attribute_id'); + if (!$id) { + Mage::getSingleton('adminhtml/session')->addError( + $this->__('Unable to find an attribute to delete.') + ); + $this->_redirect('*/*/'); + return; + } - // entity type check - $model->load($id); - if ($model->getEntityTypeId() != $this->_entityType->getEntityTypeId() || !$model->getIsUserDefined()) { - Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('eav')->__('This attribute cannot be deleted.') - ); - $this->_redirect('*/*/'); - return; - } + /** @var Mage_Eav_Model_Entity_Attribute $attribute */ + $attribute = Mage::getModel($this->entityType->getAttributeModel()); - try { - $model->delete(); - Mage::getSingleton('adminhtml/session')->addSuccess( - Mage::helper('eav')->__('The 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; - } + // 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')]); } - Mage::getSingleton('adminhtml/session')->addError( - Mage::helper('eav')->__('Unable to find an attribute to delete.') - ); - $this->_redirect('*/*/'); } } diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php index f87a697af..d163ab970 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php @@ -10,18 +10,12 @@ */ /** - * Attribute set controller - * - * @category Mage - * @package Mage_Eav + * Abstract attribute set controller */ abstract class Mage_Eav_Controller_Adminhtml_Set_Abstract extends Mage_Adminhtml_Controller_Action { - /** @var string */ - protected $_entityCode; - - /** @var Mage_Eav_Model_Entity_Type */ - protected $_entityType; + protected string $entityTypeCode; + protected Mage_Eav_Model_Entity_Type $entityType; /** * Controller predispatch method @@ -31,11 +25,10 @@ abstract class Mage_Eav_Controller_Adminhtml_Set_Abstract extends Mage_Adminhtml #[\Override] public function preDispatch() { + $this->entityType = Mage::getSingleton('eav/config')->getEntityType($this->entityTypeCode); + Mage::register('entity_type', $this->entityType, true); + $this->_setForcedFormKeyActions('delete'); - $this->_entityType = Mage::getModel('eav/entity')->setType($this->_entityCode)->getEntityType(); - if (!Mage::registry('entity_type')) { - Mage::register('entity_type', $this->_entityType); - } return parent::preDispatch(); } @@ -51,8 +44,26 @@ public function indexAction() ->renderLayout(); } + public function setGridAction() + { + $this->getResponse()->setBody( + $this->getLayout() + ->createBlock('eav/adminhtml_attribute_set_grid') + ->toHtml() + ); + } + + public function addAction() + { + $this->_initAction() + ->_title($this->__('New Set')) + ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_set_toolbar_add')) + ->renderLayout(); + } + public function editAction() { + /** @var Mage_Eav_Model_Entity_Attribute_Set $attributeSet */ $attributeSet = Mage::getModel('eav/entity_attribute_set') ->load($this->getRequest()->getParam('id')); @@ -70,62 +81,64 @@ public function editAction() $this->renderLayout(); } - public function setGridAction() + public function createFromSkeletonSetAction() { - $this->getResponse()->setBody( - $this->getLayout() - ->createBlock('eav/adminhtml_attribute_set_grid') - ->toHtml() - ); + /** @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()]); + } } - /** - * Save attribute set action - * - * [POST] Create attribute set from another set and redirect to edit page - * [AJAX] Save attribute set data - * - */ public function saveAction() { - $entityTypeId = $this->_entityType->getEntityTypeId(); - $hasError = false; - $attributeSetId = $this->getRequest()->getParam('id', false); - $isNewSet = $this->getRequest()->getParam('gotoEdit', false) == '1'; + 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_Eav_Model_Entity_Attribute_Set $model */ - $model = Mage::getModel('eav/entity_attribute_set') - ->setEntityTypeId($entityTypeId); + /** @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 ($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('eav')->__('This attribute set no longer exists.')); - } - $data = Mage::helper('core')->jsonDecode($this->getRequest()->getPost('data')); - - //filter html tags - $data['attribute_set_name'] = $helper->stripTags($data['attribute_set_name']); - - $model->organizeData($data); + 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(); - $model->validate(); - if ($isNewSet) { - $model->save(); - $model->initFromSkeleton($this->getRequest()->getParam('skeleton_set')); - } - $model->save(); $this->_getSession()->addSuccess(Mage::helper('eav')->__('The attribute set has been saved.')); } catch (Mage_Core_Exception $e) { $this->_getSession()->addError($e->getMessage()); @@ -138,41 +151,29 @@ public function saveAction() $hasError = true; } - if ($isNewSet) { - if ($hasError) { - $this->_redirect('*/*/add'); - } else { - $this->_redirect('*/*/edit', ['id' => $model->getId()]); - } + if ($hasError) { + $this->_initLayoutMessages('adminhtml/session'); + $response = [ + 'error' => 1, + 'message' => $this->getLayout()->getMessagesBlock()->getGroupedHtml(), + ]; } 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)); + $response = [ + 'error' => 0, + 'url' => $this->getUrl('*/*/'), + ]; } - } - - public function addAction() - { - $this->_initAction() - ->_title($this->__('New Set')) - ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_set_toolbar_add')) - ->renderLayout(); + $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response)); } public function deleteAction() { - $setId = $this->getRequest()->getParam('id'); + /** @var Mage_Eav_Model_Entity_Attribute_Set $attributeSet */ + $attributeSet = Mage::getModel('eav/entity_attribute_set') + ->load($this->getRequest()->getParam('id')); + try { - Mage::getModel('eav/entity_attribute_set') - ->setId($setId) - ->delete(); + $attributeSet->delete(); $this->_getSession()->addSuccess($this->__('The attribute set has been removed.')); $this->getResponse()->setRedirect($this->getUrl('*/*/')); diff --git a/app/code/core/Mage/Eav/Helper/Data.php b/app/code/core/Mage/Eav/Helper/Data.php index 1aef8f338..bcfd476f3 100644 --- a/app/code/core/Mage/Eav/Helper/Data.php +++ b/app/code/core/Mage/Eav/Helper/Data.php @@ -10,294 +10,376 @@ */ /** - * 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'; - - protected $_attributesHidden = []; + /** @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 $this->getFrontendClasses('default'); } /** - * Return merged default and entity type frontend classes value label array + * 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] - ); - } - $_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->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; } - return array_merge( - $_defaultClasses, - $this->_entityTypeFrontendClasses[$entityTypeCode] - ); + + $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 $_defaultClasses; + return $this->cacheFrontendClasses[$entityTypeCode]; } /** - * Retrieve hidden attributes for entity type + * Return attribute adminhtml display info per entity type as defined in config.xml or set by observers * - * @param string $entityTypeCode - * @return array + * 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 getHiddenAttributes($entityTypeCode) + public function getAttributeDisplayInfo(string $entityTypeCode): array { - if (!$entityTypeCode) { + if (empty($entityTypeCode)) { return []; } - if (isset($this->_attributesHidden[$entityTypeCode])) { - return $this->_attributesHidden[$entityTypeCode]; - } - $_data = Mage::app()->getConfig()->getNode('global/eav_attributes/' . $entityTypeCode); - if ($_data) { - $this->_attributesHidden[$entityTypeCode] = []; - foreach ($_data->children() as $attribute) { - if ($attribute->is('hidden')) { - $this->_attributesHidden[$entityTypeCode][] = $attribute->code; + 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; } } - return $this->_attributesHidden[$entityTypeCode]; + $response = new Varien_Object(['attributes' => $attributes]); + Mage::dispatchEvent("adminhtml_{$entityTypeCode}_attribute_displayinfo", ['response' => $response]); + $this->cacheAttributeDisplayInfo[$entityTypeCode] = $response->getAttributes(); } - return []; + return $this->cacheAttributeDisplayInfo[$entityTypeCode]; } /** - * Retrieve attributes locked fields to edit + * 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 $hiddenAttributes; + } + + /** + * 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) { - $this->_attributesLockedFields[$entityTypeCode] = []; - foreach ($_data->children() as $attribute) { - if (isset($attribute->locked_fields)) { - $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 information array of 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 input types per entity type as defined in config.xml or set by observers * - * @param string $inputType - * @return array + * 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 + * - disabled_types: (array) product types to remove from the "Apply To" dropdown, examples: + * - 'simple' + * - 'bundle' + * - 'configurable' + * - 'grouped' + * - 'virtual' + * + * See nodes in various config.xml files for examples */ - public function getAttributeInputTypes($inputType = null) + public function getInputTypes(string $entityTypeCode): array { - /** - * @todo specify there all relations for properties depending on input type - */ - $inputTypes = [ - 'text' => [ - 'backend_type' => 'varchar', - ], - 'textarea' => [ - 'backend_type' => 'text', - ], - 'select' => [ - 'backend_type' => 'int', - ], - 'multiselect' => [ - 'backend_model' => 'eav/entity_attribute_backend_array', - 'backend_type' => 'text', - ], - 'customselect' => [ - 'backend_type' => 'varchar', - 'source_model' => 'eav/entity_attribute_source_table', - ], - 'boolean' => [ - 'backend_type' => 'int', - 'source_model' => 'eav/entity_attribute_source_boolean', - ], - 'date' => [ - 'backend_type' => 'datetime', - ], - 'price' => [ - 'backend_type' => 'decimal', - ], - 'image' => [ - 'backend_type' => 'text', - ], - 'gallery' => [ - 'backend_type' => 'varchar', - ], - 'media_image' => [ - 'backend_type' => 'varchar', - ], - ]; + 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 (is_null($inputType)) { - return $inputTypes; - } elseif (isset($inputTypes[$inputType])) { - return $inputTypes[$inputType]; + 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(); + } + $this->cacheInputTypes[$entityTypeCode] = $inputTypes; } - return []; + return $this->cacheInputTypes[$entityTypeCode]; } /** * Return default attribute backend type by frontend input type - * - * @param string $inputType - * @return string|null */ - public function getAttributeBackendTypeByInputType($inputType) + public function getAttributeBackendType(string $entityTypeCode, string $inputType): ?string { - return $this->getAttributeInputTypes($inputType)['backend_type'] ?? null; + $inputTypes = $this->getInputTypes($entityTypeCode); + foreach ($inputTypes as $type) { + if ($inputType === $type['value']) { + return $type['backend_type'] ?? null; + } + } + return null; } /** * Return default attribute backend model by frontend input type - * - * @param string $inputType - * @return string|null */ - public function getAttributeBackendModelByInputType($inputType) + public function getAttributeBackendModel(string $entityTypeCode, string $inputType): ?string { - return $this->getAttributeInputTypes($inputType)['backend_model'] ?? null; + $inputTypes = $this->getInputTypes($entityTypeCode); + foreach ($inputTypes as $type) { + if ($inputType === $type['value']) { + return $type['backend_model'] ?? null; + } + } + return null; + } + + /** + * Return default attribute frontend model by frontend input type + */ + public function getAttributeFrontendModel(string $entityTypeCode, string $inputType): ?string + { + $inputTypes = $this->getInputTypes($entityTypeCode); + foreach ($inputTypes as $type) { + if ($inputType === $type['value']) { + return $type['frontend_model'] ?? null; + } + } + return null; } /** * Return default attribute source model by frontend input type - * - * @param string $inputType - * @return string|null */ - public function getAttributeSourceModelByInputType($inputType) + public function getAttributeSourceModel(string $entityTypeCode, string $inputType): ?string { - return $this->getAttributeInputTypes($inputType)['source_model'] ?? null; + $inputTypes = $this->getInputTypes($entityTypeCode); + foreach ($inputTypes as $type) { + if ($inputType === $type['value']) { + return $type['source_model'] ?? null; + } + } + return null; } /** * Return default value field by frontend input type - * - * @param string $inputType - * @return string|null */ - public function getDefaultValueFieldByInputType($inputType) + public function getAttributeDefaultValueField(string $entityTypeCode, string $inputType): ?string { - switch ($inputType) { - case 'text': - case 'price': - case 'image': - case 'weight': - return 'default_value_text'; - case 'textarea': - return 'default_value_textarea'; - case 'date': - return 'default_value_date'; - case 'boolean': - return 'default_value_yesno'; - default: - return null; + $inputTypes = $this->getInputTypes($entityTypeCode); + foreach ($inputTypes as $type) { + if ($inputType === $type['value']) { + return $type['default_value_field'] ?? null; + } } + return null; } /** - * Return entity code formatted for humans - * - * @param Mage_Eav_Model_Entity_Type|string $entityTypeCode - * @return string + * Return hidden fields per input type when editing attribute for entity type + */ + public function getInputTypeHiddenFields(string $entityTypeCode): array + { + $hiddenFields = []; + foreach ($this->getInputTypes($entityTypeCode) as $type) { + if (isset($type['hide_fields'])) { + $hiddenFields[$type['value']] = $type['hide_fields']; + } + } + return $hiddenFields; + } + + /** + * Return disable fields per input type when editing attribute for entity type */ - public function formatTypeCode($entityTypeCode) + public function getInputTypeDisabledApplyToOptions(string $entityTypeCode): array { - if ($entityTypeCode instanceof Mage_Eav_Model_Entity_Type) { - $entityTypeCode = $entityTypeCode->getEntityTypeCode(); + $disabledTypes = []; + foreach ($this->getInputTypes($entityTypeCode) as $type) { + if (isset($type['disabled_types'])) { + $disabledTypes[$type['value']] = $type['disabled_types']; + } } - if (!is_string($entityTypeCode)) { - $entityTypeCode = ''; + return $disabledTypes; + } + + /** + * 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 + { + switch ($entityTypeCode) { + case Mage_Catalog_Model_Product::ENTITY: + return 'Product'; + case Mage_Catalog_Model_Category::ENTITY: + return 'Category'; + default: + return ucwords(str_replace('_', ' ', $entityTypeCode)); } - return 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 39b172294..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,14 +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')], - ['value' => 'customselect', 'label' => Mage::helper('eav')->__('Dropdown with Other Option')], - ]; + 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 aa7ea18b5..79ae63635 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 @@ -6,14 +6,15 @@ * @package Mage_Eav * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) * @copyright Copyright (c) 2019-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) */ /** * 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/Config/Source/Form.php b/app/code/core/Mage/Eav/Model/Config/Source/Form.php deleted file mode 100644 index a28272b73..000000000 --- a/app/code/core/Mage/Eav/Model/Config/Source/Form.php +++ /dev/null @@ -1,49 +0,0 @@ -getNode(self::XML_PATH_EAV_FORMS . '/' . $entity); - if ($node === false) { - return []; - } - - $forms = []; - foreach ($node->children() as $form) { - $moduleName = $form->getAttribute('module') ?? 'eav'; - $translatedLabel = Mage::helper($moduleName)->__((string)$form->label[0]); - $forms[] = [ - 'label' => $translatedLabel, - 'value' => $form->getName() - ]; - } - return $forms; - } - - public function toOptionHash(string $entity = ''): array - { - $optionArray = $this->toOptionArray($entity); - return array_combine( - array_column($optionArray, 'value'), - array_column($optionArray, 'label') - ); - } -} diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Entity/Attribute.php index 22e35f0f7..a2c8c9744 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute.php @@ -42,6 +42,7 @@ class Mage_Eav_Model_Entity_Attribute extends Mage_Eav_Model_Entity_Attribute_Ab */ protected $_eventPrefix = 'eav_entity_attribute'; + public const ATTRIBUTE_CODE_MIN_LENGTH = 1; public const ATTRIBUTE_CODE_MAX_LENGTH = 30; /** @@ -144,49 +145,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(); @@ -197,12 +210,6 @@ protected function _beforeSave() } } - if ($this->getBackendType() == 'gallery') { - if (!$this->getBackendModel()) { - $this->setBackendModel('eav/entity_attribute_backend_media'); - } - } - return parent::_beforeSave(); } @@ -228,7 +235,8 @@ protected function _afterSave() */ public function getBackendTypeByInput($inputType) { - return Mage::helper('eav')->getAttributeBackendTypeByInputType($inputType); + $entityTypeCode = $this->getEntityType()->getEntityTypeCode(); + return Mage::helper('eav')->getAttributeBackendType($entityTypeCode, $inputType); } /** @@ -241,7 +249,8 @@ public function getBackendTypeByInput($inputType) */ public function getDefaultValueByInput($inputType) { - return Mage::helper('eav')->getDefaultValueFieldByInputType($inputType); + $entityTypeCode = $this->getEntityType()->getEntityTypeCode(); + return Mage::helper('eav')->getAttributeDefaultValueField($entityTypeCode, $inputType); } /** diff --git a/app/code/core/Mage/Eav/etc/config.xml b/app/code/core/Mage/Eav/etc/config.xml index e3193a356..b05f306f4 100644 --- a/app/code/core/Mage/Eav/etc/config.xml +++ b/app/code/core/Mage/Eav/etc/config.xml @@ -101,10 +101,92 @@ + + + + + + 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 + + + + + customselect + varchar + eav/entity_attribute_source_table + + + diff --git a/app/locale/en_US/Mage_Core.csv b/app/locale/en_US/Mage_Core.csv index f2a4ff86d..65c39af11 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_Eav.csv b/app/locale/en_US/Mage_Eav.csv index 500dbbb7d..85e35000c 100644 --- a/app/locale/en_US/Mage_Eav.csv +++ b/app/locale/en_US/Mage_Eav.csv @@ -46,6 +46,7 @@ "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" @@ -102,7 +103,6 @@ "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" @@ -118,8 +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)" -"Unique Value (not shared with other %s)","Unique Value (not shared with other products)" "Unknown parameter","Unknown parameter" "Values Required","Values Required" "Wrong attribute group ID","Wrong attribute group ID" From ac849aa4f51818dc5bea899929c645cd8ff27a05 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 23 Nov 2024 09:20:39 -0800 Subject: [PATCH 100/113] add setTemplateIfExists method --- app/code/core/Mage/Core/Block/Template.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/code/core/Mage/Core/Block/Template.php b/app/code/core/Mage/Core/Block/Template.php index 231946019..8e61b0619 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 * From be4ed29654da000d3ea1e315371d682b23b52fb3 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 23 Nov 2024 09:40:43 -0800 Subject: [PATCH 101/113] Big refactor part 2 --- .../Block/Catalog/Product/Attribute.php | 17 +- .../Block/Catalog/Product/Attribute/Edit.php | 76 +-- .../Catalog/Product/Attribute/Edit/Form.php | 10 +- .../Product/Attribute/Edit/Tab/Front.php | 88 ---- .../Product/Attribute/Edit/Tab/Main.php | 64 ++- .../Product/Attribute/Edit/Tab/System.php | 117 ----- .../Catalog/Product/Attribute/Edit/Tabs.php | 34 +- .../{Set/Main/Tree/Attribute.php => Set.php} | 9 +- .../Catalog/Product/Attribute/Set/Grid.php | 58 +-- .../Catalog/Product/Attribute/Set/Main.php | 397 +-------------- .../Attribute/Set/Main/Formattribute.php | 55 -- .../Product/Attribute/Set/Main/Formgroup.php | 72 --- .../Product/Attribute/Set/Main/Formset.php | 53 +- .../Product/Attribute/Set/Main/Tree/Group.php | 9 +- .../Product/Attribute/Set/Toolbar/Add.php | 78 +-- .../Product/Attribute/Set/Toolbar/Main.php | 9 +- .../Attribute/Set/Toolbar/Main/Filter.php | 47 -- .../Eav/Customer.php} | 8 +- .../Adminhtml/Model/Observer/Eav/Product.php | 26 + .../Catalog/Product/AttributeController.php | 307 ++---------- .../Catalog/Product/SetController.php | 209 +------- .../Customer/Address/AttributeController.php | 2 +- .../Customer/Address/SetController.php | 2 +- app/code/core/Mage/Adminhtml/etc/config.xml | 22 +- app/code/core/Mage/Catalog/etc/config.xml | 3 + .../ConfigurableSwatches/etc/jstranslator.xml | 6 + .../Mage/Eav/Block/Adminhtml/Attribute.php | 12 +- .../Eav/Block/Adminhtml/Attribute/Edit.php | 9 +- .../Block/Adminhtml/Attribute/Edit/Form.php | 3 + .../Eav/Block/Adminhtml/Attribute/Edit/Js.php | 25 - .../Attribute/Edit/Main/Abstract.php | 63 ++- .../Attribute/Edit/Options/Abstract.php | 149 +++--- .../Edit/Renderer/Fieldset/Element.php | 5 +- .../Adminhtml/Attribute/Edit/Tab/Main.php | 2 +- .../Block/Adminhtml/Attribute/Edit/Tabs.php | 31 +- .../Eav/Block/Adminhtml/Attribute/Grid.php | 19 +- .../Adminhtml/Attribute/Grid/Abstract.php | 22 +- .../Eav/Block/Adminhtml/Attribute/Set.php | 9 +- .../Attribute/Set/{Toolbar => }/Add.php | 24 +- .../Attribute/Set/{Main.php => Edit.php} | 51 +- .../Attribute/Set/{Main => Edit}/Formset.php | 13 +- .../Set/{Main => Edit}/Tree/Group.php | 5 +- .../Block/Adminhtml/Attribute/Set/Grid.php | 30 +- .../Attribute/Set/Main/Formattribute.php | 59 --- .../Attribute/Set/Main/Formgroup.php | 64 --- .../Attribute/Set/Main/Tree/Attribute.php | 23 - .../Adminhtml/Attribute/Abstract.php | 35 +- .../Eav/Controller/Adminhtml/Set/Abstract.php | 37 +- app/code/core/Mage/Eav/Helper/Data.php | 69 ++- .../core/Mage/Eav/Model/Entity/Attribute.php | 2 +- app/code/core/Mage/Eav/etc/config.xml | 25 +- .../default/default/layout/admin.xml | 4 + .../default/default/layout/catalog.xml | 53 +- .../adminhtml/default/default/layout/eav.xml | 82 +++ .../catalog/product/attribute/js.phtml | 329 ++---------- .../catalog/product/attribute/set/main.phtml | 473 ------------------ .../attribute/set/main/tree/attribute.phtml | 12 - .../attribute/set/main/tree/group.phtml | 12 - .../template/eav/attribute/edit/js.phtml | 12 - .../default/template/eav/attribute/js.phtml | 156 +----- .../template/eav/attribute/options.phtml | 260 ++-------- .../toolbar => eav/attribute/set}/add.phtml | 1 - .../template/eav/attribute/set/main.phtml | 64 ++- .../attribute/set/main/tree/attribute.phtml | 11 - .../eav/attribute/set/main/tree/group.phtml | 3 +- .../eav/attribute/set/toolbar/add.phtml | 26 - app/locale/en_US/Mage_Catalog.csv | 2 - public/js/mage/adminhtml/eav/attribute.js | 101 ++++ public/js/mage/adminhtml/eav/options.js | 171 +++++++ .../skin/adminhtml/default/default/form.css | 18 +- 70 files changed, 1091 insertions(+), 3263 deletions(-) delete mode 100644 app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Front.php delete mode 100644 app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/System.php rename app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/{Set/Main/Tree/Attribute.php => Set.php} (54%) delete mode 100644 app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formattribute.php delete mode 100644 app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formgroup.php delete mode 100644 app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Toolbar/Main/Filter.php rename app/code/core/Mage/Adminhtml/Model/{Customer/Observer.php => Observer/Eav/Customer.php} (91%) create mode 100644 app/code/core/Mage/Adminhtml/Model/Observer/Eav/Product.php delete mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php rename app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/{Toolbar => }/Add.php (75%) rename app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/{Main.php => Edit.php} (87%) rename app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/{Main => Edit}/Formset.php (83%) rename app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/{Main => Edit}/Tree/Group.php (80%) delete mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php delete mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php delete mode 100644 app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php create mode 100644 app/design/adminhtml/default/default/layout/eav.xml delete mode 100644 app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml delete mode 100644 app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/attribute.phtml delete mode 100644 app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml delete mode 100644 app/design/adminhtml/default/default/template/eav/attribute/edit/js.phtml rename app/design/adminhtml/default/default/template/{catalog/product/attribute/set/toolbar => eav/attribute/set}/add.phtml (90%) delete mode 100644 app/design/adminhtml/default/default/template/eav/attribute/set/main/tree/attribute.phtml delete mode 100644 app/design/adminhtml/default/default/template/eav/attribute/set/toolbar/add.phtml create mode 100644 public/js/mage/adminhtml/eav/attribute.js create mode 100644 public/js/mage/adminhtml/eav/options.js 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..b768a6a66 100644 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute.php +++ b/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute.php @@ -15,13 +15,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 eecf92a68..000000000 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Front.php +++ /dev/null @@ -1,88 +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 8d2251cab..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 @@ -12,6 +12,9 @@ /** * Product attribute add/edit form main tab + * + * @category Mage + * @package Mage_Adminhtml */ class Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Main extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract { @@ -104,8 +107,6 @@ protected function _prepareForm() $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)')], @@ -116,8 +117,6 @@ protected function _prepareForm() $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'), ]); $fieldset->addField('is_used_for_promo_rules', 'boolean', [ @@ -134,20 +133,21 @@ protected function _prepareForm() 'class' => 'validate-digits', ]); + $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'), ]); - $htmlAllowed = $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'), - ]); - if (!$attributeObject->getId() || $attributeObject->getIsWysiwygEnabled()) { - $attributeObject->setIsHtmlAllowedOnFront(1); - } + // if (!$attributeObject->getId() || $attributeObject->getIsWysiwygEnabled()) { + // $attributeObject->setIsHtmlAllowedOnFront(1); + // } $fieldset->addField('is_visible_on_front', 'boolean', [ 'name' => 'is_visible_on_front', @@ -178,13 +178,37 @@ protected function _prepareForm() } /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $block */ - $block = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence'); - - $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, @@ -192,8 +216,6 @@ protected function _prepareForm() 'dependence' => $block, ]); - $this->setChild('form_after', $block); - return $this; } 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..b97cb65ab 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,12 @@ * @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(); + $this->setId('product_attribute_tabs'); } } 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 a8bee476d..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,62 +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(); - - /** @var Mage_Eav_Model_Entity_Type $entityType */ - $entityType = Mage::registry('entity_type'); - - $gridId = 'attributeSetGrid'; - if ($entityType && $entityType->getEntityTypeId()) { - $gridId .= '_' . $entityType->getEntityTypeCode(); - } - - $this->setId($gridId); - $this->setDefaultSort('set_name'); - $this->setDefaultDir('ASC'); - $this->setSaveParametersInSession(true); - } - - /** - * @inheritDoc - */ - #[\Override] - protected function _prepareCollection() - { - $collection = Mage::getResourceModel('eav/entity_attribute_set_collection') - ->setEntityTypeFilter(Mage::registry('entity_type')->getEntityTypeId()); - - $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 5a3b2b140..b38b85c2e 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,404 +11,17 @@ */ /** - * 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'); - } - - /** - * 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(); - - 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() - ]; - - $item['children'][] = $attr; - } - } - - $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(); + parent::__construct(); - $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::registry('entity_type')->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(); + $this->setTemplateIfExists('catalog/product/attribute/set/main.phtml'); } } 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 616bb39e1..000000000 --- a/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main/Formgroup.php +++ /dev/null @@ -1,72 +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::registry('entity_type')->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 7efe518b4..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('entity_type')->getEntityTypeId()) - ->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..a3c88db2d 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,12 @@ * @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() + protected 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 71d2e64bd..172dad67f 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,83 +11,17 @@ */ /** + * 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'); - } - - /** - * @inheritDoc - */ - #[\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() + public function __construct() { - return Mage::helper('catalog')->__('Add New Attribute Set'); - } + parent::__construct(); - /** - * @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() - { - return $this->getChild('setForm')->getForm()->getId(); + $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 b00bd0b1e..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 @@ -24,9 +24,6 @@ public function __construct() $this->setTemplate('catalog/product/attribute/set/toolbar/main.phtml'); } - /** - * @inheritDoc - */ #[\Override] protected function _prepareLayout() { @@ -34,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', ]) @@ -55,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/Model/Customer/Observer.php b/app/code/core/Mage/Adminhtml/Model/Observer/Eav/Customer.php similarity index 91% rename from app/code/core/Mage/Adminhtml/Model/Customer/Observer.php rename to app/code/core/Mage/Adminhtml/Model/Observer/Eav/Customer.php index 3b7bad6c7..7a30ebb23 100644 --- a/app/code/core/Mage/Adminhtml/Model/Customer/Observer.php +++ b/app/code/core/Mage/Adminhtml/Model/Observer/Eav/Customer.php @@ -8,19 +8,15 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ - /** * Customer EAV Observer */ -class Mage_Adminhtml_Model_Customer_Observer +class Mage_Adminhtml_Model_Observer_Eav_Customer { /** * Modify customer and customer_address attribute edit forms - * - * @param Varien_Event_Observer $observer - * @return $this */ - public function attributeEditPrepareForm($observer) + public function attributeEditPrepareForm(Varien_Event_Observer $observer): self { /** @var Mage_Customer_Model_Attribute $attribute */ $attribute = $observer->getAttribute(); 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/controllers/Catalog/Product/AttributeController.php b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php index 47b60da25..996c1b85c 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php @@ -12,11 +12,8 @@ /** * 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 { /** * ACL resource @@ -29,37 +26,13 @@ class Mage_Adminhtml_Catalog_Product_AttributeController extends Mage_Adminhtml_ */ public const XML_PATH_ALLOWED_TAGS = 'system/catalog/frontend/allowed_html_tags_list'; - /** @var string */ - protected $_entityCode = Mage_Catalog_Model_Product::ENTITY; - - /** @var Mage_Eav_Model_Entity_Type */ - protected $_entityType; - - /** @var int */ - protected $_entityTypeId; - - /** - * Get list of allowed text formatted as array - * - * @return array - */ - protected function _getAllowedTags() - { - return explode(',', Mage::getStoreConfig(self::XML_PATH_ALLOWED_TAGS)); - } - #[\Override] - public function preDispatch() + protected function _construct() { - $this->_setForcedFormKeyActions('delete'); - $this->_entityType = Mage::getModel('eav/entity')->setType($this->_entityCode)->getEntityType(); - if (!Mage::registry('entity_type')) { - Mage::register('entity_type', $this->_entityType); - } - $this->_entityTypeId = $this->_entityType->getEntityTypeId(); - return parent::preDispatch(); + $this->entityTypeCode = Mage_Catalog_Model_Product::ENTITY; } + #[\Override] protected function _initAction() { $this->_title($this->__('Catalog')) @@ -70,98 +43,24 @@ 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() + /** + * Get list of allowed text formatted as array + * + * @return array + */ + protected function _getAllowedTags() { - $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()); + return explode(',', Mage::getStoreConfig(self::XML_PATH_ALLOWED_TAGS)); } /** @@ -173,14 +72,24 @@ public function validateAction() protected function _filterPostData($data) { if ($data) { - // Labels + if (!isset($data['is_configurable'])) { + $data['is_configurable'] = 0; + } + if (!isset($data['is_filterable'])) { + $data['is_filterable'] = 0; + } + if (!isset($data['is_filterable_in_search'])) { + $data['is_filterable_in_search'] = 0; + } + if (!isset($data['apply_to'])) { + $data['apply_to'] = []; + } $data['frontend_label'] = (array) $data['frontend_label']; foreach ($data['frontend_label'] as & $value) { if ($value) { $value = Mage::helper('catalog')->stripTags($value); } } - // Options 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) { @@ -195,160 +104,14 @@ protected function _filterPostData($data) public function saveAction() { - $data = $this->getRequest()->getPost(); - if ($data) { - /** @var Mage_Admin_Model_Session $session */ - $session = Mage::getSingleton('adminhtml/session'); - /** @var Mage_Catalog_Model_Entity_Attribute $model */ - $model = Mage::getModel('catalog/resource_eav_attribute'); - - $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); - $inputType = $model->getFrontendInput(); - - 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; - } - } else { - $inputType = $data['frontend_input']; - - // Setup default values for new attribute - $data['entity_type_id'] = $this->_entityType->getEntityTypeId(); - $data['is_user_defined'] = 1; - } - - $defaultValueField = Mage::helper('eav')->getAttributeDefaultValueField($this->_entityCode, $inputType); - if ($defaultValueField) { - $data['default_value'] = $data[$defaultValueField]; - } + $request = $this->getRequest(); - if (!isset($data['is_configurable'])) { - $data['is_configurable'] = 0; - } - if (!isset($data['is_filterable'])) { - $data['is_filterable'] = 0; - } - if (!isset($data['is_filterable_in_search'])) { - $data['is_filterable_in_search'] = 0; - } - if (!isset($data['apply_to'])) { - $data['apply_to'] = []; - } - - // Filter - $data = $this->_filterPostData($data); - $model->addData($data); - - // For creating product attribute on product page we need specify attribute set and group - if ($this->getRequest()->getParam('set') && $this->getRequest()->getParam('group')) { - $model->setAttributeSetId($this->getRequest()->getParam('set')); - $model->setAttributeGroupId($this->getRequest()->getParam('group')); - } - - 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 ($this->getRequest()->getParam('back')) { - $this->_redirect('*/*/edit', ['attribute_id' => $model->getId(),'_current' => true]); - } else { - $this->_redirect('*/*/', []); - } - return; - } catch (Exception $e) { - $session->addError($e->getMessage()); - $session->setAttributeData($data); - $this->_redirect('*/*/edit', ['attribute_id' => $id, '_current' => true]); - 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')); } - $this->_redirect('*/*/'); - } - public function deleteAction() - { - if ($id = $this->getRequest()->getParam('attribute_id')) { - $model = Mage::getModel('catalog/resource_eav_attribute'); - - // 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; - } - } - 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 5bb30ef67..98445acab 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,200 +21,40 @@ class Mage_Adminhtml_Catalog_Product_SetController extends Mage_Adminhtml_Contro */ public const ADMIN_RESOURCE = 'catalog/attributes/sets'; - /** @var string */ - protected $_entityCode = Mage_Catalog_Model_Product::ENTITY; - - /** @var Mage_Eav_Model_Entity_Type */ - protected $_entityType; - - /** - * Controller predispatch method - * - * @return Mage_Adminhtml_Controller_Action - */ #[\Override] - public function preDispatch() + protected function _construct() { - $this->_setForcedFormKeyActions('delete'); - $this->_entityType = Mage::getModel('eav/entity')->setType($this->_entityCode)->getEntityType(); - if (!Mage::registry('entity_type')) { - Mage::register('entity_type', $this->_entityType); - } - // For backwards compatibility set camelCase registry key with type id - Mage::register('entityType', $this->_entityType->getEntityTypeId()); - return parent::preDispatch(); + $this->entityTypeCode = Mage_Catalog_Model_Product::ENTITY; } - public function indexAction() - { - $this->_title($this->__('Catalog')) - ->_title($this->__('Attributes')) - ->_title($this->__('Manage Attribute Sets')); - - $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(); - } - - public function editAction() + #[\Override] + public function preDispatch() { - $this->_title($this->__('Catalog')) - ->_title($this->__('Attributes')) - ->_title($this->__('Manage Attribute Sets')); - - $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')); + parent::preDispatch(); - 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')); - - $this->renderLayout(); - } - - public function setGridAction() - { - $this->getResponse()->setBody( - $this->getLayout() - ->createBlock('adminhtml/catalog_product_attribute_set_grid') - ->toHtml() - ); + // For backwards compatibility set camelCase registry key with type id + Mage::register('entityType', $this->entityType->getEntityTypeId()); } - /** - * 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->_entityType->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->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(); + ->_title($this->__('Manage Attribute Sets')); - $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(); - } + $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 index d1428cb33..9f650f6d2 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/AttributeController.php @@ -22,7 +22,7 @@ class Mage_Adminhtml_Customer_Address_AttributeController extends Mage_Eav_Contr #[\Override] protected function _construct() { - $this->entityTypeCode = Mage_Customer_Model_Customer::ENTITY; + $this->entityTypeCode = Mage_Customer_Model_Address::ENTITY; } #[\Override] diff --git a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php index 84674bf0e..d47906084 100644 --- a/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php +++ b/app/code/core/Mage/Adminhtml/controllers/Customer/Address/SetController.php @@ -22,7 +22,7 @@ class Mage_Adminhtml_Customer_Address_SetController extends Mage_Eav_Controller_ #[\Override] protected function _construct() { - $this->entityTypeCode = Mage_Customer_Model_Customer::ENTITY; + $this->entityTypeCode = Mage_Customer_Model_Address::ENTITY; } #[\Override] diff --git a/app/code/core/Mage/Adminhtml/etc/config.xml b/app/code/core/Mage/Adminhtml/etc/config.xml index f0c4c9ffb..a5203af87 100644 --- a/app/code/core/Mage/Adminhtml/etc/config.xml +++ b/app/code/core/Mage/Adminhtml/etc/config.xml @@ -127,10 +127,28 @@
      + + + + + adminhtml/observer_eav_product + setEntityTypeRegistryIfNotExist + + + + + + + adminhtml/observer_eav_product + setEntityTypeRegistryIfNotExist + + + + - adminhtml/customer_observer + adminhtml/observer_eav_customer attributeEditPrepareForm @@ -138,7 +156,7 @@ - adminhtml/customer_observer + adminhtml/observer_eav_customer attributeEditPrepareForm diff --git a/app/code/core/Mage/Catalog/etc/config.xml b/app/code/core/Mage/Catalog/etc/config.xml index 9c286715b..0babe263b 100644 --- a/app/code/core/Mage/Catalog/etc/config.xml +++ b/app/code/core/Mage/Catalog/etc/config.xml @@ -676,6 +676,9 @@ media_image varchar + + + diff --git a/app/code/core/Mage/ConfigurableSwatches/etc/jstranslator.xml b/app/code/core/Mage/ConfigurableSwatches/etc/jstranslator.xml index 429967c8c..38ba2384f 100644 --- a/app/code/core/Mage/ConfigurableSwatches/etc/jstranslator.xml +++ b/app/code/core/Mage/ConfigurableSwatches/etc/jstranslator.xml @@ -22,4 +22,10 @@ Out of Stock + + + + Are you sure to delete this fallback color? + + diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php index 682d365f1..27fad8d28 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php @@ -9,21 +9,25 @@ */ /** - * Adminhtml attribute block + * Adminhtml generic EAV attribute grid container + * + * @category Mage + * @package Mage_Eav */ class Mage_Eav_Block_Adminhtml_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Container { + protected Mage_Eav_Model_Entity_Type $entityType; + public function __construct() { - /** @var Mage_Eav_Model_Entity_Type $entityType */ - $entityType = Mage::registry('entity_type'); + $this->entityType = Mage::registry('entity_type'); $this->_blockGroup = 'eav'; $this->_controller = 'adminhtml_attribute'; $this->_headerText = $this->__( 'Manage %s Attributes', - Mage::helper('eav')->formatTypeCode($entityType->getEntityTypeCode()) + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()) ); $this->_addButtonLabel = Mage::helper('eav')->__('Add New Attribute'); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php index 0e965c244..c4d1c85ce 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php @@ -2,21 +2,24 @@ /** * Maho * - * @category Mage - * @package Mage_Eav + * @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) */ /** + * Adminhtml generic EAV attribute edit page + * * @category Mage * @package Mage_Eav */ class Mage_Eav_Block_Adminhtml_Attribute_Edit extends Mage_Adminhtml_Block_Widget_Form_Container { protected Mage_Eav_Model_Entity_Type $entityType; - protected Mage_Eav_Model_Attribute $entityAttribute; + protected Mage_Eav_Model_Entity_Attribute $entityAttribute; public function __construct() { 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 index 093652f07..8d2c5bdc0 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Form.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Form.php @@ -5,11 +5,14 @@ * @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 add/edit form block + * * @category Mage * @package Mage_Eav */ diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php deleted file mode 100644 index 9830d7c65..000000000 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Js.php +++ /dev/null @@ -1,25 +0,0 @@ -setTemplate('eav/attribute/edit/js.phtml'); - } -} 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 1e977d71c..d66a81129 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,13 +11,14 @@ */ /** - * 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; /** @@ -38,6 +39,30 @@ 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; + } + /** * * @@ -59,9 +84,7 @@ protected function _prepareLayout() } /** - * Preparing default form elements for editing attribute - * - * @inheritDoc + * Prepare default form elements for editing attribute */ #[\Override] protected function _prepareForm() @@ -180,6 +203,21 @@ protected function _prepareForm() return parent::_prepareForm(); } + /** + * Return dependency block object + */ + 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'); + } + /** * Initialize form fields values * @@ -264,19 +302,4 @@ protected function _beforeToHtml() 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; - } } 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 0de0a33b0..386c4e50a 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,13 +11,16 @@ */ /** - * 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(); @@ -25,42 +28,61 @@ public function __construct() } /** - * Preparing layout, adding buttons - * - * @inheritDoc + * @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] - protected function _prepareLayout() + public function getTabTitle() { - $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 Mage::helper('eav')->__('Manage Label / Options'); + } + + #[\Override] + public function canShowTab() + { + return true; + } + + #[\Override] + public function isHidden() + { + 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(); } /** @@ -70,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'); } @@ -98,60 +130,55 @@ public function getStores() */ public function getOptionValues() { - $attributeType = $this->getAttributeObject()->getFrontendInput(); - $defaultValues = $this->getAttributeObject()->getDefaultValue(); - if (in_array($attributeType, ['select', 'multiselect', 'customselect'])) { - $defaultValues = explode(',', (string)$defaultValues); - } else { - $defaultValues = []; + $values = $this->getData('option_values'); + if (!is_null($values)) { + return $values; } + $values = []; - switch ($attributeType) { - case 'select': - case 'customselect': - $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; } @@ -201,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 index c58c5635c..f2b06311c 100644 --- 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 @@ -18,9 +18,10 @@ */ class Mage_Eav_Block_Adminhtml_Attribute_Edit_Renderer_Fieldset_Element extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element { - #[\Override] - protected function _construct() + protected function __construct() { + parent::__construct(); + $this->setTemplate('eav/attribute/edit/renderer/fieldset/element.phtml'); } 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 index 15ce9c140..fb0c364a7 100644 --- 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 @@ -29,7 +29,7 @@ protected function _prepareForm() $form = $this->getForm(); /** @var Mage_Adminhtml_Block_Widget_Form_Element_Dependence $block */ - $block = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence'); + $block = $this->_getDependence(); Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_edit_prepare_form", [ 'form' => $form, diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tabs.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tabs.php index 3866f8f56..229d634ba 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tabs.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tabs.php @@ -5,42 +5,31 @@ * @category Mage * @package Mage_Eav * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) + * @copyright Copyright (c) 2021-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 edit page tabs + * * @category Mage * @package Mage_Eav */ class Mage_Eav_Block_Adminhtml_Attribute_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs { + protected Mage_Eav_Model_Entity_Type $entityType; + protected Mage_Eav_Model_Entity_Attribute $entityAttribute; + public function __construct() { + $this->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')); } - - #[\Override] - protected function _beforeToHtml() - { - $this->addTab('main', [ - 'label' => Mage::helper('eav')->__('Properties'), - 'title' => Mage::helper('eav')->__('Properties'), - 'content' => $this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tab_main')->toHtml(), - 'active' => true - ]); - - $model = Mage::registry('entity_attribute'); - - $this->addTab('labels', [ - 'label' => Mage::helper('eav')->__('Manage Label / Options'), - 'title' => Mage::helper('eav')->__('Manage Label / Options'), - 'content' => $this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tab_options')->toHtml(), - ]); - - return parent::_beforeToHtml(); - } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php index 1a85968c4..a61ae35b4 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Grid.php @@ -10,27 +10,24 @@ */ /** + * Adminhtml generic EAV attribute grid + * * @category Mage * @package Mage_Eav */ class Mage_Eav_Block_Adminhtml_Attribute_Grid extends Mage_Eav_Block_Adminhtml_Attribute_Grid_Abstract { - /** - * @inheritDoc - */ #[\Override] protected function _prepareCollection() { - /** @var Mage_Eav_Model_Entity_Type $entityType */ - $entityType = Mage::registry('entity_type'); - - /** TODO additionally use customer_eav_attribute is_visible */ - $hiddenAttributes = Mage::helper('eav')->getHiddenAttributes($entityType->getEntityTypeCode()); + // 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($entityType->getEntityAttributeCollection()); - $collection->setEntityTypeFilter($entityType->getEntityTypeId()) - ->setNotCodeFilter($hiddenAttributes); + $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 d1bb33663..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,28 +11,24 @@ */ /** - * Eav attributes grid + * Adminhtml generic EAV attribute grid abstract class * * @category Mage * @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(); - - /** @var Mage_Eav_Model_Entity_Type $entityType */ - $entityType = Mage::registry('entity_type'); + $this->entityType = Mage::registry('entity_type'); - $gridId = 'attributeGrid'; - if ($entityType && $entityType->getEntityTypeId()) { - $gridId .= '_' . $entityType->getEntityTypeCode(); - } - - $this->setId($gridId); + $this->setId('attributeGrid_' . $this->entityType->getEntityTypeCode()); $this->setDefaultSort('frontend_label'); $this->setDefaultDir('ASC'); + + parent::__construct(); } /** @@ -72,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 ], ]); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php index 471f6ce2b..5c5ae0e9b 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set.php @@ -9,21 +9,22 @@ */ /** - * Adminhtml attribute sets block + * EAV attribute sets grid container */ class Mage_Eav_Block_Adminhtml_Attribute_Set extends Mage_Adminhtml_Block_Widget_Grid_Container { + protected Mage_Eav_Model_Entity_Type $entityType; + public function __construct() { - /** @var Mage_Eav_Model_Entity_Type $entityType */ - $entityType = Mage::registry('entity_type'); + $this->entityType = Mage::registry('entity_type'); $this->_blockGroup = 'eav'; $this->_controller = 'adminhtml_attribute_set'; $this->_headerText = $this->__( 'Manage %s Attribute Sets', - Mage::helper('eav')->formatTypeCode($entityType->getEntityTypeCode()) + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()) ); $this->_addButtonLabel = Mage::helper('eav')->__('Add New Set'); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Add.php similarity index 75% rename from app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php rename to app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Add.php index 58a71b353..856c91ee3 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Toolbar/Add.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Add.php @@ -13,12 +13,14 @@ * @category Mage * @package Mage_Eav */ -class Mage_Eav_Block_Adminhtml_Attribute_Set_Toolbar_Add extends Mage_Adminhtml_Block_Template +class Mage_Eav_Block_Adminhtml_Attribute_Set_Add extends Mage_Adminhtml_Block_Template { - #[\Override] - protected function _construct() + protected Mage_Eav_Model_Entity_Type $entityType; + + protected function __construct() { - $this->setTemplate('eav/attribute/set/toolbar/add.phtml'); + $this->entityType = Mage::registry('entity_type'); + $this->setTemplate('eav/attribute/set/add.phtml'); } #[\Override] @@ -42,11 +44,6 @@ protected function _prepareLayout() 'class' => 'back' ]) ); - - $this->setChild( - 'setForm', - $this->getLayout()->createBlock('eav/adminhtml_attribute_set_main_formset') - ); return parent::_prepareLayout(); } @@ -55,7 +52,10 @@ protected function _prepareLayout() */ protected function _getHeader() { - return Mage::helper('eav')->__('Add New Attribute Set'); + return Mage::helper('eav')->__( + 'Add New %s Attribute Set', + Mage::helper('eav')->formatTypeCode($this->entityType->getEntityTypeCode()) + ); } /** @@ -79,7 +79,7 @@ protected function getBackButtonHtml() */ protected function getFormHtml() { - return $this->getChildHtml('setForm'); + return $this->getChildHtml('set_form'); } /** @@ -87,6 +87,6 @@ protected function getFormHtml() */ protected function getFormId() { - return $this->getChild('setForm')->getForm()->getId(); + return $this->getChild('set_form')->getForm()->getId(); } } diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit.php similarity index 87% rename from app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php rename to app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit.php index fbdc107e1..c739b141c 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit.php @@ -15,11 +15,15 @@ * @category Mage * @package Mage_Eav */ -class Mage_Eav_Block_Adminhtml_Attribute_Set_Main extends Mage_Adminhtml_Block_Template +class Mage_Eav_Block_Adminhtml_Attribute_Set_Edit extends Mage_Adminhtml_Block_Template { - #[\Override] - protected function _construct() + protected Mage_Eav_Model_Entity_Type $entityType; + protected Mage_Eav_Model_Entity_Attribute_Set $attributeSet; + + protected function __construct() { + $this->entityType = Mage::registry('entity_type'); + $this->attributeSet = Mage::registry('attribute_set'); $this->setTemplate('eav/attribute/set/main.phtml'); } @@ -33,16 +37,6 @@ protected function _prepareLayout() { $setId = $this->_getSetId(); - $this->setChild( - 'group_tree', - $this->getLayout()->createBlock('eav/adminhtml_attribute_set_main_tree_group') - ); - - $this->setChild( - 'edit_set_form', - $this->getLayout()->createBlock('eav/adminhtml_attribute_set_main_formset') - ); - $this->setChild( 'delete_group_button', $this->getLayout()->createBlock('adminhtml/widget_button')->setData([ @@ -127,7 +121,7 @@ public function getGroupTreeHtml() */ public function getSetFormHtml() { - return $this->getChildHtml('edit_set_form'); + return $this->getChildHtml('set_form'); } /** @@ -177,10 +171,8 @@ public function getGroupTreeJson() ->setSortOrder() ->load(); - /* @var $entityType Mage_Eav_Model_Entity_Type */ - $entityType = Mage::registry('entity_type'); - - $hiddenAttributes = Mage::helper('eav')->getHiddenAttributes($entityType->getEntityTypeCode()); + // Get global/eav_attributes/$entityType/$attributeCode/hidden config.xml nodes + $hiddenAttributes = Mage::helper('eav')->getHiddenAttributes($this->entityType->getEntityTypeCode()); /* @var $node Mage_Eav_Model_Entity_Attribute_Group */ foreach ($groups as $node) { @@ -192,8 +184,8 @@ public function getGroupTreeJson() $item['allowDrag'] = true; /** @var Mage_Eav_Model_Entity_Attribute $nodeChildren */ - $nodeChildren = Mage::getResourceModel($entityType->getEntityAttributeCollection()); - $nodeChildren->setEntityTypeFilter($entityType->getEntityTypeId()) + $nodeChildren = Mage::getResourceModel($this->entityType->getEntityAttributeCollection()); + $nodeChildren->setEntityTypeFilter($this->entityType->getEntityTypeId()) ->setNotCodeFilter($hiddenAttributes) ->setAttributeGroupFilter($node->getId()) ->load(); @@ -233,12 +225,9 @@ public function getAttributeTreeJson() $items = []; $setId = $this->_getSetId(); - /* @var $entityType Mage_Eav_Model_Entity_Type */ - $entityType = Mage::registry('entity_type'); - /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection */ - $collection = Mage::getResourceModel($entityType->getEntityAttributeCollection()); - $collection->setEntityTypeFilter($entityType->getEntityTypeId()) + $collection = Mage::getResourceModel($this->entityType->getEntityAttributeCollection()); + $collection->setEntityTypeFilter($this->entityType->getEntityTypeId()) ->setAttributeSetFilter($setId) ->load(); @@ -249,8 +238,8 @@ public function getAttributeTreeJson() } /** @var Mage_Eav_Model_Resource_Entity_Attribute_Collection $attributes */ - $attributes = Mage::getResourceModel($entityType->getEntityAttributeCollection()); - $attributes->setEntityTypeFilter($entityType->getEntityTypeId()) + $attributes = Mage::getResourceModel($this->entityType->getEntityAttributeCollection()); + $attributes->setEntityTypeFilter($this->entityType->getEntityTypeId()) ->setAttributesExcludeFilter($attributesIds) ->setOrder('attribute_code', 'asc') ->load(); @@ -363,7 +352,7 @@ public function getRenameButton() */ protected function _getAttributeSet() { - return Mage::registry('current_attribute_set'); + return $this->attributeSet; } /** @@ -385,7 +374,7 @@ public function getIsCurrentSetDefault() { $isDefault = $this->getData('is_current_set_default'); if (is_null($isDefault)) { - $defaultSetId = Mage::registry('entity_type')->getDefaultAttributeSetId(); + $defaultSetId = $this->entityType->getDefaultAttributeSetId(); $isDefault = $this->_getSetId() == $defaultSetId; $this->setData('is_current_set_default', $isDefault); } @@ -411,8 +400,8 @@ protected function _getSetData() #[\Override] protected function _toHtml() { - $type = Mage::registry('entity_type')->getEntityTypeCode(); - Mage::dispatchEvent("adminhtml_{$type}_attribute_set_main_html_before", ['block' => $this]); + $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/Main/Formset.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Formset.php similarity index 83% rename from app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php rename to app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Formset.php index 9112ce54e..2b5053aa5 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formset.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Formset.php @@ -5,6 +5,7 @@ * @category Mage * @package Mage_Eav * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) + * @copyright Copyright (c) 2021-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) */ @@ -13,11 +14,13 @@ * @category Mage * @package Mage_Eav */ -class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Formset extends Mage_Adminhtml_Block_Widget_Form +class Mage_Eav_Block_Adminhtml_Attribute_Set_Edit_Formset extends Mage_Adminhtml_Block_Widget_Form { + protected Mage_Eav_Model_Entity_Type $entityType; + public function __construct() { - parent::__construct(); + $this->entityType = Mage::registry('entity_type'); } #[\Override] @@ -43,11 +46,7 @@ protected function _prepareForm() 'value' => '1' ]); - /** @var Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection @collection */ - $collection = Mage::getModel('eav/entity_attribute_set') - ->getResourceCollection(); - - $sets = $collection->setEntityTypeFilter(Mage::registry('entity_type')->getEntityTypeId()) + $sets = $this->entityType->getAttributeSetCollection() ->setOrder('attribute_set_name', 'asc') ->load() ->toOptionArray(); diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Tree/Group.php similarity index 80% rename from app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php rename to app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Tree/Group.php index 5ecd8ddae..b78e85461 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Group.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Tree/Group.php @@ -13,10 +13,9 @@ * @category Mage * @package Mage_Eav */ -class Mage_Eav_Block_Adminhtml_Attribute_Set_Main_Tree_Group extends Mage_Adminhtml_Block_Template +class Mage_Eav_Block_Adminhtml_Attribute_Set_Edit_Tree_Group extends Mage_Adminhtml_Block_Template { - #[\Override] - protected function _construct() + protected function __construct() { $this->setTemplate('eav/attribute/set/main/tree/group.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 index be661823e..4a6c58be6 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Grid.php @@ -15,42 +15,31 @@ */ class Mage_Eav_Block_Adminhtml_Attribute_Set_Grid extends Mage_Adminhtml_Block_Widget_Grid { + protected Mage_Eav_Model_Entity_Type $entityType; + public function __construct() { - parent::__construct(); - - /** @var Mage_Eav_Model_Entity_Type $entityType */ - $entityType = Mage::registry('entity_type'); - - $gridId = 'attributeSetGrid'; - if ($entityType && $entityType->getEntityTypeId()) { - $gridId .= '_' . $entityType->getEntityTypeCode(); - } + $this->entityType = Mage::registry('entity_type'); - $this->setId($gridId); + $this->setId('attributeSetGrid_' . $this->entityType->getEntityTypeCode()); $this->setDefaultSort('set_name'); $this->setDefaultDir('ASC'); $this->setSaveParametersInSession(true); + + parent::__construct(); } - /** - * @inheritDoc - */ #[\Override] protected function _prepareCollection() { /** @var Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection $collection */ - $collection = Mage::getResourceModel('eav/entity_attribute_set_collection'); - - $collection->setEntityTypeFilter(Mage::registry('entity_type')->getEntityTypeId()); + $collection = $this->entityType->getAttributeSetCollection(); $this->setCollection($collection); + return parent::_prepareCollection(); } - /** - * @inheritDoc - */ #[\Override] protected function _prepareColumns() { @@ -63,9 +52,6 @@ protected function _prepareColumns() return $this; } - /** - * @inheritDoc - */ #[\Override] public function getRowUrl($row) { diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php deleted file mode 100644 index 507454caa..000000000 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formattribute.php +++ /dev/null @@ -1,59 +0,0 @@ -addFieldset('set_fieldset', ['legend' => Mage::helper('eav')->__('Add New Attribute')]); - - $fieldset->addField( - 'new_attribute', - 'text', - [ - 'label' => Mage::helper('eav')->__('Name'), - 'name' => 'new_attribute', - 'required' => true, - ] - ); - - $fieldset->addField( - 'submit', - 'note', - [ - 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData([ - 'label' => Mage::helper('eav')->__('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/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php deleted file mode 100644 index 0ad40703f..000000000 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Formgroup.php +++ /dev/null @@ -1,64 +0,0 @@ -addFieldset('set_fieldset', ['legend' => Mage::helper('eav')->__('Add New Group')]); - - $fieldset->addField('attribute_group_name', 'text', [ - 'label' => Mage::helper('eav')->__('Name'), - 'name' => 'attribute_group_name', - 'required' => true, - ]); - - $fieldset->addField('submit', 'note', [ - 'text' => $this->getLayout()->createBlock('adminhtml/widget_button') - ->setData([ - 'label' => Mage::helper('eav')->__('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('*/*/save')); - $this->setForm($form); - return $this; - } - - protected function _getSetId() - { - return ((int) $this->getRequest()->getParam('id') > 0) - ? (int) $this->getRequest()->getParam('id') - : Mage::registry('entity_type')->getDefaultAttributeSetId(); - } -} diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php deleted file mode 100644 index cf1171612..000000000 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Main/Tree/Attribute.php +++ /dev/null @@ -1,23 +0,0 @@ -setTemplate('eav/attribute/set/main/tree/attribute.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 index f625cf1ab..59f2ed52c 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php @@ -17,11 +17,6 @@ abstract class Mage_Eav_Controller_Adminhtml_Attribute_Abstract extends Mage_Adm protected string $entityTypeCode; protected Mage_Eav_Model_Entity_Type $entityType; - /** - * Controller predispatch method - * - * @return Mage_Adminhtml_Controller_Action - */ #[\Override] public function preDispatch() { @@ -32,6 +27,17 @@ public function preDispatch() 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(); @@ -40,8 +46,7 @@ protected function _initAction() public function indexAction() { $this->_initAction() - ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute')) - ->renderLayout(); + ->renderLayout(); } public function newAction() @@ -119,21 +124,13 @@ public function editAction() // Add website switcher if editing existing attribute and we have a scope table if (!Mage::app()->isSingleStoreMode()) { if ($id && $attribute->getResource()->hasScopeTable()) { - $this->_addLeft( + $this->getLayout()->getBlock('left')->insert( $this->getLayout()->createBlock('adminhtml/website_switcher') - ->setDefaultWebsiteName($this->__('Default Values')) + ->setDefaultWebsiteName($this->__('Default Values')) ); } } - $this->_addLeft($this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tabs')) - ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_edit')); - - $this->_addJs( - $this->getLayout()->createBlock('adminhtml/template') - ->setTemplate('eav/attribute/js.phtml') - ); - $this->renderLayout(); } @@ -170,14 +167,12 @@ public function validateAction() protected function _filterPostData($data) { if ($data) { - // Labels $data['frontend_label'] = (array) $data['frontend_label']; foreach ($data['frontend_label'] as & $value) { if ($value) { $value = Mage::helper('eav')->stripTags($value); } } - // Options 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) { @@ -235,7 +230,7 @@ public function saveAction() } // Entity type check - if ($attribute->getEntityTypeId() !== $this->entityType->getEntityTypeId()) { + if ($attribute->getEntityTypeId() != $this->entityType->getEntityTypeId()) { $session->addError( $this->__('This attribute cannot be updated.') ); diff --git a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php index d163ab970..9851b6106 100644 --- a/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php +++ b/app/code/core/Mage/Eav/Controller/Adminhtml/Set/Abstract.php @@ -17,11 +17,6 @@ abstract class Mage_Eav_Controller_Adminhtml_Set_Abstract extends Mage_Adminhtml protected string $entityTypeCode; protected Mage_Eav_Model_Entity_Type $entityType; - /** - * Controller predispatch method - * - * @return Mage_Adminhtml_Controller_Action - */ #[\Override] public function preDispatch() { @@ -32,6 +27,17 @@ public function preDispatch() 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(); @@ -40,25 +46,20 @@ protected function _initAction() public function indexAction() { $this->_initAction() - ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_set')) - ->renderLayout(); + ->renderLayout(); } public function setGridAction() { - $this->getResponse()->setBody( - $this->getLayout() - ->createBlock('eav/adminhtml_attribute_set_grid') - ->toHtml() - ); + $this->_initAction() + ->renderLayout(); } public function addAction() { $this->_initAction() - ->_title($this->__('New Set')) - ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_set_toolbar_add')) - ->renderLayout(); + ->_title($this->__('New Set')) + ->renderLayout(); } public function editAction() @@ -75,10 +76,8 @@ public function editAction() Mage::register('current_attribute_set', $attributeSet); $this->_initAction() - ->_addContent($this->getLayout()->createBlock('eav/adminhtml_attribute_set_main')); - - $this->getLayout()->getBlock('head')->setCanLoadExtJs(true); - $this->renderLayout(); + ->_title($attributeSet->getAttributeSetName()) + ->renderLayout(); } public function createFromSkeletonSetAction() diff --git a/app/code/core/Mage/Eav/Helper/Data.php b/app/code/core/Mage/Eav/Helper/Data.php index bcfd476f3..5edf93797 100644 --- a/app/code/core/Mage/Eav/Helper/Data.php +++ b/app/code/core/Mage/Eav/Helper/Data.php @@ -194,12 +194,15 @@ public function getInputTypesValidatorData() * - '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 */ @@ -237,7 +240,9 @@ public function getInputTypes(string $entityTypeCode): array Mage::dispatchEvent($event, ['response' => $response]); $inputTypes = $response->getTypes(); } - $this->cacheInputTypes[$entityTypeCode] = $inputTypes; + foreach ($inputTypes as $type) { + $this->cacheInputTypes[$entityTypeCode][$type['value']] = $type; + } } return $this->cacheInputTypes[$entityTypeCode]; } @@ -247,13 +252,7 @@ public function getInputTypes(string $entityTypeCode): array */ public function getAttributeBackendType(string $entityTypeCode, string $inputType): ?string { - $inputTypes = $this->getInputTypes($entityTypeCode); - foreach ($inputTypes as $type) { - if ($inputType === $type['value']) { - return $type['backend_type'] ?? null; - } - } - return null; + return $this->getInputTypes($entityTypeCode)[$inputType]['backend_type'] ?? null; } /** @@ -261,13 +260,7 @@ public function getAttributeBackendType(string $entityTypeCode, string $inputTyp */ public function getAttributeBackendModel(string $entityTypeCode, string $inputType): ?string { - $inputTypes = $this->getInputTypes($entityTypeCode); - foreach ($inputTypes as $type) { - if ($inputType === $type['value']) { - return $type['backend_model'] ?? null; - } - } - return null; + return $this->getInputTypes($entityTypeCode)[$inputType]['backend_model'] ?? null; } /** @@ -275,13 +268,7 @@ public function getAttributeBackendModel(string $entityTypeCode, string $inputTy */ public function getAttributeFrontendModel(string $entityTypeCode, string $inputType): ?string { - $inputTypes = $this->getInputTypes($entityTypeCode); - foreach ($inputTypes as $type) { - if ($inputType === $type['value']) { - return $type['frontend_model'] ?? null; - } - } - return null; + return $this->getInputTypes($entityTypeCode)[$inputType]['frontend_model'] ?? null; } /** @@ -289,13 +276,7 @@ public function getAttributeFrontendModel(string $entityTypeCode, string $inputT */ public function getAttributeSourceModel(string $entityTypeCode, string $inputType): ?string { - $inputTypes = $this->getInputTypes($entityTypeCode); - foreach ($inputTypes as $type) { - if ($inputType === $type['value']) { - return $type['source_model'] ?? null; - } - } - return null; + return $this->getInputTypes($entityTypeCode)[$inputType]['source_model'] ?? null; } /** @@ -303,13 +284,7 @@ public function getAttributeSourceModel(string $entityTypeCode, string $inputTyp */ public function getAttributeDefaultValueField(string $entityTypeCode, string $inputType): ?string { - $inputTypes = $this->getInputTypes($entityTypeCode); - foreach ($inputTypes as $type) { - if ($inputType === $type['value']) { - return $type['default_value_field'] ?? null; - } - } - return null; + return $this->getInputTypes($entityTypeCode)[$inputType]['default_value_field'] ?? null; } /** @@ -318,9 +293,9 @@ public function getAttributeDefaultValueField(string $entityTypeCode, string $in public function getInputTypeHiddenFields(string $entityTypeCode): array { $hiddenFields = []; - foreach ($this->getInputTypes($entityTypeCode) as $type) { + foreach ($this->getInputTypes($entityTypeCode) as $key => $type) { if (isset($type['hide_fields'])) { - $hiddenFields[$type['value']] = $type['hide_fields']; + $hiddenFields[$key] = $type['hide_fields']; } } return $hiddenFields; @@ -332,14 +307,28 @@ public function getInputTypeHiddenFields(string $entityTypeCode): array public function getInputTypeDisabledApplyToOptions(string $entityTypeCode): array { $disabledTypes = []; - foreach ($this->getInputTypes($entityTypeCode) as $type) { + foreach ($this->getInputTypes($entityTypeCode) as $key => $type) { if (isset($type['disabled_types'])) { - $disabledTypes[$type['value']] = $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 */ diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute.php b/app/code/core/Mage/Eav/Model/Entity/Attribute.php index a2c8c9744..b02639d34 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute.php @@ -155,7 +155,7 @@ protected function _beforeSave() if (empty($code)) { throw Mage::exception('Mage_Eav', $helper->__('Attribute code cannot be empty')); } - if (!preg_match('/^[a-z][a-z_0-9]$/', $code)) { + 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) { diff --git a/app/code/core/Mage/Eav/etc/config.xml b/app/code/core/Mage/Eav/etc/config.xml index b05f306f4..3d499949f 100644 --- a/app/code/core/Mage/Eav/etc/config.xml +++ b/app/code/core/Mage/Eav/etc/config.xml @@ -173,17 +173,20 @@ multiselect text eav/entity_attribute_backend_array + checkbox customselect varchar eav/entity_attribute_source_table + radio @@ -199,6 +202,13 @@
      + + + + eav.xml + + + @@ -220,19 +230,4 @@ - - - - - text - - date - boolean - multiselect - customselect - - - - -
      diff --git a/app/design/adminhtml/default/default/layout/admin.xml b/app/design/adminhtml/default/default/layout/admin.xml index 50681d702..a5db2741f 100644 --- a/app/design/adminhtml/default/default/layout/admin.xml +++ b/app/design/adminhtml/default/default/layout/admin.xml @@ -91,6 +91,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 76a26e302..fc760c52b 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 @@ -10,320 +10,59 @@ * @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ ?> - diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml deleted file mode 100644 index d9087aa17..000000000 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml +++ /dev/null @@ -1,473 +0,0 @@ - -
      - - - - - -

      escapeHtml($this->_getHeader()) ?>

      - getBackButtonHtml() ?> - getResetButtonHtml() ?> - getDeleteButtonHtml() ?> - getSaveButtonHtml() ?> -
      -
      - - - - - - -
      - getSetFormHtml() ?> - -
      - - - - - - -

      __('Groups') ?>

      -
      - - getIsReadOnly()): ?> -

      getAddGroupButton() ?> getDeleteGroupButton() ?>

      -

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

      - - - getSetsFilterHtml() ?> - getGroupTreeHtml() ?> -
      -
      - - - - - - -

      __('Unassigned Attributes') ?>

      -
      -
      - -
      diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/attribute.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/attribute.phtml deleted file mode 100644 index 8f99ce285..000000000 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/attribute.phtml +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml b/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml deleted file mode 100644 index c806c8dbd..000000000 --- a/app/design/adminhtml/default/default/template/catalog/product/attribute/set/main/tree/group.phtml +++ /dev/null @@ -1,12 +0,0 @@ - -
      diff --git a/app/design/adminhtml/default/default/template/eav/attribute/edit/js.phtml b/app/design/adminhtml/default/default/template/eav/attribute/edit/js.phtml deleted file mode 100644 index 8f99ce285..000000000 --- a/app/design/adminhtml/default/default/template/eav/attribute/edit/js.phtml +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/app/design/adminhtml/default/default/template/eav/attribute/js.phtml b/app/design/adminhtml/default/default/template/eav/attribute/js.phtml index 7dd384e3b..d94fc039a 100644 --- a/app/design/adminhtml/default/default/template/eav/attribute/js.phtml +++ b/app/design/adminhtml/default/default/template/eav/attribute/js.phtml @@ -5,160 +5,32 @@ * @category design * @package default_default * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) + * @copyright Copyright (c) 2021-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) */ ?> - 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..90b614a2d 100644 --- a/app/design/adminhtml/default/default/template/eav/attribute/options.phtml +++ b/app/design/adminhtml/default/default/template/eav/attribute/options.phtml @@ -14,11 +14,11 @@ /** * Attribute options control * - * @see Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract * @var Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract $this */ ?> -
      +getEntityTypeCode() ?> +getReadOnly() ? 'disabled' : '' ?>
        • @@ -26,240 +26,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..d90a9a0bf 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,7 +5,6 @@ * @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) */ diff --git a/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml b/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml index 36a560c08..87dd36ead 100644 --- a/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml +++ b/app/design/adminhtml/default/default/template/eav/attribute/set/main.phtml @@ -5,14 +5,17 @@ * @category design * @package default_default * @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com) + * @copyright Copyright (c) 2021-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) */ + +/** @var Mage_Eav_Block_Adminhtml_Attribute_Set_Edit $this */ ?>
      - +

      escapeHtml($this->_getHeader()) ?>

      escapeHtml($this->_getHeader()) ?>

      getBackButtonHtml() ?> getResetButtonHtml() ?> @@ -32,7 +35,7 @@ - +

      __('Groups') ?>

      __('Groups') ?>

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

      getAddGroupButton() ?> getDeleteGroupButton() ?>

      -

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

      +

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

      getSetsFilterHtml() ?> @@ -51,16 +54,16 @@ - +

      __('Unassigned Attributes') ?>

      __('Unassigned Attributes') ?>

      -
      +
      diff --git a/app/locale/en_US/Mage_Catalog.csv b/app/locale/en_US/Mage_Catalog.csv index 94f4b5ec9..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." diff --git a/public/js/mage/adminhtml/eav/attribute.js b/public/js/mage/adminhtml/eav/attribute.js new file mode 100644 index 000000000..3fd89520f --- /dev/null +++ b/public/js/mage/adminhtml/eav/attribute.js @@ -0,0 +1,101 @@ +/** + * + */ +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..e08f03cf6 --- /dev/null +++ b/public/js/mage/adminhtml/eav/options.js @@ -0,0 +1,171 @@ +/** + * + */ +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/skin/adminhtml/default/default/form.css b/public/skin/adminhtml/default/default/form.css index c9f008cf0..568b31de5 100644 --- a/public/skin/adminhtml/default/default/form.css +++ b/public/skin/adminhtml/default/default/form.css @@ -247,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; @@ -276,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 */ From 90445284f9b6b75cb599d7ca95f3751fc4ab89c7 Mon Sep 17 00:00:00 2001 From: Justin Beaty Date: Sat, 23 Nov 2024 10:37:00 -0800 Subject: [PATCH 102/113] templates --- .../Block/Adminhtml/Attribute/Set/Edit.php | 2 +- .../Attribute/Set/Edit/Tree/Group.php | 2 +- .../catalog/product/attribute/js.phtml | 5 ++- .../product/attribute/new/created.phtml | 2 ++ .../edit/renderer/fieldset/element.phtml | 35 ++++++++++--------- .../default/template/eav/attribute/js.phtml | 4 ++- .../template/eav/attribute/options.phtml | 13 +++---- .../template/eav/attribute/set/add.phtml | 2 ++ .../attribute/set/{main.phtml => edit.phtml} | 0 .../set/{main => edit}/tree/group.phtml | 2 ++ .../default/template/eav/widget/form.phtml | 2 ++ .../eav/widget/form/element/boolean.phtml | 2 ++ .../eav/widget/form/element/country.phtml | 2 ++ .../widget/form/element/customselect.phtml | 2 ++ .../eav/widget/form/element/date.phtml | 2 ++ .../eav/widget/form/element/fieldset.phtml | 12 ++++--- .../eav/widget/form/element/hidden.phtml | 2 ++ .../eav/widget/form/element/multiline.phtml | 8 +++-- .../eav/widget/form/element/multiselect.phtml | 2 ++ .../eav/widget/form/element/postcode.phtml | 2 ++ .../eav/widget/form/element/region.phtml | 2 ++ .../eav/widget/form/element/select.phtml | 2 ++ .../eav/widget/form/element/text.phtml | 2 ++ .../eav/widget/form/element/textarea.phtml | 2 ++ 24 files changed, 73 insertions(+), 38 deletions(-) rename app/design/adminhtml/default/default/template/eav/attribute/set/{main.phtml => edit.phtml} (100%) rename app/design/adminhtml/default/default/template/eav/attribute/set/{main => edit}/tree/group.phtml (87%) 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 index c739b141c..cb3b1588e 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit.php @@ -24,7 +24,7 @@ protected function __construct() { $this->entityType = Mage::registry('entity_type'); $this->attributeSet = Mage::registry('attribute_set'); - $this->setTemplate('eav/attribute/set/main.phtml'); + $this->setTemplate('eav/attribute/set/edit.phtml'); } /** diff --git a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Tree/Group.php b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Tree/Group.php index b78e85461..313a279a2 100644 --- a/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Tree/Group.php +++ b/app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Set/Edit/Tree/Group.php @@ -17,6 +17,6 @@ class Mage_Eav_Block_Adminhtml_Attribute_Set_Edit_Tree_Group extends Mage_Adminh { protected function __construct() { - $this->setTemplate('eav/attribute/set/main/tree/group.phtml'); + $this->setTemplate('eav/attribute/set/edit/tree/group.phtml'); } } 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 fc760c52b..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,9 +9,12 @@ * @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'; ?>