Skip to content

Commit

Permalink
magento#271: [My Account] Minor fixes for validation and exceptions h…
Browse files Browse the repository at this point in the history
…andling
  • Loading branch information
furseyev committed Jun 24, 2019
1 parent f358267 commit eb48f44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

namespace Magento\CustomerGraphQl\Model\Customer;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Exception\GraphQlAlreadyExistsException;
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\Api\DataObjectHelper;
Expand Down Expand Up @@ -89,8 +91,7 @@ public function __construct(
* @throws GraphQlAlreadyExistsException
* @throws GraphQlAuthenticationException
* @throws GraphQlInputException
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException
* @throws GraphQlNoSuchEntityException
*/
public function execute(CustomerInterface $customer, array $data): void
{
Expand All @@ -106,7 +107,12 @@ public function execute(CustomerInterface $customer, array $data): void
$filteredData = array_diff_key($data, array_flip($this->restrictedKeys));
$this->dataObjectHelper->populateWithArray($customer, $filteredData, CustomerInterface::class);

$customer->setStoreId($this->storeManager->getStore()->getId());
try {
$customer->setStoreId($this->storeManager->getStore()->getId());
} catch (NoSuchEntityException $exception) {
throw new GraphQlNoSuchEntityException(__($exception->getMessage()), $exception);
}


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function execute(array $customerData, $addRequiredAttributes = false): vo
$errorInput = [];

foreach ($attributes as $attributeInfo) {
if ($attributeInfo->getIsRequired() && empty($customerData[$attributeInfo->getAttributeCode()])) {
if ($attributeInfo->getIsRequired() && $customerData[$attributeInfo->getAttributeCode()] == '') {
$errorInput[] = $attributeInfo->getDefaultFrontendLabel();
}
}
Expand Down

0 comments on commit eb48f44

Please sign in to comment.