Magento: how to display a customer phone number in a customer information field

I am trying to show the clients phone number in the client account information section. I know that the phone number belongs to the client address section, but I'm trying to reverse engineer what the client account information looks like.

I added a new custom field for the customer ID and Im to display it using the following code, as the customer ID belongs to customer_entity.

<?php echo $this->__('Identification:') ?><?php echo $this->htmlEscape($this->getCustomer()->getCustid()) ?>

but now I'm trying to do the same for a phone number using this

<?php echo $this->__('Telephone:') ?><?php echo $this->htmlEscape($this->getCustomer()->getTelephone()) ?>

But it does not display any data since it belongs to customer_address_entity, and I BELIEVE it should be

->getAddress()->getTelephone()

instead

->getCustomer()->getTelephone()

but using -> getAddress just gives me the error "Calling the member function getTelephone () for a non-object"

- , ?

, customer\account\dashboard\info.phtml

.

+5
5

, , ! (. ).

:

$this->getCustomer()->getPrimaryBillingAddress()->getTelephone();

, var_dump() @paperids.

+13

@Alex, , :

:

$this->getCustomer()->getPrimaryBillingAddress()->getTelephone()
+4

, , : - -.

If you want to be prepared for this situation, you can put the code in the following IF statement:

<?php if ($customerAddressId){ ?>
    <?php $address=Mage::getModel('customer/address')->load($customerAddressId); ?>
    <?php $this->getCustomer()->getPrimaryBillingAddress()->getTelephone(); 
} ?>
+1
source

Caution, if there is no address specified, this getPrimaryBillingAddress () returns no object.

$address = $this->getCustomer()->getPrimaryBillingAddress();
if ( $address ) echo $address->getTelephone();
0
source
isLoggedIn ()) {$ customer = Mage :: getSingleton ('customer / session') → getCustomer (); $ customerName = $ customer-> getName (); // for example, can you access all other attributes}? >
-1
source

All Articles