7
7
8
8
namespace Magento \CustomerGraphQl \Model \Customer ;
9
9
10
- use Magento \Customer \Api \CustomerRepositoryInterface ;
11
- use Magento \Framework \Exception \AlreadyExistsException ;
12
- use Magento \Framework \Exception \LocalizedException ;
13
10
use Magento \Framework \GraphQl \Exception \GraphQlAlreadyExistsException ;
14
11
use Magento \Framework \GraphQl \Exception \GraphQlAuthenticationException ;
15
12
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
23
20
class UpdateCustomerAccount
24
21
{
25
22
/**
26
- * @var CustomerRepositoryInterface
23
+ * @var SaveCustomer
27
24
*/
28
- private $ customerRepository ;
25
+ private $ saveCustomer ;
29
26
30
27
/**
31
28
* @var StoreManagerInterface
@@ -53,22 +50,22 @@ class UpdateCustomerAccount
53
50
private $ restrictedKeys ;
54
51
55
52
/**
56
- * @param CustomerRepositoryInterface $customerRepository
53
+ * @param SaveCustomer $saveCustomer
57
54
* @param StoreManagerInterface $storeManager
58
55
* @param CheckCustomerPassword $checkCustomerPassword
59
56
* @param DataObjectHelper $dataObjectHelper
60
57
* @param ChangeSubscriptionStatus $changeSubscriptionStatus
61
58
* @param array $restrictedKeys
62
59
*/
63
60
public function __construct (
64
- CustomerRepositoryInterface $ customerRepository ,
61
+ SaveCustomer $ saveCustomer ,
65
62
StoreManagerInterface $ storeManager ,
66
63
CheckCustomerPassword $ checkCustomerPassword ,
67
64
DataObjectHelper $ dataObjectHelper ,
68
65
ChangeSubscriptionStatus $ changeSubscriptionStatus ,
69
66
array $ restrictedKeys = []
70
67
) {
71
- $ this ->customerRepository = $ customerRepository ;
68
+ $ this ->saveCustomer = $ saveCustomer ;
72
69
$ this ->storeManager = $ storeManager ;
73
70
$ this ->checkCustomerPassword = $ checkCustomerPassword ;
74
71
$ this ->dataObjectHelper = $ dataObjectHelper ;
@@ -87,26 +84,6 @@ public function __construct(
87
84
* @throws GraphQlInputException
88
85
*/
89
86
public function execute (CustomerInterface $ customer , array $ data ): void
90
- {
91
- try {
92
- $ this ->updateCustomer ($ customer , $ data );
93
- } catch (LocalizedException $ e ) {
94
- throw new GraphQlInputException (__ ($ e ->getMessage ()));
95
- }
96
-
97
- if (isset ($ data ['is_subscribed ' ])) {
98
- $ this ->changeSubscriptionStatus ->execute ((int )$ customer ->getId (), (bool )$ data ['is_subscribed ' ]);
99
- }
100
- }
101
-
102
- /**
103
- * @param CustomerInterface $customer
104
- * @param array $data
105
- * @throws GraphQlAlreadyExistsException
106
- * @throws GraphQlAuthenticationException
107
- * @throws GraphQlInputException
108
- */
109
- private function updateCustomer (CustomerInterface $ customer , array $ data ): void
110
87
{
111
88
if (isset ($ data ['email ' ]) && $ customer ->getEmail () !== $ data ['email ' ]) {
112
89
if (!isset ($ data ['password ' ]) || empty ($ data ['password ' ])) {
@@ -122,15 +99,10 @@ private function updateCustomer(CustomerInterface $customer, array $data): void
122
99
123
100
$ customer ->setStoreId ($ this ->storeManager ->getStore ()->getId ());
124
101
125
- try {
126
- $ this ->customerRepository ->save ($ customer );
127
- } catch (AlreadyExistsException $ e ) {
128
- throw new GraphQlAlreadyExistsException (
129
- __ ('A customer with the same email address already exists in an associated website. ' ),
130
- $ e
131
- );
132
- } catch (LocalizedException $ e ) {
133
- throw new GraphQlInputException (__ ($ e ->getMessage ()), $ e );
102
+ $ this ->saveCustomer ->execute ($ customer );
103
+
104
+ if (isset ($ data ['is_subscribed ' ])) {
105
+ $ this ->changeSubscriptionStatus ->execute ((int )$ customer ->getId (), (bool )$ data ['is_subscribed ' ]);
134
106
}
135
107
}
136
108
}
0 commit comments