I'm using Magento 2 Community Edition Version 2.1.0

I'm following How to Override Core Block, Model and controller in Magento2

for overriding Customer Model.

I have added newly attribute called "Passport", it displays in backend/frontend registration page.

For Frontend's Edit Profile, now i'm trying to add "Passport" attribute.

As per above tutorial i have added <module name>/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Customer\Model\Data\Customer" type="Custom\Module\Model\Data\Customer" />

{folder path}\magento2\app\code\Custom\Module\Model\Data\Customer.php

namespace Custom\Module\Model\Data;

use \Magento\Framework\Api\AttributeValueFactory;

    class Customer extends \Magento\Customer\Model\Data\Customer

        const PASSPORT = 'passport';

        public function getPassport()
            return $this->_get(self::PASSPORT);

        public function setPassport($passport)
            return $this->setData(self::PASSPORT, $passport);

Once i use this file & try to login with correct credentials. It gives below error.

An unspecified error occurred. Please contact us for assistance.

If i rename that file say di1.xml, then i'm able to login.

By debug i found that in

{folder path}\magento2\vendor\magento\module-customer\Controller\Account\LoginPost.php

It's not authenticating user

  • can you share your Custom\Module\Model\Data\Customer ? – Ekta Puri Aug 12 '16 at 4:19
  • @EktaPuri: Added in question now. – Ankit Shah Aug 12 '16 at 4:25
  • works fine, no issues at all. I used your code in di.xml and model customer.php. after this i am able to login. I created attribute passport in admin -> stores -> attributes -> customer and made it visible in registration and account edit. – Ekta Puri Aug 12 '16 at 4:42
  • have you done setup:upgrade command after creating module? – Ekta Puri Aug 12 '16 at 4:44
  • Strange. I'm using Magento 2 CE. So have to create attribute manually/through code – Ankit Shah Aug 12 '16 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.