diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php index af777e86d..6f71c22e2 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers/MailchimpTags.php @@ -459,43 +459,43 @@ protected function getWebSiteByStoreId($storeId) } /** - * @param $address + * @param $customerAddress * @return array | returns an array with the address data of the customer. */ - protected function getAddressData($address) + protected function getAddressData($customerAddress) { - $lastOrder = $this->getLastOrderByEmail(); - $addressData = $this->getAddressFromLastOrder($lastOrder); - if (!empty($addressData)) { - if ($address) { - $street = $address->getStreet(); - if (count($street) > 1) { - $addressData["addr1"] = $street[0]; - $addressData["addr2"] = $street[1]; - } else { - if (!empty($street[0])) { - $addressData["addr1"] = $street[0]; - } - } + if (!$customerAddress || !$customerAddress->getId()) { + return []; + } - if ($address->getCity()) { - $addressData["city"] = $address->getCity(); - } + $addressData = []; - if ($address->getRegion()) { - $addressData["state"] = $address->getRegion(); - } + $street = $customerAddress->getStreet(); + if (count($street) > 1) { + $addressData["addr1"] = $street[0]; + $addressData["addr2"] = $street[1]; + } else { + if (!empty($street[0])) { + $addressData["addr1"] = $street[0]; + } + } - if ($address->getPostcode()) { - $addressData["zip"] = $address->getPostcode(); - } + if ($customerAddress->getCity()) { + $addressData["city"] = $customerAddress->getCity(); + } - if ($address->getCountry()) { - $addressData["country"] = Mage::getModel('directory/country') - ->loadByCode($address->getCountry()) - ->getName(); - } - } + if ($customerAddress->getRegion()) { + $addressData["state"] = $customerAddress->getRegion(); + } + + if ($customerAddress->getPostcode()) { + $addressData["zip"] = $customerAddress->getPostcode(); + } + + if ($customerAddress->getCountry()) { + $addressData["country"] = Mage::getModel('directory/country') + ->loadByCode($customerAddress->getCountry()) + ->getName(); } return $addressData;