diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php index 95c46cdcca5dc..22bd0abb1a159 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/AssignBillingAddressToCart.php @@ -39,17 +39,17 @@ public function __construct( * * @param CartInterface $cart * @param AddressInterface $billingAddress - * @param bool $useForShipping + * @param bool $sameAsShipping * @throws GraphQlInputException * @throws GraphQlNoSuchEntityException */ public function execute( CartInterface $cart, AddressInterface $billingAddress, - bool $useForShipping + bool $sameAsShipping ): void { try { - $this->billingAddressManagement->assign($cart->getId(), $billingAddress, $useForShipping); + $this->billingAddressManagement->assign($cart->getId(), $billingAddress, $sameAsShipping); } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e); } catch (InputException $e) { diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/SetBillingAddressOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/SetBillingAddressOnCart.php index f3b96a1454fb8..7c8126194777f 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/SetBillingAddressOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/SetBillingAddressOnCart.php @@ -65,8 +65,11 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b { $customerAddressId = $billingAddressInput['customer_address_id'] ?? null; $addressInput = $billingAddressInput['address'] ?? null; - $useForShipping = isset($billingAddressInput['use_for_shipping']) + // Need to keep this for BC of `use_for_shipping` field + $sameAsShipping = isset($billingAddressInput['use_for_shipping']) ? (bool)$billingAddressInput['use_for_shipping'] : false; + $sameAsShipping = isset($billingAddressInput['same_as_shipping']) + ? (bool)$billingAddressInput['same_as_shipping'] : $sameAsShipping; if (null === $customerAddressId && null === $addressInput) { throw new GraphQlInputException( @@ -81,15 +84,15 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b } $addresses = $cart->getAllShippingAddresses(); - if ($useForShipping && count($addresses) > 1) { + if ($sameAsShipping && count($addresses) > 1) { throw new GraphQlInputException( - __('Using the "use_for_shipping" option with multishipping is not possible.') + __('Using the "same_as_shipping" option with multishipping is not possible.') ); } $billingAddress = $this->createBillingAddress($context, $customerAddressId, $addressInput); - $this->assignBillingAddressToCart->execute($cart, $billingAddress, $useForShipping); + $this->assignBillingAddressToCart->execute($cart, $billingAddress, $sameAsShipping); } /** diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index 0f818984ebda4..76bab6349424b 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -96,7 +96,8 @@ input SetBillingAddressOnCartInput { input BillingAddressInput { customer_address_id: Int address: CartAddressInput - use_for_shipping: Boolean + use_for_shipping: Boolean @doc(description: "Deprecated: use `same_as_shipping` field instead") + same_as_shipping: Boolean @doc(description: "Set billing address same as shipping") } input CartAddressInput { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php index d4f23854378fa..d2164a6dcc65f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/SetBillingAddressOnCartTest.php @@ -101,6 +101,7 @@ public function testSetNewBillingAddress() country_code: "US" telephone: "88776655" } + same_as_shipping: true } } ) { @@ -119,6 +120,20 @@ public function testSetNewBillingAddress() } __typename } + shipping_addresses { + firstname + lastname + company + street + city + postcode + telephone + country { + code + label + } + __typename + } } } } @@ -129,10 +144,15 @@ public function testSetNewBillingAddress() $cartResponse = $response['setBillingAddressOnCart']['cart']; self::assertArrayHasKey('billing_address', $cartResponse); $billingAddressResponse = $cartResponse['billing_address']; + self::assertArrayHasKey('shipping_addresses', $cartResponse); + $shippingAddressResponse = current($cartResponse['shipping_addresses']); $this->assertNewAddressFields($billingAddressResponse); + $this->assertNewAddressFields($shippingAddressResponse, 'ShippingCartAddress'); } /** + * Test case for deprecated `use_for_shipping` param. + * * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php @@ -389,7 +409,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress() input: { cart_id: "$maskedQuoteId" billing_address: { - use_for_shipping: true + same_as_shipping: true } } ) { @@ -415,7 +435,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress() * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_multishipping_with_two_shipping_addresses.php */ - public function testSetNewBillingAddressWithUseForShippingAndMultishipping() + public function testSetNewBillingAddressWithSameAsShippingAndMultishipping() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); @@ -436,7 +456,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping() country_code: "US" telephone: "88776655" } - use_for_shipping: true + same_as_shipping: true } } ) { @@ -450,7 +470,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping() QUERY; self::expectExceptionMessage( - 'Using the "use_for_shipping" option with multishipping is not possible.' + 'Using the "same_as_shipping" option with multishipping is not possible.' ); $this->graphQlMutation($query, [], '', $this->getHeaderMap()); } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php index 5a3d45005c911..92822c6ce2056 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/SetBillingAddressOnCartTest.php @@ -42,7 +42,7 @@ public function testSetNewBillingAddress() input: { cart_id: "$maskedQuoteId" billing_address: { - address: { + address: { firstname: "test firstname" lastname: "test lastname" company: "test company" @@ -52,7 +52,8 @@ public function testSetNewBillingAddress() postcode: "887766" country_code: "US" telephone: "88776655" - } + } + same_as_shipping: true } } ) { @@ -71,6 +72,20 @@ public function testSetNewBillingAddress() } __typename } + shipping_addresses { + firstname + lastname + company + street + city + postcode + telephone + country { + code + label + } + __typename + } } } } @@ -82,9 +97,15 @@ public function testSetNewBillingAddress() self::assertArrayHasKey('billing_address', $cartResponse); $billingAddressResponse = $cartResponse['billing_address']; $this->assertNewAddressFields($billingAddressResponse); + self::assertArrayHasKey('shipping_addresses', $cartResponse); + $shippingAddressResponse = current($cartResponse['shipping_addresses']); + $this->assertNewAddressFields($billingAddressResponse); + $this->assertNewAddressFields($shippingAddressResponse, 'ShippingCartAddress'); } /** + * Test case for deprecated `use_for_shipping` param. + * * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php @@ -342,7 +363,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress() input: { cart_id: "$maskedQuoteId" billing_address: { - use_for_shipping: true + same_as_shipping: true } } ) { @@ -367,7 +388,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress() * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_multishipping_with_two_shipping_addresses.php */ - public function testSetNewBillingAddressWithUseForShippingAndMultishipping() + public function testSetNewBillingAddressWithSameAsShippingAndMultishipping() { $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote'); @@ -388,7 +409,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping() country_code: "US" telephone: "88776655" } - use_for_shipping: true + same_as_shipping: true } } ) { @@ -402,7 +423,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping() QUERY; self::expectExceptionMessage( - 'Using the "use_for_shipping" option with multishipping is not possible.' + 'Using the "same_as_shipping" option with multishipping is not possible.' ); $this->graphQlMutation($query); }