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

Commit 216e4b9

Browse files
committed
1 parent 68d2137 commit 216e4b9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

app/code/Magento/CustomerGraphQl/Model/Customer/Address/CreateCustomerAddress.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
use Magento\Customer\Api\AddressRepositoryInterface;
1111
use Magento\Customer\Api\Data\AddressInterface;
1212
use Magento\Customer\Api\Data\AddressInterfaceFactory;
13+
use Magento\Directory\Helper\Data as DirectoryData;
14+
use Magento\Framework\Api\DataObjectHelper;
1315
use Magento\Framework\Exception\LocalizedException;
1416
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
15-
use Magento\Framework\Api\DataObjectHelper;
1617

1718
/**
1819
* Create customer address
@@ -38,23 +39,30 @@ class CreateCustomerAddress
3839
* @var DataObjectHelper
3940
*/
4041
private $dataObjectHelper;
42+
/**
43+
* @var DirectoryData
44+
*/
45+
private $directoryData;
4146

4247
/**
4348
* @param GetAllowedAddressAttributes $getAllowedAddressAttributes
4449
* @param AddressInterfaceFactory $addressFactory
4550
* @param AddressRepositoryInterface $addressRepository
4651
* @param DataObjectHelper $dataObjectHelper
52+
* @param DirectoryData $directoryData
4753
*/
4854
public function __construct(
4955
GetAllowedAddressAttributes $getAllowedAddressAttributes,
5056
AddressInterfaceFactory $addressFactory,
5157
AddressRepositoryInterface $addressRepository,
52-
DataObjectHelper $dataObjectHelper
58+
DataObjectHelper $dataObjectHelper,
59+
DirectoryData $directoryData
5360
) {
5461
$this->getAllowedAddressAttributes = $getAllowedAddressAttributes;
5562
$this->addressFactory = $addressFactory;
5663
$this->addressRepository = $addressRepository;
5764
$this->dataObjectHelper = $dataObjectHelper;
65+
$this->directoryData = $directoryData;
5866
}
5967

6068
/**
@@ -102,6 +110,13 @@ public function validateData(array $addressData): void
102110
$attributes = $this->getAllowedAddressAttributes->execute();
103111
$errorInput = [];
104112

113+
//Add error for empty postcode with country with no optional ZIP
114+
if (!in_array($addressData['country_id'], $this->directoryData->getCountriesWithOptionalZip())
115+
&& (!isset($addressData['postcode']) || empty($addressData['postcode']))
116+
) {
117+
$errorInput[] = 'postcode';
118+
}
119+
105120
foreach ($attributes as $attributeName => $attributeInfo) {
106121
if ($attributeInfo->getIsRequired()
107122
&& (!isset($addressData[$attributeName]) || empty($addressData[$attributeName]))

0 commit comments

Comments
 (0)