0

I created a new customer attribute with the select tag and the various options. When I try to create a new customer, this field returns the vacuum to me as the default value.

enter image description here

I want to force the default option in the select field of the attribute with the php. How can I do?

The module with which I create custom attributes for customers is called "Manage Customer Attributes Extension"

Thanks

6
  • There might be an option while creating custom customer attribute to set default value. You can share screen shot of screen where you are creating attribute Commented Feb 18, 2018 at 12:11
  • This is true man thanks, but since in my admin I will have several users I would like this default value to change. For example: if (getUserId() == 2) {setDefaultvalue}
    – Gabriel91
    Commented Feb 18, 2018 at 12:20
  • Here "if (getUserId() == 2) " user id is customer id or admin user id? Commented Feb 18, 2018 at 12:30
  • admin user id..
    – Gabriel91
    Commented Feb 18, 2018 at 12:33
  • FYI, customer attribute value is associated with the customer cannot change as per admin user, if you to show different values as per admin then you need to change in core customer admin module by adding some static conditions . Commented Feb 18, 2018 at 13:39

1 Answer 1

1

If you are using Magento's default customer Account Information tab to see this information in admin then you can see this file:

/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php

In this file you can see these 2 lines which set the form data in admin:

$form->setValues($customer->getData());
$this->setForm($form);

So you can add below code above these lines to update any customer attribute value to be seen in admin Account Information tab:

$admin_user_session = Mage::getSingleton('admin/session');
$adminuserId = $admin_user_session->getUser()->getUserId();
if($adminuserId ==68){
//like below code you can set particular customer attribute value as per your requirement 
$customer->setFirstname('test');

}

Note: This code will only manipulate the customer data before showing on Account information tab it will not update the actual customer data, if you want to update use

$customer->save(); after the above code

Also this is the core file, so please override in your module as not recommended to modify core files.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.