Skip to content

Commit eb48f44

Browse files
committed
magento#271: [My Account] Minor fixes for validation and exceptions handling
1 parent f358267 commit eb48f44

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

app/code/Magento/CustomerGraphQl/Model/Customer/UpdateCustomerAccount.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
namespace Magento\CustomerGraphQl\Model\Customer;
99

10+
use Magento\Framework\Exception\NoSuchEntityException;
1011
use Magento\Framework\GraphQl\Exception\GraphQlAlreadyExistsException;
1112
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException;
1213
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
14+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1315
use Magento\Store\Model\StoreManagerInterface;
1416
use Magento\Customer\Api\Data\CustomerInterface;
1517
use Magento\Framework\Api\DataObjectHelper;
@@ -89,8 +91,7 @@ public function __construct(
8991
* @throws GraphQlAlreadyExistsException
9092
* @throws GraphQlAuthenticationException
9193
* @throws GraphQlInputException
92-
* @throws \Magento\Framework\Exception\NoSuchEntityException
93-
* @throws \Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException
94+
* @throws GraphQlNoSuchEntityException
9495
*/
9596
public function execute(CustomerInterface $customer, array $data): void
9697
{
@@ -106,7 +107,12 @@ public function execute(CustomerInterface $customer, array $data): void
106107
$filteredData = array_diff_key($data, array_flip($this->restrictedKeys));
107108
$this->dataObjectHelper->populateWithArray($customer, $filteredData, CustomerInterface::class);
108109

109-
$customer->setStoreId($this->storeManager->getStore()->getId());
110+
try {
111+
$customer->setStoreId($this->storeManager->getStore()->getId());
112+
} catch (NoSuchEntityException $exception) {
113+
throw new GraphQlNoSuchEntityException(__($exception->getMessage()), $exception);
114+
}
115+
110116

111117
$this->saveCustomer->execute($customer);
112118

app/code/Magento/CustomerGraphQl/Model/Customer/ValidateCustomerData.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function execute(array $customerData, $addRequiredAttributes = false): vo
4747
$errorInput = [];
4848

4949
foreach ($attributes as $attributeInfo) {
50-
if ($attributeInfo->getIsRequired() && empty($customerData[$attributeInfo->getAttributeCode()])) {
50+
if ($attributeInfo->getIsRequired() && $customerData[$attributeInfo->getAttributeCode()] == '') {
5151
$errorInput[] = $attributeInfo->getDefaultFrontendLabel();
5252
}
5353
}

0 commit comments

Comments
 (0)