Skip to content

Commit

Permalink
GraphQl-903: fixed priority of same as shipping
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Boyko committed Oct 20, 2019
1 parent 663acb0 commit 4939719
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ 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'] : $useForShipping;
? (bool)$billingAddressInput['same_as_shipping'] : false;
$sameAsShipping = isset($billingAddressInput['use_for_shipping'])
? (bool)$billingAddressInput['use_for_shipping'] : $sameAsShipping;

if (null === $customerAddressId && null === $addressInput) {
throw new GraphQlInputException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,82 @@ public function testSetNewBillingAddressWithSameAsShippingParameter()
$this->assertNewAddressFields($shippingAddressResponse, 'ShippingCartAddress');
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
*/
public function testSetNewBillingAddressWithUseForShippingParameter()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = <<<QUERY
mutation {
setBillingAddressOnCart(
input: {
cart_id: "$maskedQuoteId"
billing_address: {
address: {
firstname: "test firstname"
lastname: "test lastname"
company: "test company"
street: ["test street 1", "test street 2"]
city: "test city"
region: "test region"
postcode: "887766"
country_code: "US"
telephone: "88776655"
}
use_for_shipping: true
}
}
) {
cart {
billing_address {
firstname
lastname
company
street
city
postcode
telephone
country {
code
label
}
__typename
}
shipping_addresses {
firstname
lastname
company
street
city
postcode
telephone
country {
code
label
}
__typename
}
}
}
}
QUERY;
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());

self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
$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');
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,87 @@ public function testSetNewBillingAddress()
$this->assertNewAddressFields($billingAddressResponse);
}

/**
* @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
*/
public function testSetNewBillingAddressWithSameAsShippingParameter()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = <<<QUERY
mutation {
setBillingAddressOnCart(
input: {
cart_id: "$maskedQuoteId"
billing_address: {
address: {
firstname: "test firstname"
lastname: "test lastname"
company: "test company"
street: ["test street 1", "test street 2"]
city: "test city"
region: "test region"
postcode: "887766"
country_code: "US"
telephone: "88776655"
}
same_as_shipping: true
}
}
) {
cart {
billing_address {
firstname
lastname
company
street
city
postcode
telephone
country {
code
label
}
__typename
}
shipping_addresses {
firstname
lastname
company
street
city
postcode
telephone
country {
code
label
}
__typename
}
}
}
}
QUERY;
$response = $this->graphQlMutation($query);

self::assertArrayHasKey('cart', $response['setBillingAddressOnCart']);
$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');
}

/**
* @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
*/
public function testSetNewBillingAddressWithSameAsShippingParameter()
public function testSetNewBillingAddressWithUseForShippingParameter()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

Expand All @@ -110,7 +185,7 @@ public function testSetNewBillingAddressWithSameAsShippingParameter()
country_code: "US"
telephone: "88776655"
}
same_as_shipping: true
use_for_shipping: true
}
}
) {
Expand Down

0 comments on commit 4939719

Please sign in to comment.