1

I'm able to add custom customer attribute called "passport".

It's working fine on Admin Side. So no issues.

For the frontend however it's not displaying on Registration page.

Below code already added InstallData.php

'used_in_forms' => ['adminhtml_customer', 'checkout_register', 'customer_account_create', 'customer_account_edit','adminhtml_checkout'],

So, for frontend, i have created Block - Widget for that Passport Field & Overriding Customer Registration Page. It's already pointing to New File.

\magento2\app\code\Custom\CustomerAttribute\Block\Widget\Passport.php

public function _construct() { 
 parent::_construct(); 
$this->setTemplate('Custom_CustomerAttribute::widget/passport.phtml'); 
 }

\magento2\app\code\Custom\CustomerAttribute\view\frontend\templates\form\register.phtml

<?php
$_passport = $block->getLayout()->createBlock('Custom\CustomerAttribute\Block\Widget\Passport');
if ($_passport->isEnabled()):
 echo $_passport->setPassport($block->getFormData()->getPassport())->toHtml();
endif;
?>

While running above code it's not calling <project path>\magento2\app\code\Custom\CustomerAttribute\view\frontend\templates\widget\passport.phtml file.

asked Aug 11, 2016 at 3:29

1 Answer 1

1

I got the answer & solution.

\magento2\app\code\Custom\CustomerAttribute\Block\Widget\Passport.php

/**
 * @return bool
 */
public function isEnabled() {
 $attributeMetadata = $this->_getAttribute('passport');
 return $attributeMetadata ? (bool) $attributeMetadata->isVisible() : false;
}

Now it's displaying in frontend :)

answered Aug 11, 2016 at 3:51
3
  • have you created extension Custom/CustomerAttribute Commented Feb 15, 2017 at 5:14
  • @ankit - Can you plz share your Widget\Passport.php, actually I am doing same but don't know why getting error. Commented Feb 20, 2017 at 10:23
  • It's already mentioned in question magento.stackexchange.com/questions/88245/… Commented Feb 21, 2017 at 1:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.