Skip to content

Commit df5c5d9

Browse files
authored
ENGCOM-5963: graphQl-903: deprecated use_for_shipping in billing address schema #943
2 parents 1afc4b0 + 20ed684 commit df5c5d9

File tree

5 files changed

+63
-18
lines changed

5 files changed

+63
-18
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ public function __construct(
3939
*
4040
* @param CartInterface $cart
4141
* @param AddressInterface $billingAddress
42-
* @param bool $useForShipping
42+
* @param bool $sameAsShipping
4343
* @throws GraphQlInputException
4444
* @throws GraphQlNoSuchEntityException
4545
*/
4646
public function execute(
4747
CartInterface $cart,
4848
AddressInterface $billingAddress,
49-
bool $useForShipping
49+
bool $sameAsShipping
5050
): void {
5151
try {
52-
$this->billingAddressManagement->assign($cart->getId(), $billingAddress, $useForShipping);
52+
$this->billingAddressManagement->assign($cart->getId(), $billingAddress, $sameAsShipping);
5353
} catch (NoSuchEntityException $e) {
5454
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
5555
} catch (InputException $e) {

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ 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'])
68+
// Need to keep this for BC of `use_for_shipping` field
69+
$sameAsShipping = isset($billingAddressInput['use_for_shipping'])
6970
? (bool)$billingAddressInput['use_for_shipping'] : false;
71+
$sameAsShipping = isset($billingAddressInput['same_as_shipping'])
72+
? (bool)$billingAddressInput['same_as_shipping'] : $sameAsShipping;
7073

7174
if (null === $customerAddressId && null === $addressInput) {
7275
throw new GraphQlInputException(
@@ -81,15 +84,15 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
8184
}
8285

8386
$addresses = $cart->getAllShippingAddresses();
84-
if ($useForShipping && count($addresses) > 1) {
87+
if ($sameAsShipping && count($addresses) > 1) {
8588
throw new GraphQlInputException(
86-
__('Using the "use_for_shipping" option with multishipping is not possible.')
89+
__('Using the "same_as_shipping" option with multishipping is not possible.')
8790
);
8891
}
8992

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

92-
$this->assignBillingAddressToCart->execute($cart, $billingAddress, $useForShipping);
95+
$this->assignBillingAddressToCart->execute($cart, $billingAddress, $sameAsShipping);
9396
}
9497

9598
/**

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ input SetBillingAddressOnCartInput {
9696
input BillingAddressInput {
9797
customer_address_id: Int
9898
address: CartAddressInput
99-
use_for_shipping: Boolean
99+
use_for_shipping: Boolean @doc(description: "Deprecated: use `same_as_shipping` field instead")
100+
same_as_shipping: Boolean @doc(description: "Set billing address same as shipping")
100101
}
101102

102103
input CartAddressInput {

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function testSetNewBillingAddress()
101101
country_code: "US"
102102
telephone: "88776655"
103103
}
104+
same_as_shipping: true
104105
}
105106
}
106107
) {
@@ -119,6 +120,20 @@ public function testSetNewBillingAddress()
119120
}
120121
__typename
121122
}
123+
shipping_addresses {
124+
firstname
125+
lastname
126+
company
127+
street
128+
city
129+
postcode
130+
telephone
131+
country {
132+
code
133+
label
134+
}
135+
__typename
136+
}
122137
}
123138
}
124139
}
@@ -129,10 +144,15 @@ public function testSetNewBillingAddress()
129144
$cartResponse = $response['setBillingAddressOnCart']['cart'];
130145
self::assertArrayHasKey('billing_address', $cartResponse);
131146
$billingAddressResponse = $cartResponse['billing_address'];
147+
self::assertArrayHasKey('shipping_addresses', $cartResponse);
148+
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
132149
$this->assertNewAddressFields($billingAddressResponse);
150+
$this->assertNewAddressFields($shippingAddressResponse, 'ShippingCartAddress');
133151
}
134152

135153
/**
154+
* Test case for deprecated `use_for_shipping` param.
155+
*
136156
* @magentoApiDataFixture Magento/Customer/_files/customer.php
137157
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
138158
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
@@ -389,7 +409,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
389409
input: {
390410
cart_id: "$maskedQuoteId"
391411
billing_address: {
392-
use_for_shipping: true
412+
same_as_shipping: true
393413
}
394414
}
395415
) {
@@ -415,7 +435,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
415435
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
416436
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_multishipping_with_two_shipping_addresses.php
417437
*/
418-
public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
438+
public function testSetNewBillingAddressWithSameAsShippingAndMultishipping()
419439
{
420440
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
421441

@@ -436,7 +456,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
436456
country_code: "US"
437457
telephone: "88776655"
438458
}
439-
use_for_shipping: true
459+
same_as_shipping: true
440460
}
441461
}
442462
) {
@@ -450,7 +470,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
450470
QUERY;
451471

452472
self::expectExceptionMessage(
453-
'Using the "use_for_shipping" option with multishipping is not possible.'
473+
'Using the "same_as_shipping" option with multishipping is not possible.'
454474
);
455475
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
456476
}

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testSetNewBillingAddress()
4242
input: {
4343
cart_id: "$maskedQuoteId"
4444
billing_address: {
45-
address: {
45+
address: {
4646
firstname: "test firstname"
4747
lastname: "test lastname"
4848
company: "test company"
@@ -52,7 +52,8 @@ public function testSetNewBillingAddress()
5252
postcode: "887766"
5353
country_code: "US"
5454
telephone: "88776655"
55-
}
55+
}
56+
same_as_shipping: true
5657
}
5758
}
5859
) {
@@ -71,6 +72,20 @@ public function testSetNewBillingAddress()
7172
}
7273
__typename
7374
}
75+
shipping_addresses {
76+
firstname
77+
lastname
78+
company
79+
street
80+
city
81+
postcode
82+
telephone
83+
country {
84+
code
85+
label
86+
}
87+
__typename
88+
}
7489
}
7590
}
7691
}
@@ -82,9 +97,15 @@ public function testSetNewBillingAddress()
8297
self::assertArrayHasKey('billing_address', $cartResponse);
8398
$billingAddressResponse = $cartResponse['billing_address'];
8499
$this->assertNewAddressFields($billingAddressResponse);
100+
self::assertArrayHasKey('shipping_addresses', $cartResponse);
101+
$shippingAddressResponse = current($cartResponse['shipping_addresses']);
102+
$this->assertNewAddressFields($billingAddressResponse);
103+
$this->assertNewAddressFields($shippingAddressResponse, 'ShippingCartAddress');
85104
}
86105

87106
/**
107+
* Test case for deprecated `use_for_shipping` param.
108+
*
88109
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
89110
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
90111
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
@@ -342,7 +363,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
342363
input: {
343364
cart_id: "$maskedQuoteId"
344365
billing_address: {
345-
use_for_shipping: true
366+
same_as_shipping: true
346367
}
347368
}
348369
) {
@@ -367,7 +388,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
367388
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
368389
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_multishipping_with_two_shipping_addresses.php
369390
*/
370-
public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
391+
public function testSetNewBillingAddressWithSameAsShippingAndMultishipping()
371392
{
372393
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
373394

@@ -388,7 +409,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
388409
country_code: "US"
389410
telephone: "88776655"
390411
}
391-
use_for_shipping: true
412+
same_as_shipping: true
392413
}
393414
}
394415
) {
@@ -402,7 +423,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
402423
QUERY;
403424

404425
self::expectExceptionMessage(
405-
'Using the "use_for_shipping" option with multishipping is not possible.'
426+
'Using the "same_as_shipping" option with multishipping is not possible.'
406427
);
407428
$this->graphQlMutation($query);
408429
}

0 commit comments

Comments
 (0)