Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI to Edit EAV Attributes & Sets - Customer #2352

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
| admin_user_authenticate_after | 1.9.4.5 |
| admin_user_authenticate_before | 1.9.4.5 |
| admin_user_validate | 1.9.4.5 |
| adminhtml_[entityCode]_attribute_types | 20.0.15 |
| adminhtml_[entityCode]_attribute_scopes | 20.0.15 |
| adminhtml_[entityCode]_attribute_edit_prepare_form | 20.0.15 |
| adminhtml_[entityCode]_attribute_edit_prepare_save | 20.0.15 |
| adminhtml_block_eav_attribute_edit_form_init | 1.9.4.5 |
| adminhtml_block_promo_widget_chooser_prepare_collection | 1.9.4.5 |
| adminhtml_block_salesrule_actions_prepareform | 1.9.4.5 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,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')
Expand Down
67 changes: 49 additions & 18 deletions app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,62 @@ protected function _prepareLayout()

$validateClass = sprintf('required-entry validate-length maximum-length-%d',
Mage_Customer_Model_Group::GROUP_CODE_MAX_LENGTH);
$name = $fieldset->addField('customer_group_code', 'text',
array(
'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', array(
'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() ) {
$name->setDisabled(true);
}

$fieldset->addField('tax_class_id', 'select',
array(
'name' => 'tax_class',
'label' => Mage::helper('customer')->__('Tax Class'),
'title' => Mage::helper('customer')->__('Tax Class'),
$fieldset->addField('tax_class_id', 'select', array(
'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()
));

// 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' => Mage::getSingleton('tax/class_source_customer')->toOptionArray()
)
);
'values' => $setsAddress
));

}

if (!is_null($customerGroup->getId())) {
// If edit add id
Expand Down
148 changes: 148 additions & 0 deletions app/code/core/Mage/Adminhtml/Model/Customer/Observer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php
/**
* OpenMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/


/**
* Customer EAV Observer
*
* @category Mage
* @package Mage_Adminhtml
* @author Magento Core Team <core@magentocommerce.com>
*/
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looking at #2260 again, not sure why I implemented a new method instead of using $attribute->getUsedInForms()

));

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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* OpenMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

require_once 'Mage/Eav/Controller/Adminhtml/Attribute/Abstract.php';

/**
* Customer address attribute controller
*
* @category Mage
* @package Mage_Adminhtml
* @author Magento Core Team <core@magentocommerce.com>
*/

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');
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* OpenMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

require_once 'Mage/Eav/Controller/Adminhtml/Set/Abstract.php';

/**
* Customer address attribute sets controller
*
* @category Mage
* @package Mage_Adminhtml
* @author Magento Core Team <core@magentocommerce.com>
*/

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');
}

}
Loading