Skip to content

[Bug] Customer model - getPrimaryAddresses without primary billing address #1096

Closed
@ihor-sviziev

Description

@ihor-sviziev

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentbug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions