@@ -17,27 +17,27 @@ class Helper
17
17
/**
18
18
* @var Source
19
19
*/
20
- protected $ source ;
20
+ private $ source ;
21
21
22
22
/**
23
23
* @var Destination
24
24
*/
25
- protected $ destination ;
25
+ private $ destination ;
26
26
27
27
/**
28
28
* @var string
29
29
*/
30
- protected $ eavEntityStore = 'eav_entity_store ' ;
30
+ private $ eavEntityStoreTable = 'eav_entity_store ' ;
31
31
32
32
/**
33
33
* @var string
34
34
*/
35
- protected $ storeTable = 'core_store ' ;
35
+ private $ storeTable = 'core_store ' ;
36
36
37
37
/**
38
38
* @var array
39
39
*/
40
- protected $ sequenceMetaTable = [
40
+ private $ sequenceMetaTable = [
41
41
'name ' => 'sales_sequence_meta ' ,
42
42
'structure ' => [
43
43
'meta_id ' ,
@@ -50,7 +50,7 @@ class Helper
50
50
/**
51
51
* @var array
52
52
*/
53
- protected $ sequenceProfileTable = [
53
+ private $ sequenceProfileTable = [
54
54
'name ' => 'sales_sequence_profile ' ,
55
55
'structure ' => [
56
56
'profile_id ' ,
@@ -68,7 +68,7 @@ class Helper
68
68
/**
69
69
* @var array
70
70
*/
71
- protected $ entityTypeTablesMap = [
71
+ private $ entityTypeTablesMap = [
72
72
[
73
73
'entity_type_code ' => 'order ' ,
74
74
'entity_type_table ' => 'sequence_order ' ,
@@ -106,24 +106,48 @@ public function __construct(
106
106
107
107
/**
108
108
* @param int $entityTypeId
109
+ * @param int $storeId
109
110
* @return bool|int
110
111
*/
111
- public function getMaxIncrementForEntityType ($ entityTypeId )
112
+ public function getMaxIncrementForEntityType ($ entityTypeId, $ storeId )
112
113
{
113
114
/** @var \Migration\ResourceModel\Adapter\Mysql $adapter */
114
115
$ adapter = $ this ->source ->getAdapter ();
115
116
$ query = $ adapter ->getSelect ()->from (
116
- $ this ->source ->addDocumentPrefix ($ this ->eavEntityStore ),
117
+ $ this ->source ->addDocumentPrefix ($ this ->eavEntityStoreTable ),
117
118
['increment_prefix ' , 'increment_last_id ' ]
118
- )->where ('entity_type_id = ? ' , $ entityTypeId );
119
+ )->where ('entity_type_id = ? ' , $ entityTypeId
120
+ )->where ('store_id IN (?) ' , $ this ->getStoreIdsOfStoreGroup ($ storeId ));
119
121
$ data = $ query ->getAdapter ()->fetchAll ($ query );
120
122
if (!$ data ) {
121
123
return false ;
122
124
}
123
125
$ cutPrefixFunction = function (array $ data ) {
124
126
return (int ) substr ($ data ['increment_last_id ' ], strlen ($ data ['increment_prefix ' ]));
125
127
};
126
- return max (array_map ($ cutPrefixFunction , $ data ));
128
+ $ maxIncrement = max (array_map ($ cutPrefixFunction , $ data ));
129
+ return $ maxIncrement ;
130
+ }
131
+
132
+ /**
133
+ * Return store ids of store group
134
+ *
135
+ * @param $storeId
136
+ * @return array
137
+ */
138
+ public function getStoreIdsOfStoreGroup ($ storeId )
139
+ {
140
+ /** @var \Migration\ResourceModel\Adapter\Mysql $adapter */
141
+ $ adapter = $ this ->source ->getAdapter ();
142
+ $ select = $ adapter ->getSelect ()->from (
143
+ ['cs ' => $ this ->source ->addDocumentPrefix ($ this ->storeTable )],
144
+ ['store_id ' ]
145
+ )->join (
146
+ ['css ' => $ this ->source ->addDocumentPrefix ($ this ->storeTable )],
147
+ 'css.group_id = cs.group_id ' ,
148
+ []
149
+ )->where ('css.store_id = ? ' , $ storeId );
150
+ return $ select ->getAdapter ()->fetchCol ($ select );
127
151
}
128
152
129
153
/**
@@ -200,7 +224,7 @@ public function getTableName($table, $storeId = false)
200
224
* @param array $entityTypeCodes
201
225
* @return array
202
226
*/
203
- protected function getEntityTypeIdByCode ($ entityTypeCodes )
227
+ private function getEntityTypeIdByCode ($ entityTypeCodes )
204
228
{
205
229
/** @var Mysql $adapter */
206
230
$ adapter = $ this ->destination ->getAdapter ();
0 commit comments