Magento 2 Database – Get Value from Custom Column in customer_entity

customerdatabasemagento-2.1magento2

I'm having an issue with getting data from custom column I added in customer_entity. I added a column typo3_password in UpdateSchema.php and now I need to get data from this column. Trying to do that using getTypo3Password() method and adding CustomerInterface in module's Api\Data but it doesn't work.

 $customer       = $this->customerRepository->get($username);
 $customerId     = $customer->getId();
 $typoHashFromDb = $customer->getTypo3Password();

Any ideas? Do I need to add my custom Customer Model as well?

— edit

Adding the custom CustomerInterface I created.

 const TYPO3_PASSWORD = 'typo3_password';

/**
 * Get Typo3 Password
 *
 * @return string|null
 */
public function getTypo3Password();

/**
 * @param string $typo3password
 * @return $this
 */
public function setTypo3Password($typo3password);

Best Answer

The customer entity is an EAV entity, and a customer's properties are organized with attributes in the table eav_attribute.

After you added a customer attribute, you don't have to create a getter or a setter. Magic methods will take care of it, and getTypo3Password() will automatically be available.

You can also use getData('typo3_password').

Related Topic