Skip to content

Commit 4939719

Browse files
author
Vitaliy Boyko
committed
GraphQl-903: fixed priority of same as shipping
1 parent 663acb0 commit 4939719

File tree

3 files changed

+156
-5
lines changed

3 files changed

+156
-5
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/SetBillingAddressOnCart.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
6565
{
6666
$customerAddressId = $billingAddressInput['customer_address_id'] ?? null;
6767
$addressInput = $billingAddressInput['address'] ?? null;
68-
$useForShipping = isset($billingAddressInput['use_for_shipping'])
69-
? (bool)$billingAddressInput['use_for_shipping'] : false;
7068
$sameAsShipping = isset($billingAddressInput['same_as_shipping'])
71-
? (bool)$billingAddressInput['same_as_shipping'] : $useForShipping;
69+
? (bool)$billingAddressInput['same_as_shipping'] : false;
70+
$sameAsShipping = isset($billingAddressInput['use_for_shipping'])
71+
? (bool)$billingAddressInput['use_for_shipping'] : $sameAsShipping;
7272

7373
if (null === $customerAddressId && null === $addressInput) {
7474
throw new GraphQlInputException(

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,82 @@ public function testSetNewBillingAddressWithSameAsShippingParameter()
208208
$this->assertNewAddressFields($shippingAddressResponse, 'ShippingCartAddress');
209209
}
210210

211+
/**
212+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
213+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
214+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
215+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
216+
*/
217+
public function testSetNewBillingAddressWithUseForShippingParameter()
218+
{
219+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
220+
221+
$query = <<<QUERY
222+
mutation {
223+
setBillingAddressOnCart(
224+
input: {
225+
cart_id: "$maskedQuoteId"
226+
billing_address: {
227+
address: {
228+
firstname: "test firstname"
229+
lastname: "test lastname"
230+
company: "test company"
231+
street: ["test street 1", "test street 2"]
232+
city: "test city"
233+
region: "test region"
234+
postcode: "887766"
235+
country_code: "US"
236+
telephone: "88776655"
237+
}
238+
use_for_shipping: true
239+
}
240+
}
241+
) {
242+
cart {
243+
billing_address {
244+
firstname
245+
lastname
246+
company
247+
street
248+
city
249+
postcode
250+
telephone
251+
country {
252+
code
253+
label
254+
}
255+
__typename
256+
}
257+
shipping_addresses {
258+
firstname
259+
lastname
260+
company
261+
street
262+
city
263+
postcode
264+
telephone
265+
country {
266+
code
267+
label
268+
}
269+
__typename
270+
}
271+
}
272+
}
273+
}
274+
QUERY;
275+
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
276+
277+
self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
278+
$cartResponse = $response['setBillingAddressOnCart']['cart'];
279+
self::assertArrayHasKey('billing_address', $cartResponse);
280+
$billingAddressResponse = $cartResponse['billing_address'];
281+
self::assertArrayHasKey('shipping_addresses', $cartResponse);
282+
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
283+
$this->assertNewAddressFields($billingAddressResponse);
284+
$this->assertNewAddressFields($shippingAddressResponse, 'ShippingCartAddress');
285+
}
286+
211287
/**
212288
* @magentoApiDataFixture Magento/Customer/_files/customer.php
213289
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,87 @@ public function testSetNewBillingAddress()
8484
$this->assertNewAddressFields($billingAddressResponse);
8585
}
8686

87+
/**
88+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
89+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
90+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
91+
*/
92+
public function testSetNewBillingAddressWithSameAsShippingParameter()
93+
{
94+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
95+
96+
$query = <<<QUERY
97+
mutation {
98+
setBillingAddressOnCart(
99+
input: {
100+
cart_id: "$maskedQuoteId"
101+
billing_address: {
102+
address: {
103+
firstname: "test firstname"
104+
lastname: "test lastname"
105+
company: "test company"
106+
street: ["test street 1", "test street 2"]
107+
city: "test city"
108+
region: "test region"
109+
postcode: "887766"
110+
country_code: "US"
111+
telephone: "88776655"
112+
}
113+
same_as_shipping: true
114+
}
115+
}
116+
) {
117+
cart {
118+
billing_address {
119+
firstname
120+
lastname
121+
company
122+
street
123+
city
124+
postcode
125+
telephone
126+
country {
127+
code
128+
label
129+
}
130+
__typename
131+
}
132+
shipping_addresses {
133+
firstname
134+
lastname
135+
company
136+
street
137+
city
138+
postcode
139+
telephone
140+
country {
141+
code
142+
label
143+
}
144+
__typename
145+
}
146+
}
147+
}
148+
}
149+
QUERY;
150+
$response = $this->graphQlMutation($query);
151+
152+
self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
153+
$cartResponse = $response['setBillingAddressOnCart']['cart'];
154+
self::assertArrayHasKey('billing_address', $cartResponse);
155+
$billingAddressResponse = $cartResponse['billing_address'];
156+
self::assertArrayHasKey('shipping_addresses', $cartResponse);
157+
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
158+
$this->assertNewAddressFields($billingAddressResponse);
159+
$this->assertNewAddressFields($shippingAddressResponse, 'ShippingCartAddress');
160+
}
161+
87162
/**
88163
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
89164
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
90165
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
91166
*/
92-
public function testSetNewBillingAddressWithSameAsShippingParameter()
167+
public function testSetNewBillingAddressWithUseForShippingParameter()
93168
{
94169
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
95170

@@ -110,7 +185,7 @@ public function testSetNewBillingAddressWithSameAsShippingParameter()
110185
country_code: "US"
111186
telephone: "88776655"
112187
}
113-
same_as_shipping: true
188+
use_for_shipping: true
114189
}
115190
}
116191
) {

0 commit comments

Comments
 (0)