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

Commit 18a3260

Browse files
committed
graphQl-961: ShippingAddressInput.postcode: String, is not required by Schema
1 parent 39c9c80 commit 18a3260

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/QuoteAddressFactory.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
use Magento\Customer\Helper\Address as AddressHelper;
1111
use Magento\CustomerGraphQl\Model\Customer\Address\GetCustomerAddress;
12+
use Magento\Directory\Api\CountryInformationAcquirerInterface;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1415
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1516
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1617
use Magento\Quote\Model\Quote\Address as QuoteAddress;
1718
use Magento\Quote\Model\Quote\AddressFactory as BaseQuoteAddressFactory;
19+
use Magento\Framework\App\ObjectManager;
1820

1921
/**
2022
* Create QuoteAddress
@@ -36,38 +38,53 @@ class QuoteAddressFactory
3638
*/
3739
private $addressHelper;
3840

41+
/**
42+
* @var CountryInformationAcquirerInterface
43+
*/
44+
private $countryInformationAcquirer;
45+
3946
/**
4047
* @param BaseQuoteAddressFactory $quoteAddressFactory
4148
* @param GetCustomerAddress $getCustomerAddress
4249
* @param AddressHelper $addressHelper
50+
* @param CountryInformationAcquirerInterface|null $countryInformationAcquirer
4351
*/
4452
public function __construct(
4553
BaseQuoteAddressFactory $quoteAddressFactory,
4654
GetCustomerAddress $getCustomerAddress,
47-
AddressHelper $addressHelper
55+
AddressHelper $addressHelper,
56+
CountryInformationAcquirerInterface $countryInformationAcquirer = null
4857
) {
4958
$this->quoteAddressFactory = $quoteAddressFactory;
5059
$this->getCustomerAddress = $getCustomerAddress;
5160
$this->addressHelper = $addressHelper;
61+
$this->countryInformationAcquirer = $countryInformationAcquirer;
62+
$this->countryInformationAcquirer = $countryInformationAcquirer
63+
?: ObjectManager::getInstance()->get(CountryInformationAcquirerInterface::class);
5264
}
5365

