Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ihor-sviziev opened this issue Mar 17, 2015 · 6 comments
Closed
Labels
bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@ihor-sviziev
Copy link
Contributor

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;
    }
@vpelipenko
Copy link
Contributor

@ihor-sviziev, thank you posting this issue, but could you provide a way how we can get this fatal? Do you use native Magento workflows? Or is it a result of some customizations?

@ihor-sviziev
Copy link
Contributor Author

@vpelipenko I got this issue in my own module, it contains cloning of customer model, which firing this method.

@vpelipenko
Copy link
Contributor

@ihor-sviziev, how can we reproduce this issue? What should we do for that?

@ihor-sviziev
Copy link
Contributor Author

@vpelipenko use code like this:

//Customer ID which has selected shipping address and NOT selected billing address
$customerId = '1'; 
$customer = $this->_objectManager->create('Magento\Customer\Model\Customer');
$customer->load($customerId);

//This part will cause fatal error
$primaryAddresses = $customer->getPrimaryAddresses();

//This part also will cause fatal error
$newCustomer = clone $customer;

@vpelipenko
Copy link
Contributor

Ok. Thanks. We will try to check it.

@vpelipenko vpelipenko added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Mar 18, 2015
@vpelipenko
Copy link
Contributor

Issue is closed, because PR #1097 is created instead.

magento-team added a commit to abeeskau/magento2-community-edition that referenced this issue Mar 31, 2015
* Fixed bugs
    * Wrong capitalization of the label names (the sentence-style capitalization instead of the headline style)
    * Inconsistency in the labels in the Admin panel
    * Customer menu tabs aren't displayed as selected for the child pages
    * An issue with the Active item in the navigation menu in the Blank and Luma themes
    * Incorrect price alignment during checkout in the Blank and Luma themes
    * Broken field "URL" in the Downloadable product in the Admin panel
* GitHub issues and requests:
    * [#1096] (magento/magento2#1096) -- Customer model - getPrimaryAddresses without primary billing address
    * [#1114] (magento/magento2#1114) -- GA bug
    * [#1116] (magento/magento2#1116) -- Incorrect use of implode()
    * [#1126] (magento/magento2#1126) -- Fixed occurrences of implode with wrong argument order
    * [#1128] (magento/magento2#1128) -- Change wording for long operation warning
magento-team added a commit to abeeskau/magento2-community-edition that referenced this issue Apr 8, 2015
* Fixed bugs
    * Wrong capitalization of the label names (the sentence-style capitalization instead of the headline style)
    * Inconsistency in the labels in the Admin panel
    * Customer menu tabs aren't displayed as selected for the child pages
    * An issue with the Active item in the navigation menu in the Blank and Luma themes
    * Incorrect price alignment during checkout in the Blank and Luma themes
    * Broken field "URL" in the Downloadable product in the Admin panel
* GitHub issues and requests:
    * [#1096] (magento/magento2#1096) -- Customer model - getPrimaryAddresses without primary billing address
    * [#1114] (magento/magento2#1114) -- GA bug
    * [#1116] (magento/magento2#1116) -- Incorrect use of implode()
    * [#1126] (magento/magento2#1126) -- Fixed occurrences of implode with wrong argument order
    * [#1128] (magento/magento2#1128) -- Change wording for long operation warning
magento-team pushed a commit that referenced this issue May 12, 2017
- MAGETWO-53431 [GITHUB] SOAP API Encoding Object has no 'label' property #4630
- MAGETWO-58652 [GitHub] REST API multiselect attribute values are sent in an incompatible format and cannot be cleared #6120
- MAGETWO-62567 Make static file versioning number not based on timestamp
- MAGETWO-63741 [FT] Magento\Catalog\Test\TestCase\Product\CreateSimpleProductEntityTest fails on CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests

2 participants