1

I have added a phone no text box in Customer Account edit form(Account Edit).

Block file
\Magento\Customer\Block\Form\Edit

The issue is, I am not able to get the phone no to get it after the user saved it.

For dob(date of birth)

 <?php $_dob = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?>

 <?php if ($_dob->isEnabled()): ?>
       <?= $_dob->setDate($block->getCustomer()->getDob())->toHtml() ?>
 <?php endif ?>

For Telephone, I am not able to get phone no.

 <?php $_telephone = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Telephone') ?>

 <?php if ($_telephone->isEnabled()): ?>
       <?= $_telephone->setTelephone($block->getCustomer()->getTelephone())->toHtml() ?>
 <?php endif ?>

as error is

Method 'getTelephone' not found in Magento\Customer\Api\Data\CustomerInterface more... 

How can I get Customer telephone no, from this interface Magento\Customer\Api\Data\CustomerInterface

0

You are not able to get the getTelephone() on Magento\Customer\Api\Data\CustomerInterface because Telephone is part of customer address Magento\Customer\Api\Data\AddressInterface object not for customer object.

So If you want the Telephone then you need to get the address object of the customer then you can get the Telephone value

i.e

$block->getAddress()->getTelephone()

  • I get this error $block->getAddress()->getTelephone(), because block \Magento\Customer\Block\Form\Edit has so such function getAddress() – summu Apr 24 at 17:52
  • correct, because each address has own telephone number so you need to first select the address then you can get the telephone , but I think you know the reason error which you are getting :) @summu – Keyur Shah Apr 25 at 9:33

Your Answer

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

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