Skip to content

Commit 66290e6

Browse files
author
Vitaliy Boyko
committed
graphQl-864: Prevent to return a shipping address until it be set on a cart
1 parent ebee07a commit 66290e6

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddresses.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4444
$cart = $value['model'];
4545

4646
$addressesData = [];
47+
if (!$cart->getExtensionAttributes()->getShippingAssignments()) {
48+
return $addressesData;
49+
}
50+
4751
$shippingAddresses = $cart->getAllShippingAddresses();
4852

4953
if (count($shippingAddresses)) {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ public function testGetSpecifiedShippingAddress()
7777
self::assertEquals($expectedShippingAddressData, current($response['cart']['shipping_addresses']));
7878
}
7979

80+
/**
81+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
82+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
83+
*/
84+
public function testShippingAddressOnCreatedEmptyCart()
85+
{
86+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
87+
$query = $this->getQuery($maskedQuoteId);
88+
89+
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
90+
self::assertArrayHasKey('cart', $response);
91+
self::assertArrayHasKey('shipping_addresses', $response['cart']);
92+
93+
self::assertCount(0, $response['cart']['shipping_addresses']);
94+
}
95+
8096
/**
8197
* @magentoApiDataFixture Magento/Customer/_files/customer.php
8298
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ public function testGetSpecifiedShippingAddress()
6868
self::assertEquals($expectedShippingAddressData, current($response['cart']['shipping_addresses']));
6969
}
7070

71+
/**
72+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
73+
*/
74+
public function testShippingAddressOnCreatedEmptyCart()
75+
{
76+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
77+
$query = $this->getQuery($maskedQuoteId);
78+
79+
$response = $this->graphQlQuery($query);
80+
self::assertArrayHasKey('cart', $response);
81+
self::assertArrayHasKey('shipping_addresses', $response['cart']);
82+
83+
self::assertCount(0, $response['cart']['shipping_addresses']);
84+
}
85+
7186
/**
7287
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
7388
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php

0 commit comments

Comments
 (0)