-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MC-31586: Customer address is duplicated after setBillingAddressOnCar…
…t GraphQL mutation. - Added fix and api functional test
- Loading branch information
1 parent
756aedf
commit 8a92d80
Showing
2 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -871,6 +871,89 @@ public function testSetNewBillingAddressWithSaveInAddressBook() | |
} | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php | ||
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php | ||
*/ | ||
public function testSetBillingAddressAndPlaceOrder() | ||
{ | ||
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); | ||
$query = <<<QUERY | ||
mutation { | ||
setBillingAddressOnCart( | ||
input: { | ||
cart_id: "$maskedQuoteId" | ||
billing_address: { | ||
same_as_shipping: true | ||
address: { | ||
firstname: "test firstname" | ||
lastname: "test lastname" | ||
company: "test company" | ||
street: ["test street 1", "test street 2"] | ||
city: "test city" | ||
region: "AZ" | ||
postcode: "887766" | ||
country_code: "US" | ||
telephone: "88776655" | ||
save_in_address_book: true | ||
} | ||
} | ||
} | ||
) { | ||
cart { | ||
billing_address { | ||
firstname | ||
lastname | ||
company | ||
street | ||
city | ||
postcode | ||
telephone | ||
country { | ||
code | ||
label | ||
} | ||
__typename | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap()); | ||
$this->graphQlMutation( | ||
$this->getSetShippingMethodsQuery($maskedQuoteId, 'flatrate', 'flatrate'), | ||
[], | ||
'', | ||
$this->getHeaderMap() | ||
); | ||
$this->graphQlMutation( | ||
$this->getSetPaymentMethodQuery( | ||
$maskedQuoteId, | ||
'checkmo' | ||
), | ||
[], | ||
'', | ||
$this->getHeaderMap() | ||
); | ||
$this->graphQlMutation( | ||
$this->getPlaceOrderQuery($maskedQuoteId), | ||
[], | ||
'', | ||
$this->getHeaderMap() | ||
); | ||
$customer = $this->customerRepository->get('[email protected]'); | ||
$searchCriteria = $this->searchCriteriaBuilder->addFilter('parent_id', $customer->getId())->create(); | ||
$addresses = $this->customerAddressRepository->getList($searchCriteria)->getItems(); | ||
|
||
self::assertCount(1, $addresses); | ||
self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']); | ||
foreach ($addresses as $address) { | ||
$this->customerAddressRepository->delete($address); | ||
} | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/Customer/_files/customer.php | ||
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php | ||
|
@@ -1111,4 +1194,88 @@ private function assignQuoteToCustomer( | |
$this->quoteResource->save($quote); | ||
return $this->quoteIdToMaskedId->execute((int)$quote->getId()); | ||
} | ||
|
||
/** | ||
* @param string $maskedQuoteId | ||
* @param string $shippingMethodCode | ||
* @param string $shippingCarrierCode | ||
* @return string | ||
*/ | ||
private function getSetShippingMethodsQuery( | ||
string $maskedQuoteId, | ||
string $shippingMethodCode, | ||
string $shippingCarrierCode | ||
): string { | ||
return <<<QUERY | ||
mutation { | ||
setShippingMethodsOnCart(input: | ||
{ | ||
cart_id: "$maskedQuoteId", | ||
shipping_methods: [{ | ||
carrier_code: "$shippingCarrierCode" | ||
method_code: "$shippingMethodCode" | ||
}] | ||
}) { | ||
cart { | ||
shipping_addresses { | ||
selected_shipping_method { | ||
carrier_code | ||
method_code | ||
carrier_title | ||
method_title | ||
amount { | ||
value | ||
currency | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
} | ||
|
||
/** | ||
* @param string $maskedQuoteId | ||
* @param string $methodCode | ||
* @return string | ||
*/ | ||
private function getSetPaymentMethodQuery( | ||
string $maskedQuoteId, | ||
string $methodCode | ||
) : string { | ||
return <<<QUERY | ||
mutation { | ||
setPaymentMethodOnCart(input: { | ||
cart_id: "$maskedQuoteId" | ||
payment_method: { | ||
code: "$methodCode" | ||
} | ||
}) { | ||
cart { | ||
selected_payment_method { | ||
code | ||
} | ||
} | ||
} | ||
} | ||
QUERY; | ||
} | ||
|
||
/** | ||
* @param string $maskedQuoteId | ||
* @return string | ||
*/ | ||
private function getPlaceOrderQuery(string $maskedQuoteId): string | ||
{ | ||
return <<<QUERY | ||
mutation { | ||
placeOrder(input: {cart_id: "{$maskedQuoteId}"}) { | ||
order { | ||
order_number | ||
} | ||
} | ||
} | ||
QUERY; | ||
} | ||
} |