33 votes
Accepted

What's the difference between an user defined attribute and non user defined attribute?

Actually Magento user_defined = false attributes are known as system attributes. So Magento has some of their system attribute, which we can not delete from admin panel. So magento won't allow system ...
Dhaval Solanki's user avatar
29 votes

Magento 2 custom customer attribute's values not getting saved in database?

You have probably solved your issue but for people who come here from google as me, there is a solution: When creating the customer attribute, please take care of the following things: Attribute is ...
A.Maksymiuk's user avatar
24 votes
Accepted

Get attribute value in product view page

If you are in the product view page, in the catalog/product/view.phtml there is an instance of the product model usually called $_product. From this variable you have access to all the attribute ...
Giuseppe's user avatar
  • 1,131
22 votes
Accepted

Magento2 : user define customer attribute not save value while create / save from admin

looks like the issue was due to the fact your attributes are not assigned to the customer attribute set. the following code is needed in your install: I added full code for you at https://bitbucket....
Herve Tribouilloy's user avatar
17 votes
Accepted

How to save customer attribute value in custom script in Magento 2

This is how it can be done with customer save method: /** @var \Magento\Customer\Model\CustomerFactory $customerFactory */ /** @var \Magento\Customer\Model\Customer $customer */ /** @var \Magento\...
Daniel Ifrim's user avatar
  • 3,394
17 votes

How can we remove/delete the custom attribute(created for customer) in Magento 2

You should use UpgradeData now. Create this file app/code/Bibhu/Customattribute/Setup/UpgradeData.php : namespace Bibhu\Customattribute\Setup; use Magento\Eav\Setup\EavSetupFactory; use Magento\...
Antoine Martin's user avatar
17 votes
Accepted

How to prevent "Call to a member function getValue() on null" when using getCustomAttribute()->getValue()?

Try following way: if($myCustomAttribute = $customer->getCustomAttribute('my_custom_attribute')) { echo $myCustomAttribute->getValue(); }
Sohel Rana's user avatar
  • 35.7k
16 votes
Accepted

Customer custom attribute not showing in admin form

In contrast to Magento 1, in Magento 2 you now need to add some XML to make custom attributes appear in the edit customer section of the admin. Create YourNamespace/YourModule/view/base/ui_component/...
ProcessEight's user avatar
  • 1,000
16 votes
Accepted

Add a custom attribute in grid customer magento 2

You don't need customer_listing.xml or indexer.xml to show customer attribute in gird. these line will do it for you 'is_used_in_grid' => true, 'is_visible_in_grid' => true, ...
Qaisar Satti's user avatar
  • 32.5k
16 votes
Accepted

Magento 2.3 - How to add custom column to customer_entity table

You can try using following code. app/code/Anshu/CustomerEdit/registration.php <?php use Magento\Framework\Component\ComponentRegistrar; ComponentRegistrar::register( ComponentRegistrar::...
Anshu Mishra's user avatar
  • 8,950
15 votes
Accepted

Magento 2: Save custom customer attribute value programmatically

I have got the solution protected $customer; protected $customerFactory; public function __construct( \Magento\Customer\Model\Customer $customer, \Magento\Customer\Model\ResourceModel\...
Dinesh Yadav's user avatar
  • 6,437
13 votes
Accepted

Get Customer information from order Magento 2

Inside observer, $order = $observer->getEvent()->getOrder(); $orderFromFront = $order->getRemoteIp(); $guestCustomer = $order->getCustomerIsGuest(); $groupId = $order->...
Rakesh Jesadiya's user avatar
13 votes
Accepted

Magento 2 : How to know "used_in_forms" param of eav attribute for a form?

You can get all used_in_forms in magento by typing below query, Used in form customer attribute: SELECT DISTINCT form_code FROM customer_form_attribute WHERE 1 adminhtml_checkout ...
Rakesh Jesadiya's user avatar
11 votes
Accepted

How to add cutom customer attribute field to call rest api via create new customer

The custom attribute mobile_number should be inside custom customer attribute data: { "customer": { "email": "[email protected]", "firstname": "First", "lastname": "Last", "storeId": ...
Khoa TruongDinh's user avatar
11 votes
Accepted

Magento2: get custom customer attribute value

Your code is working perfectly fine for me. The issue must be with no value for that attribute with the particular customer_is. Have you tried and saved is_vendor value for customer_id 5 once. I mean ...
arushi's user avatar
  • 790
9 votes

Magento 2 Fail to save the value of a newly added Yes/No customer attribute

I found the answer finally. adding: $attributeMyhkt->addData([ 'attribute_set_id' => 1, 'attribute_group_id' => 1 ]); below: $attribute->...
Ricky.C's user avatar
  • 2,182
9 votes
Accepted

Update customer password directly in database

Try this: Replace testtest with your new password and $customer_entity_id with the customers entity_id in the customer_entity table. update customer_entity_varchar set value = md5('testtest') where ...
Yogesh Agarwal's user avatar
9 votes

Magento 2: How to get first and last name of customer?

The Best idea to use repository interface for getting customer data Magento 2.2.. Magento\Customer\Api\CustomerRepositoryInterface Use function getById($customerId) Inject that class on ...
Amit Bera's user avatar
  • 77.4k
8 votes
Accepted

How to add dropdown attribute to custom module in magento 2.0

Add bellow installation script in your module at path app/code/{Namespace} /{Module-Name}/Setup/InstallData.php <?php /** * @author AR * @category AR * @package AR_CustomerAttribute ...
Abdul's user avatar
  • 9,702
8 votes
Accepted

Magento 2 Save customer attribute value while customer register

You can do this by observer. SR/StackExchange/etc/frontend/events.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:...
Sohel Rana's user avatar
  • 35.7k
8 votes

“Type Error occurred when creating object: Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Config”

Try to look at the customer eav attribute with select value for frontend_input column in eav_attribute table, make sure the source_model column value is not null or empty or it fills with correct ...
Idham Choudry's user avatar
7 votes
Accepted

Adding custom customer attribute to admin panel?

Try this <?php $installer = $this; $attribute = array( 'type' => 'int', 'input' => 'text', 'label' => 'Is Active', 'global' => 1, 'visible' => 1, 'default'...
Akhilesh Patel's user avatar
7 votes
Accepted

magento2 create customer attribute

Please make below change in module.xml, <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../...
Rushvi's user avatar
  • 2,833
7 votes

How to add a unique custom attribute for a customer?

You need to InstallData.php like below code : public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $this->logger->info("Username data installed."); ...
Charvi Parikh's user avatar
7 votes

Magento 2: Save custom customer attribute value programmatically

You need to do it the strange Magento 2 way:- public function __construct( \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, ) { $this->_customerRepository = $...
Dallas Clarke's user avatar
6 votes

Source Model not found for Attribute

For those who might have this issue, I solved it by another way. It happened when I disabled a module and some attributes were still trying to be launched in db, even if they were useless. what i did ...
Nicolas D's user avatar
  • 191
6 votes

Magento 2: Add custom attributes to customer grid

Leaving out view_id seems to work: <indexer id="customer_grid"> This way, the XML will be merged into the existing indexer instead of defining a new indexer.
Fabian Schmengler's user avatar
6 votes
Accepted

Magento 2 - how to update customer Info?

The email_backup is the custom customer attribute. We can use Magento\Customer\Api\CustomerRepositoryInterface to save the customer info. /** * @var CustomerRepositoryInterface */ protected $...
Khoa TruongDinh's user avatar
6 votes

What's the difference between an user defined attribute and non user defined attribute?

Magento system attributes are set to false for user_defined so our custom attributes should be set to true. System attributes can not be deleted so if you set false to user_defined, your attribute ...
Kishan Patadia's user avatar
6 votes
Accepted

Retrieve all customers data

you can get the customer details like below : customer id here $customerId = 1; load customer object $customer = Mage::getModel('customer/customer')->load($customerId); //insert cust ID create ...
Manashvi Birla's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible