Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

graphQl-903: deprecated use_for_shipping in billing address schema #943

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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 (LocalizedException $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ 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'])
? (bool)$billingAddressInput['use_for_shipping'] : false;
$sameAsshipping = isset($billingAddressInput['same_as_shipping'])
? (bool)$billingAddressInput['same_as_shipping'] : false;

if (null === $customerAddressId && null === $addressInput) {
throw new GraphQlInputException(
Expand All @@ -72,15 +72,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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testSetNewBillingAddress()
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
*/
public function testSetNewBillingAddressWithUseForShippingParameter()
public function testSetNewBillingAddressWithSameAsShippingParameter()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

Expand All @@ -142,7 +142,7 @@ public function testSetNewBillingAddressWithUseForShippingParameter()
telephone: "88776655"
save_in_address_book: false
}
use_for_shipping: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep tests for both fields for now.

same_as_shipping: true
}
}
) {
Expand Down Expand Up @@ -337,7 +337,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
input: {
cart_id: "$maskedQuoteId"
billing_address: {
use_for_shipping: true
same_as_shipping: true
}
}
) {
Expand All @@ -363,7 +363,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');

Expand All @@ -385,7 +385,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
telephone: "88776655"
save_in_address_book: false
}
use_for_shipping: true
same_as_shipping: true
}
}
) {
Expand All @@ -399,7 +399,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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testSetNewBillingAddress()
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
*/
public function testSetNewBillingAddressWithUseForShippingParameter()
public function testSetNewBillingAddressWithSameAsShippingParameter()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

Expand All @@ -112,7 +112,7 @@ public function testSetNewBillingAddressWithUseForShippingParameter()
telephone: "88776655"
save_in_address_book: false
}
use_for_shipping: true
same_as_shipping: true
}
}
) {
Expand Down Expand Up @@ -346,7 +346,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
input: {
cart_id: "$maskedQuoteId"
billing_address: {
use_for_shipping: true
same_as_shipping: true
}
}
) {
Expand All @@ -371,7 +371,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');

Expand All @@ -393,7 +393,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
telephone: "88776655"
save_in_address_book: false
}
use_for_shipping: true
same_as_shipping: true
}
}
) {
Expand All @@ -407,7 +407,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);
}
Expand Down