5466
/**
5567
* Create QuoteAddress based on input data
5668
*
5769
* @param array $addressInput
70+
*
5871
* @return QuoteAddress
5972
* @throws GraphQlInputException
6073
*/
6174
public function createBasedOnInputData(array $addressInput): QuoteAddress
6275
{
6376
$addressInput['country_id'] = '';
64-
if ($addressInput['country_code']) {
77+
if (isset($addressInput['country_code']) && $addressInput['country_code']) {
6578
$addressInput['country_code'] = strtoupper($addressInput['country_code']);
6679
$addressInput['country_id'] = $addressInput['country_code'];
6780
}
6881

69-
if (isset($addressInput['region'])) {
70-
$addressInput['region_code'] = $addressInput['region'];
82+
if ($addressInput['country_id'] && isset($addressInput['region'])) {
83+
$countryInformation = $this->countryInformationAcquirer->getCountryInfo($addressInput['country_id']);
84+
$availableRegions = $countryInformation->getAvailableRegions();
85+
if (null !== $availableRegions) {
86+
$addressInput['region_code'] = $addressInput['region'];
87+
}
7188
}
7289

7390
$maxAllowedLineCount = $this->addressHelper->getStreetLines();

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testSetNewBillingAddress()
4848
company: "test company"
4949
street: ["test street 1", "test street 2"]
5050
city: "test city"
51-
region: "test region"
51+
region: "AL"
5252
postcode: "887766"
5353
country_code: "US"
5454
telephone: "88776655"
@@ -106,7 +106,7 @@ public function testSetNewBillingAddressWithUseForShippingParameter()
106106
company: "test company"
107107
street: ["test street 1", "test street 2"]
108108
city: "test city"
109-
region: "test region"
109+
region: "AL"
110110
postcode: "887766"
111111
country_code: "US"
112112
telephone: "88776655"
@@ -182,7 +182,7 @@ public function testSetBillingAddressToCustomerCart()
182182
company: "test company"
183183
street: ["test street 1", "test street 2"]
184184
city: "test city"
185-
region: "test region"
185+
region: "AL"
186186
postcode: "887766"
187187
country_code: "US"
188188
telephone: "88776655"
@@ -259,7 +259,7 @@ public function testSetBillingAddressOnNonExistentCart()
259259
company: "test company"
260260
street: ["test street 1", "test street 2"]
261261
city: "test city"
262-
region: "test region"
262+
region: "AL"
263263
postcode: "887766"
264264
country_code: "US"
265265
telephone: "88776655"
@@ -387,7 +387,7 @@ public function testSetNewBillingAddressWithUseForShippingAndMultishipping()
387387
company: "test company"
388388
street: ["test street 1", "test street 2"]
389389
city: "test city"
390-
region: "test region"
390+
region: "AL"
391391
postcode: "887766"
392392
country_code: "US"
393393
telephone: "88776655"
@@ -433,7 +433,7 @@ public function testSetNewBillingAddressRedundantStreetLine()
433433
company: "test company"
434434
street: ["test street 1", "test street 2", "test street 3"]
435435
city: "test city"
436-
region: "test region"
436+
region: "AL"
437437
postcode: "887766"
438438
country_code: "US"
439439
telephone: "88776655"
@@ -476,7 +476,7 @@ public function testSetBillingAddressWithLowerCaseCountry()
476476
company: "test company"
477477
street: ["test street 1", "test street 2"]
478478
city: "test city"
479-
region: "test region"
479+
region: "AL"
480480
postcode: "887766"
481481
country_code: "us"
482482
telephone: "88776655"

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testSetNewShippingAddressOnCartWithSimpleProduct()
4949
company: "test company"
5050
street: ["test street 1", "test street 2"]
5151
city: "test city"
52-
region: "test region"
52+
region: "AL"
5353
postcode: "887766"
5454
country_code: "US"
5555
telephone: "88776655"
@@ -114,7 +114,7 @@ public function testSetNewShippingAddressOnCartWithVirtualProduct()
114114
company: "test company"
115115
street: ["test street 1", "test street 2"]
116116
city: "test city"
117-
region: "test region"
117+
region: "AL"
118118
postcode: "887766"
119119
country_code: "US"
120120
telephone: "88776655"
@@ -266,7 +266,7 @@ public function testSetNewShippingAddressOnCartWithRedundantStreetLine()
266266
company: "test company"
267267
street: ["test street 1", "test street 2", "test street 3"]
268268
city: "test city"
269-
region: "test region"
269+
region: "AL"
270270
postcode: "887766"
271271
country_code: "US"
272272
telephone: "88776655"
@@ -335,7 +335,7 @@ public function testSetMultipleNewShippingAddresses()
335335
company: "test company"
336336
street: ["test street 1", "test street 2"]
337337
city: "test city"
338-
region: "test region"
338+
region: "AL"
339339
postcode: "887766"
340340
country_code: "US"
341341
telephone: "88776655"
@@ -349,7 +349,7 @@ public function testSetMultipleNewShippingAddresses()
349349
company: "test company 2"
350350
street: ["test street 1", "test street 2"]
351351
city: "test city"
352-
region: "test region"
352+
region: "AL"
353353
postcode: "887766"
354354
country_code: "US"
355355
telephone: "88776655"
@@ -389,7 +389,7 @@ public function testSetShippingAddressOnNonExistentCart()
389389
company: "test company"
390390
street: ["test street 1", "test street 2"]
391391
city: "test city"
392-
region: "test region"
392+
region: "AL"
393393
postcode: "887766"
394394
country_code: "US"
395395
telephone: "88776655"

0 commit comments

Comments
 (0)