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

address with saveInAddressBook 0 are still being added to the address book for new customers #7691

Closed
koenner01 opened this issue Dec 6, 2016 · 2 comments
Assignees
Labels
bug report Component: Checkout Component: Customer Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@koenner01
Copy link
Contributor

If you place an order as a guest and set the save_in_address_book for an address on 0, that address will still be copied to the customer address book when registering as a new customer on the checkout success page.

Preconditions

  1. PHP7.0
  2. MG2 CE 2.1.2

Steps to reproduce

  1. Place an order as a guest and set the save_in_address_book for your shipping address to 0
  2. Click the register link on the checkout success page

Expected result

  1. Every address that has save_in_address_book set to 0 should not be copied to the customer address book

Actual result

  1. Addresses with save_in_address_book set to 0 are still copied to the new customer address book.

I traced this issue back to Magento\Sales\Model\Order\CustomerManagement where in the create() function a check should be added to see if the quote_address from where the order_address was copied from has a value 0 for save_in_address_book. If the value is 0, the address should not be copied.

public function create($orderId)
{
    $order = $this->orderRepository->get($orderId);
    if ($order->getCustomerId()) {
        throw new AlreadyExistsException(__("This order already has associated customer account"));
    }
    $customerData = $this->objectCopyService->copyFieldsetToTarget(
        'order_address',
        'to_customer',
        $order->getBillingAddress(),
        []
    );
    $addresses = $order->getAddresses();
    foreach ($addresses as $address) {
        $addressData = $this->objectCopyService->copyFieldsetToTarget(
            'order_address',
            'to_customer_address',
            $address,
            []
        );
        
        ...
}

Should be something like

protected $quoteAddressFactory;

public function __construct(
    ...
    \Magento\Quote\Model\Quote\AddressFactory $quoteAddressFactory
) {
    ...
    $this->quoteAddressFactory = $quoteAddressFactory;
}

public function create($orderId)
{
    $order = $this->orderRepository->get($orderId);
    if ($order->getCustomerId()) {
        throw new AlreadyExistsException(__("This order already has associated customer account"));
    }
    $customerData = $this->objectCopyService->copyFieldsetToTarget(
        'order_address',
        'to_customer',
        $order->getBillingAddress(),
        []
    );
    $addresses = $order->getAddresses();
    foreach ($addresses as $address) {
        $quoteAddressId = $address->getData('quote_address_id');
        if($quoteAddressId) {
            $quoteAddress = $this->quoteAddressFactory->create()->load($quoteAddressId);
            $saveInAddressBook = (int) $quoteAddress->getData('save_in_address_book');
            if ($saveInAddressBook === 0) {
                continue;
            }
        }

        ...
@magento-engcom-team
Copy link
Contributor

@koenner01, thank you for your report.
We've created internal ticket(s) MAGETWO-81448 to track progress on the issue.

@magento-engcom-team magento-engcom-team added 2.2.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Oct 11, 2017
@RomaKis RomaKis self-assigned this Oct 31, 2017
@okorshenko
Copy link
Contributor

The issue has been fixed and delivered to 2.2-develop branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Checkout Component: Customer Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

5 participants