Skip to content

Commit

Permalink
LYNX-121: Add custom_attributes to updateCustomerV2 mutation (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
loginesta authored May 3, 2023
1 parent ce8ace7 commit 9f0ae06
Show file tree
Hide file tree
Showing 3 changed files with 383 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\CustomerGraphQl\Model\Customer;

use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\GraphQl\Exception\GraphQlAlreadyExistsException;
use Magento\Framework\GraphQl\Exception\GraphQlAuthenticationException;
Expand Down Expand Up @@ -89,17 +90,20 @@ public function __construct(
* @throws GraphQlAuthenticationException
* @throws GraphQlInputException
* @throws GraphQlNoSuchEntityException
* @throws NoSuchEntityException
* @throws LocalizedException
*/
public function execute(CustomerInterface $customer, array $data, StoreInterface $store): void
{
if (isset($data['email']) && $customer->getEmail() !== $data['email']) {
if (!isset($data['password']) || empty($data['password'])) {
if (empty($data['password'])) {
throw new GraphQlInputException(__('Provide the current "password" to change "email".'));
}

$this->checkCustomerPassword->execute($data['password'], (int)$customer->getId());
$customer->setEmail($data['email']);
}

$this->validateCustomerData->execute($data);
$filteredData = array_diff_key($data, array_flip($this->restrictedKeys));
$this->dataObjectHelper->populateWithArray($customer, $filteredData, CustomerInterface::class);
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/CustomerGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ input CustomerUpdateInput @doc(description: "An input object for updating a cust
prefix: String @doc(description: "An honorific, such as Dr., Mr., or Mrs.")
suffix: String @doc(description: "A value such as Sr., Jr., or III.")
taxvat: String @doc(description: "The customer's Tax/VAT number (for corporate customers).")
custom_attributes: [AttributeValueInput!] @doc(description: "The customer's custom attributes.")
}

type CustomerOutput @doc(description: "Contains details about a newly-created or updated customer.") {
Expand Down
Loading

0 comments on commit 9f0ae06

Please sign in to comment.