-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
base: main
Are you sure you want to change the base?
Conversation
a4bbceb
to
2293a10
Compare
In testing the However it does seem to work perfectly in all of the adminhtml areas. |
I can confirm you that there's some work on the frontend that needs to be done for the use_in_forms to work :-) |
* | ||
* @return array | ||
*/ | ||
public function toOptionArray() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have custom form types, is it possible to define these in app\code\core\Mage\Customer\etc\config.xml
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it maybe be better to set up an event to hook into? I'm thinking about the best way a module could define their own form types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using event is ok, but I like the config method. An example is product types:
magento-lts/app/code/core/Mage/Catalog/etc/config.xml
Lines 479 to 487 in 35acb46
<catalog> | |
<product> | |
<type> | |
<simple translate="label" module="catalog"> | |
<label>Simple Product</label> | |
<model>catalog/product_type_simple</model> | |
<composite>0</composite> | |
<index_priority>10</index_priority> | |
</simple> |
and product custom option:
magento-lts/app/code/core/Mage/Catalog/etc/config.xml
Lines 531 to 537 in 35acb46
<options> | |
<custom> | |
<groups> | |
<text translate="label" module="adminhtml"> | |
<label>Text</label> | |
<render>adminhtml/catalog_product_edit_tab_options_type_text</render> | |
<types> |
which I have used to add more options in the HTML select element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kiatng thanks for the examples, I was thinking about it more and agree the config.xml method is indeed better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref
magento-lts/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Options/Type.php
Line 34 in 35acb46
class Mage_Adminhtml_Model_System_Config_Source_Product_Options_Type |
I made a sample code:
class Mage_Adminhtml_Model_System_Config_Source_Customer_Form
{
const CUSTOMER_FORM_PATH = 'global/customer/form';
public function toOptionArray()
{
$helper = Mage::helper('customer');
foreach (Mage::getConfig()->getNode(self::CUSTOMER_FORM_PATH)->children() as $form) {
$labelPath = self::CUSTOMER_FORM_PATH . '/' . $form->getName() . '/label';
$forms[] = [
'label' => $helper->__((string) Mage::getConfig()->getNode($labelPath)),
'value' => $form->getName()
];
}
return $forms;
}
}
The config.xml
looks like this:
<global>
<customer>
<form>
<adminhtml_checkout translate="label" module="customer">
<label>Adminhtml Checkout</label>
</adminhtml_checkout>
<adminhtml_customer translate="label" module="customer">
<label>Adminhtml Customer</label>
</adminhtml_customer>
<!-- more forms -->
</form>
</customer>
</global>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That code sample doesn't consider the module attribute. Corrected version:
class Mage_Adminhtml_Model_System_Config_Source_Customer_Form
{
const CUSTOMER_FORM_PATH = 'global/customer/form';
public function toOptionArray()
{
foreach (Mage::getConfig()->getNode(self::CUSTOMER_FORM_PATH)->children() as $form) {
$labelPath = self::CUSTOMER_FORM_PATH . '/' . $form->getName() . '/label';
$moduleName = $form->getAttribute('module') ?? 'customer';
$forms[] = [
'label' => Mage::helper($moduleName)->__((string) Mage::getConfig()->getNode($labelPath)),
'value' => $form->getName()
];
}
return $forms;
}
}
Note that $form->getAttribute('module')
can return null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kiatng thanks for the implementation!
Do you think this XML is better? Since we need to also define customer_address
forms it keeps all forms under one node, <form>
.
<global>
<form>
<customer>
<adminhtml_checkout translate="label" module="customer">
<label>Adminhtml Checkout</label>
</adminhtml_checkout>
<adminhtml_customer translate="label" module="customer">
<label>Adminhtml Customer</label>
</adminhtml_customer>
<!-- more forms -->
</customer>
<customer_address>
<adminhtml_customer_address translate="label" module="customer">
<label>Adminhtml Customer Address</label>
</adminhtml_customer_address>
<customer_address_edit translate="label" module="customer">
<label>Customer Address Edit</label>
</customer_address_edit>
<!-- more forms -->
</customer_address>
</form>
</global>
I could also move the source models to:
Mage_Adminhtml_Model_System_Config_Source_Form_Customer
Mage_Adminhtml_Model_System_Config_Source_Form_Customer_Address
to match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref
class Mage_Customer_Model_Form extends Mage_Eav_Model_Form |
and
magento-lts/app/code/core/Mage/Catalog/etc/config.xml
Lines 620 to 621 in 18e68a2
</catalog> | |
<eav_attributes> |
Use the module name like <catalog>
:
<global>
<eav>
<form>
<customer>
<!-- more forms -->
</customer>
<customer_address>
<!-- more forms -->
</customer_address>
</form>
</eav>
</global>
or continue with the format <eav_attributes>
:
<global>
<eav_forms>
<customer>
<!-- more forms -->
</customer>
<customer_address>
<!-- more forms -->
</customer_address>
</eav_forms>
</global>
Which do you prefer? I'd go with the latter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the latter as well 👍
I've started support for Todo:
|
This pull request introduces 2 alerts and fixes 8 when merging e629678 into cf82b8f - view on LGTM.com new alerts:
fixed alerts:
|
wow! |
e629678
to
bf5a98a
Compare
I still have address forms to do tomorrow. I am also thinking it might be nice to group these fields on the frontend based on the attribute set > groups. This way there is some more organization and the user can label the fieldset. For example in Account Information they could have a group called "Social Media" and let the user enter urls to their pages (just an example.) But also, I am going to take a stab at allowing you to define attribute set per customer group. Thus it would be important that not only do you define |
Co-authored-by: Fabrizio Balliano <fabrizio.balliano@gmail.com>
1956c43
to
4d460bb
Compare
@kiatng (and @fballiano) I'm seeking your opinion on the following (originally posted here)
The PR as it now should definitely not conflict with anything since it's all new code, but I see your point if we hook up a customer group -> customer attribute set relation. Still, I think it could be worth it maybe just waiting to merge this PR until the next major version. How did you correlate attribute sets with customer groups? My first thought is to modify the
To add something like If we can do it in a way that is maybe compatible with what you've done, then that's at least one site that wouldn't break. In any case, I'll set up an observer so that users can change this logic. |
Yes, in fact sets 19 and 23 in the screenshot I attached are of the same customer group. The use case is for different backend users to view/edit a different set of attributes. At its height, there were a couple hundreds of backend users in this project. There are other advantages to add Your approach to match an attribute set at the customer group is similar to the product's But what I have is customized to a very particular use case. I only developed what is required of the project, I do not have anything on addresses and categories. Developing for general use cases is a lot more challenging. |
Will be ready for RC4? |
I wanted to revive this, I think they should target "next" but it's like my preference, because we're more free to choose how to act on the frontend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check if extrafileds exists and add validation classes to text input
I wasn't able to send a commit
@@ -153,6 +153,18 @@ | |||
</li> | |||
</ul> | |||
</div> | |||
<div class="fieldset"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap into
<?php if($this->extraFields()): ?>
...
<?php endif ?>
<?php $_code = $_attribute->getAttributeCode() ?> | ||
<label for="<?php echo $this->getFieldId($_code)?>"<?php if ($this->isRequired()) echo ' class="required"' ?>><?php if ($this->isRequired()) echo '<em>*</em>' ?><?php echo $this->__($_attribute->getStoreLabel()) ?></label> | ||
<div class="input-box"> | ||
<input type="text" id="<?php echo $this->getFieldId($_code)?>" name="<?php echo $this->getFieldName($_code)?>" value="<?php echo $this->escapeHtml($this->getObject()->getData($_code)) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__($_attribute->getStoreLabel())) ?>" class="input-text" <?php echo $this->getFieldParams() ?> /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add validation classes
class="input-text <?php echo $_attribute->getFrontendClass() ?>"
i've made some test on this PR:
|
there were some bad conflicts, I did what i could, not sure 100% was correct |
Description (*)
[WIP] This commit was previously part of #2317. It is broken out so that we can discuss ways to integrate the customer EAV attributes into customer groups, and customer forms. Discussions about this are in that PR.
Related Pull Requests
#2317
#2260
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Todo:
Contribution checklist (*)