Skip to content

Commit

Permalink
ENGCOM-5963: graphQl-903: deprecated use_for_shipping in billing addr…
Browse files Browse the repository at this point in the history
…ess schema #943
  • Loading branch information
lenaorobei authored Oct 28, 2019
2 parents 1afc4b0 + 20ed684 commit df5c5d9
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
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 (InputException $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}

/**
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 @@ -101,6 +101,7 @@ public function testSetNewBillingAddress()
country_code: "US"
telephone: "88776655"
}
same_as_shipping: true
}
}
) {
Expand All @@ -119,6 +120,20 @@ public function testSetNewBillingAddress()
}
__typename
}
shipping_addresses {
firstname
lastname
company
street
city
postcode
telephone
country {
code
label
}
__typename
}
}
}
}
Expand All @@ -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
Expand Down Expand Up @@ -389,7 +409,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
input: {
cart_id: "$maskedQuoteId"
billing_address: {
use_for_shipping: true
same_as_shipping: true
}
}
) {
Expand All @@ -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');

Expand All @@ -436,7 +456,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
country_code: "US"
telephone: "88776655"
}
use_for_shipping: true
same_as_shipping: true
}
}
) {
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testSetNewBillingAddress()
input: {
cart_id: "$maskedQuoteId"
billing_address: {
address: {
address: {
firstname: "test firstname"
lastname: "test lastname"
company: "test company"
Expand All @@ -52,7 +52,8 @@ public function testSetNewBillingAddress()
postcode: "887766"
country_code: "US"
telephone: "88776655"
}
}
same_as_shipping: true
}
}
) {
Expand All @@ -71,6 +72,20 @@ public function testSetNewBillingAddress()
}
__typename
}
shipping_addresses {
firstname
lastname
company
street
city
postcode
telephone
country {
code
label
}
__typename
}
}
}
}
Expand All @@ -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
Expand Down Expand Up @@ -342,7 +363,7 @@ public function testSetNewBillingAddressWithoutCustomerAddressIdAndAddress()
input: {
cart_id: "$maskedQuoteId"
billing_address: {
use_for_shipping: true
same_as_shipping: true
}
}
) {
Expand All @@ -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');

Expand All @@ -388,7 +409,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
country_code: "US"
telephone: "88776655"
}
use_for_shipping: true
same_as_shipping: true
}
}
) {
Expand All @@ -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);
}
Expand Down

0 comments on commit df5c5d9

Please sign in to comment.