checkCustomerAccount = $checkCustomerAccount; $this->addressRepository = $addressRepository; $this->getCustomerAddressForUser = $getCustomerAddressForUser; } /** * @inheritdoc */ public function resolve( Field $field, $context, ResolveInfo $info, array $value = null, array $args = null ) { $currentUserId = $context->getUserId(); $currentUserType = $context->getUserType(); $this->checkCustomerAccount->execute($currentUserId, $currentUserType); return $this->deleteCustomerAddress((int)$currentUserId, (int)$args['id']); } /** * Delete customer address * * @param int $customerId * @param int $addressId * @return bool * @throws GraphQlAuthorizationException * @throws GraphQlNoSuchEntityException */ private function deleteCustomerAddress($customerId, $addressId) { $address = $this->getCustomerAddressForUser->execute($addressId, $customerId); if ($address->isDefaultBilling()) { throw new GraphQlAuthorizationException( __('Customer Address %1 is set as default billing address and can not be deleted', [$addressId]) ); } if ($address->isDefaultShipping()) { throw new GraphQlAuthorizationException( __('Customer Address %1 is set as default shipping address and can not be deleted', [$addressId]) ); } return $this->addressRepository->delete($address); } }