Closed
Description
Once you have customer model with primary shipping, but wo primary billing and try to execute getPrimaryAddresses method - you got fatal error.
It's happening because there no checking that you have primary billing.
https://github.com/magento/magento2/blob/develop/app/code/Magento/Customer/Model/Customer.php#L722
This issue also exists in Magento CE 1.9.1.
How to fix it:
/**
* Retrieve all customer default addresses
*
* @return Address[]
*/
public function getPrimaryAddresses()
{
$addresses = [];
$primaryBilling = $this->getPrimaryBillingAddress();
if ($primaryBilling) {
$addresses[] = $primaryBilling;
$primaryBilling->setIsPrimaryBilling(true);
}
$primaryShipping = $this->getPrimaryShippingAddress();
if ($primaryShipping) {
if ($primaryBilling && $primaryBilling->getId() == $primaryShipping->getId()) {
$primaryBilling->setIsPrimaryShipping(true);
} else {
$primaryShipping->setIsPrimaryShipping(true);
$addresses[] = $primaryShipping;
}
}
return $addresses;
}