Skip to content

Resolved issue for Customer address is duplicated after setBillingAddressOnCart GraphQL mutation #27107

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

Merged
merged 3 commits into from
Mar 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
);
}

$billingAddress = $this->createBillingAddress($context, $customerAddressId, $addressInput);
$billingAddress = $this->createBillingAddress($context, $customerAddressId, $addressInput, $sameAsShipping);

$this->assignBillingAddressToCart->execute($cart, $billingAddress, $sameAsShipping);
}
Expand All @@ -101,6 +101,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
* @param ContextInterface $context
* @param int|null $customerAddressId
* @param array $addressInput
* @param bool $sameAsShipping
* @return Address
* @throws GraphQlAuthorizationException
* @throws GraphQlInputException
Expand All @@ -109,16 +110,17 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
private function createBillingAddress(
ContextInterface $context,
?int $customerAddressId,
?array $addressInput
?array $addressInput,
$sameAsShipping
): Address {
if (null === $customerAddressId) {
$billingAddress = $this->quoteAddressFactory->createBasedOnInputData($addressInput);

$customerId = $context->getUserId();
// need to save address only for registered user and if save_in_address_book = true
if (0 !== $customerId
if ((0 !== $customerId
&& isset($addressInput['save_in_address_book'])
&& (bool)$addressInput['save_in_address_book'] === true
&& (bool)$addressInput['save_in_address_book'] && $sameAsShipping !== true) === true
) {
$this->saveQuoteAddressToCustomerAddressBook->execute($billingAddress, $customerId);
}
Expand Down