@@ -13,7 +13,7 @@ public function process($entity)
13
13
{
14
14
$ this ->assertEnvironment ($ entity );
15
15
16
- if ($ this ->checkExistingCustomer ()) {
16
+ if ($ this ->checkExistingCustomer ($ entity )) {
17
17
return null ;
18
18
}
19
19
@@ -29,19 +29,22 @@ public function process($entity)
29
29
}
30
30
31
31
/**
32
+ * @param Customer $entity
33
+ *
32
34
* @return Customer
33
35
*/
34
- protected function checkExistingCustomer ()
36
+ protected function checkExistingCustomer (Customer $ entity )
35
37
{
36
- $ itemData = $ this ->context ->getValue ('itemData ' );
37
- if (!array_key_exists ('customerEmail ' , $ itemData )) {
38
+ if (!$ entity ->getEmail ()) {
38
39
return null ;
39
40
}
40
41
41
- $ email = $ itemData ['customerEmail ' ];
42
42
$ existingCustomer = $ this ->databaseHelper ->findOneBy (
43
43
'OroCRM\Bundle\MagentoBundle\Entity\Customer ' ,
44
- ['email ' => $ email ]
44
+ [
45
+ 'email ' => $ entity ->getEmail (),
46
+ 'channel ' => $ entity ->getChannel ()
47
+ ]
45
48
);
46
49
47
50
return $ existingCustomer ;
@@ -62,63 +65,30 @@ protected function afterProcessEntity($entity)
62
65
*/
63
66
protected function processChangeAttributes (Customer $ entity )
64
67
{
65
- $ itemData = $ this ->context ->getValue ('itemData ' );
66
- $ entity ->setGuest (true );
67
- $ entity ->setConfirmed (false );
68
68
foreach ($ entity ->getAddresses () as $ address ) {
69
69
$ address ->setOriginId (null );
70
70
}
71
71
72
- $ em = $ this ->databaseHelper ->getRegistry ()->getManager ();
73
- if (!empty ($ itemData ['store ' ]['channel ' ]['id ' ])) {
74
- $ this ->setGroup ($ entity , $ itemData , $ em );
75
- $ this ->setWebsite ($ entity , $ itemData , $ em );
76
- }
77
-
78
- !empty ($ itemData ['customerEmail ' ]) && $ entity ->setEmail ($ itemData ['customerEmail ' ]);
79
- if (!empty ($ itemData ['addresses ' ])) {
80
- $ address = array_pop ($ itemData ['addresses ' ]);
81
- !empty ($ address ['firstName ' ]) && !$ entity ->getFirstName () && $ entity ->setFirstName ($ address ['firstName ' ]);
82
- !empty ($ address ['lastName ' ]) && !$ entity ->getLastName () && $ entity ->setLastName ($ address ['lastName ' ]);
83
- }
72
+ $ entity ->setWebsite ($ entity ->getStore ()->getWebsite ());
73
+ $ entity ->setCreatedIn ($ entity ->getStore ()->getName ());
74
+ $ this ->setDefaultGroup ($ entity );
84
75
}
85
76
86
77
/**
87
78
* @param Customer $entity
88
- * @param $itemData
89
- * @param $em
90
79
*/
91
- protected function setGroup (Customer $ entity, $ itemData , $ em )
80
+ protected function setDefaultGroup (Customer $ entity )
92
81
{
93
- if (array_key_exists ('customer_group_id ' , $ itemData ) && !$ entity ->getGroup ()) {
82
+ $ em = $ this ->databaseHelper ->getRegistry ()->getManager ();
83
+ if (!$ entity ->getGroup () && $ entity ->getWebsite ()->getDefaultGroupId ()) {
94
84
$ group = $ em ->getRepository ('OroCRMMagentoBundle:CustomerGroup ' )
95
85
->findOneBy (
96
86
[
97
- 'originId ' => $ itemData [ ' customer_group_id ' ] ,
98
- 'channel ' => $ itemData [ ' store ' ][ ' channel ' ][ ' id ' ]
87
+ 'originId ' => $ entity -> getWebsite ()-> getDefaultGroupId () ,
88
+ 'channel ' => $ entity -> getChannel ()
99
89
]
100
90
);
101
91
$ entity ->setGroup ($ group );
102
92
}
103
93
}
104
-
105
- /**
106
- * @param Customer $entity
107
- * @param $itemData
108
- * @param $em
109
- */
110
- protected function setWebsite (Customer $ entity , $ itemData , $ em )
111
- {
112
- if (!empty ($ itemData ['store ' ]['originId ' ])) {
113
- $ store = $ em ->getRepository ('OroCRMMagentoBundle:Store ' )
114
- ->findOneBy (
115
- [
116
- 'originId ' => $ itemData ['store ' ]['originId ' ],
117
- 'channel ' => $ itemData ['store ' ]['channel ' ]['id ' ]
118
- ]
119
- );
120
- $ entity ->setWebsite ($ store ->getWebsite ());
121
- $ entity ->setCreatedIn ($ store ->getName ());
122
- }
123
- }
124
94
}
0 commit comments