I'm trying to have the customer's phone number show under the customer account information section. I know the phone number belongs to the customer address section but I'm trying to redesign how the customer account information looks like.
I added a new custom field for Customer ID and I'm able to display it by 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 the telephone number by using this
<?php echo $this->__('Telephone:') ?><?php echo $this->htmlEscape($this->getCustomer()->getTelephone()) ?>
But it doesn't display any data since it belongs to customer_address_entity and I BELIEVE it should be
->getAddress()->getTelephone()
instead of
->getCustomer()->getTelephone()
but using ->getAddress just gives me an error “ Call to a member function getTelephone() on a non-object “
Does anyone have any idea how to do this?
As a reference, I'm trying to have this data display on the file customer\\account\\dashboard\\info.phtml
Thanks in advance.
Oh, thanks I'll post now! (see comments under original post).
Simply use the following:
$this->getCustomer()->getPrimaryBillingAddress()->getTelephone();
The first part will give you all the details, which you could then explore with var_dump()
as per @paperids.
This answer should go to @Alex, but just for the sake of completion, I'm posting this as an answer:
Use:
$this->getCustomer()->getPrimaryBillingAddress()->getTelephone()
Luis has mentioned before that if customer didn't setup his billing address you will get an error in return: Call to a member function in a non-object.
If you want to be ready for such situation you can put the code into following IF statement:
<?php if ($customerAddressId){ ?>
<?php $address=Mage::getModel('customer/address')->load($customerAddressId); ?>
<?php $this->getCustomer()->getPrimaryBillingAddress()->getTelephone();
} ?>
Careful if there is NO address set then this getPrimaryBillingAddress() return a non object.
$address = $this->getCustomer()->getPrimaryBillingAddress();
if ( $address ) echo $address->getTelephone();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.