2
votes

I am new to Magento2 and I was wondering if someone could help me echo out Customer's Address information in an activation email to Admin. Below is the code I am using to build the Customer's information.

->setTemplateVars(
            [
                'email' => $customer->getEmail(),
                'firstname' => $customer->getFirstname(),
                'lastname' => $customer->getLastname(),
                'company' => $customer->getAddress()->getCompany(), //DOESN'T WORK!!
                'telephone' => $customer->getAddress()->getTelephone(), //DOESN'T WORK!!
                'taxvat' => $customer->getTaxvat(),
                'website' => $customer->getCustomAttribute('website')->getValue(),
            ]
        );

Email, Firstname, Lastname, TaxVat and Custom Attribute "Website" are all working and showing properly on my email. However, I can't get the information for Company Name, Telephone, Address, etc.

I would appreciate it if anyone could help point me in the right direction.

1
Hi Can you dump this $customer->getAddress(); and see what data you are getting in this.Rohit Goel

1 Answers

0
votes

To get customer phone number and company info you need to used this things.

$customer->getDefaultShippingAddress()->getTelephone(); // For Telephone

$customer->getDefaultShippingAddress()->getCompany(); // For Company