Skip to content

Commit 9bf12cc

Browse files
committed
subscription implementetion way changed, schema required fields removed, gender input type changed
1 parent 176bc4a commit 9bf12cc

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Customer\Api\AccountManagementInterface;
1212
use Magento\Customer\Api\Data\CustomerInterface;
1313
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
14+
use Magento\CustomerGraphQl\Model\Customer\ChangeSubscriptionStatus;
1415
use Magento\CustomerGraphQl\Model\Customer\CustomerDataProvider;
1516
use Magento\Framework\Api\DataObjectHelper;
1617
use Magento\Framework\Exception\LocalizedException;
@@ -22,26 +23,20 @@
2223
use Magento\Newsletter\Model\SubscriberFactory;
2324
use Magento\Store\Model\StoreManagerInterface;
2425

25-
/**
26-
* Create customer data resolver
27-
*/
2826
class CreateCustomer implements ResolverInterface
2927
{
3028
/**
3129
* @var CustomerDataProvider
3230
*/
3331
private $customerDataProvider;
34-
3532
/**
3633
* @var AccountManagementInterface
3734
*/
3835
private $accountManagement;
39-
4036
/**
4137
* @var CustomerInterfaceFactory
4238
*/
4339
private $customerFactory;
44-
4540
/**
4641
* @var DataObjectHelper
4742
*/
@@ -54,6 +49,10 @@ class CreateCustomer implements ResolverInterface
5449
* @var SubscriberFactory
5550
*/
5651
private $subscriberFactory;
52+
/**
53+
* @var ChangeSubscriptionStatus
54+
*/
55+
private $changeSubscriptionStatus;
5756

5857
/**
5958
* @param DataObjectHelper $dataObjectHelper
@@ -62,21 +61,24 @@ class CreateCustomer implements ResolverInterface
6261
* @param StoreManagerInterface $storeManager
6362
* @param SubscriberFactory $subscriberFactory
6463
* @param CustomerDataProvider $customerDataProvider
64+
* @param ChangeSubscriptionStatus $changeSubscriptionStatus
6565
*/
6666
public function __construct(
6767
DataObjectHelper $dataObjectHelper,
6868
CustomerInterfaceFactory $customerFactory,
6969
AccountManagementInterface $accountManagement,
7070
StoreManagerInterface $storeManager,
7171
SubscriberFactory $subscriberFactory,
72-
CustomerDataProvider $customerDataProvider
72+
CustomerDataProvider $customerDataProvider,
73+
ChangeSubscriptionStatus $changeSubscriptionStatus
7374
) {
7475
$this->customerDataProvider = $customerDataProvider;
7576
$this->accountManagement = $accountManagement;
7677
$this->customerFactory = $customerFactory;
7778
$this->dataObjectHelper = $dataObjectHelper;
7879
$this->storeManager = $storeManager;
7980
$this->subscriberFactory = $subscriberFactory;
81+
$this->changeSubscriptionStatus = $changeSubscriptionStatus;
8082
}
8183

8284
/**
@@ -94,13 +96,14 @@ public function resolve(
9496
}
9597
try {
9698
$customer = $this->createUserAccount($args);
99+
$customerId = (int)$customer->getId();
97100
$this->setUpUserContext($context, $customer);
98101
if (array_key_exists('is_subscribed', $args['input'])) {
99102
if ($args['input']['is_subscribed']) {
100-
$this->subscriberFactory->create()->subscribeCustomerById($customer->getId());
103+
$this->changeSubscriptionStatus->execute($customerId, true);
101104
}
102105
}
103-
$data = $this->customerDataProvider->getCustomerById((int)$customer->getId());
106+
$data = $this->customerDataProvider->getCustomerById($customerId);
104107
} catch (LocalizedException $e) {
105108
throw new GraphQlInputException(__($e->getMessage()));
106109
}

app/code/Magento/CustomerGraphQl/etc/schema.graphqls

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ type CustomerToken {
1919

2020
input CustomerInput {
2121
prefix: String
22-
firstname: String!
23-
middlename: String!
24-
lastname: String!
22+
firstname: String
23+
middlename: String
24+
lastname: String
2525
suffix: String
2626
dob: String
2727
taxvat: String
28-
gender: String
29-
email: String!
30-
password: String!
28+
gender: Int
29+
email: String
30+
password: String
3131
is_subscribed: Boolean
3232
}
3333

0 commit comments

Comments
 (0)