@@ -58,6 +58,9 @@ class Data
58
58
const ENTITY_TYPE_CUSTOMER_CODE = 'customer ' ;
59
59
const ENTITY_TYPE_CUSTOMER_ADDRESS_CODE = 'customer_address ' ;
60
60
61
+ const TYPE_SOURCE = 'source ' ;
62
+ const TYPE_DEST = 'destination ' ;
63
+
61
64
/**
62
65
* @param Source $source
63
66
* @param Destination $destination
@@ -105,19 +108,20 @@ public function updateMappedKeys($destDocument, $column, $records, $mappedIdKeys
105
108
}
106
109
107
110
/**
108
- * Get list of attribute sets depending on entity type
111
+ * Get list of product attribute sets
109
112
*
110
- * @param null|int $entityTypeId
111
113
* @param string $mode
114
+ * @param string $type
112
115
* @return array|mixed
113
116
*/
114
- public function getAttributeSets ($ entityTypeId = null , $ mode = self ::ATTRIBUTE_SETS_ALL )
115
- {
117
+ public function getProductAttributeSets (
118
+ $ mode = self ::ATTRIBUTE_SETS_ALL ,
119
+ $ type = self ::TYPE_SOURCE
120
+ ) {
121
+ $ productEntityTypeId = $ this ->getEntityTypeIdByCode (self ::ENTITY_TYPE_PRODUCT_CODE , $ type );
116
122
$ attributeSets = [];
117
- foreach ($ this ->initialData ->getAttributeSets ('source ' ) as $ attributeSet ) {
118
- if ($ entityTypeId === null
119
- || $ entityTypeId == $ attributeSet ['entity_type_id ' ]
120
- ) {
123
+ foreach ($ this ->initialData ->getAttributeSets ($ type ) as $ attributeSet ) {
124
+ if ($ productEntityTypeId == $ attributeSet ['entity_type_id ' ]) {
121
125
$ attributeSets [$ attributeSet ['attribute_set_id ' ]] = $ attributeSet ;
122
126
}
123
127
}
@@ -133,13 +137,14 @@ public function getAttributeSets($entityTypeId = null, $mode = self::ATTRIBUTE_S
133
137
/**
134
138
* Return entity type id by its code
135
139
*
136
- * @param $code
140
+ * @param string $code
141
+ * @param string $type
137
142
* @return mixed|null
138
143
*/
139
- public function getEntityTypeIdByCode ($ code )
144
+ public function getEntityTypeIdByCode ($ code, $ type = self :: TYPE_SOURCE )
140
145
{
141
146
$ entityTypeId = null ;
142
- foreach ($ this ->initialData ->getEntityTypes (' source ' ) as $ entityType ) {
147
+ foreach ($ this ->initialData ->getEntityTypes ($ type ) as $ entityType ) {
143
148
if ($ entityType ['entity_type_code ' ] == $ code ) {
144
149
$ entityTypeId = $ entityType ['entity_type_id ' ];
145
150
}
@@ -154,12 +159,12 @@ public function getEntityTypeIdByCode($code)
154
159
*/
155
160
public function getDefaultProductAttributeGroups ()
156
161
{
157
- $ defaultProductAttributeSetId = $ this ->getAttributeSets (
158
- $ this -> getEntityTypeIdByCode ( self ::ENTITY_TYPE_PRODUCT_CODE ) ,
159
- self ::ATTRIBUTE_SETS_DEFAULT
162
+ $ defaultProductAttributeSetId = $ this ->getProductAttributeSets (
163
+ self ::ATTRIBUTE_SETS_DEFAULT ,
164
+ self ::TYPE_DEST
160
165
)['attribute_set_id ' ];
161
166
$ attributeGroups = [];
162
- foreach ($ this ->initialData ->getAttributeGroups (' dest ' ) as $ attributeGroup ) {
167
+ foreach ($ this ->initialData ->getAttributeGroups (self :: TYPE_DEST ) as $ attributeGroup ) {
163
168
if ($ attributeGroup ['attribute_set_id ' ] == $ defaultProductAttributeSetId ) {
164
169
$ attributeGroup ['attribute_group_id ' ] = null ;
165
170
$ attributeGroup ['attribute_set_id ' ] = null ;
@@ -176,12 +181,12 @@ public function getDefaultProductAttributeGroups()
176
181
*/
177
182
public function getDefaultProductEntityAttributes ()
178
183
{
179
- $ defaultProductAttributeSetId = $ this ->getAttributeSets (
180
- $ this -> getEntityTypeIdByCode ( self ::ENTITY_TYPE_PRODUCT_CODE ) ,
181
- self ::ATTRIBUTE_SETS_DEFAULT
184
+ $ defaultProductAttributeSetId = $ this ->getProductAttributeSets (
185
+ self ::ATTRIBUTE_SETS_DEFAULT ,
186
+ self ::TYPE_DEST
182
187
)['attribute_set_id ' ];
183
188
$ entityAttributes = [];
184
- foreach ($ this ->initialData ->getEntityAttributes (' dest ' ) as $ entityAttribute ) {
189
+ foreach ($ this ->initialData ->getEntityAttributes (self :: TYPE_DEST ) as $ entityAttribute ) {
185
190
if ($ entityAttribute ['attribute_set_id ' ] == $ defaultProductAttributeSetId ) {
186
191
$ entityAttribute ['entity_attribute_id ' ] = null ;
187
192
$ entityAttribute ['attribute_set_id ' ] = null ;
@@ -221,7 +226,7 @@ public function getAttributeGroupIdForAttributeSet($prototypeAttributeGroupId, $
221
226
public function getDestAttributeGroupCodeFromId ($ attributeGroupId )
222
227
{
223
228
$ attributeGroupCode = null ;
224
- foreach ($ this ->initialData ->getAttributeGroups (' dest ' ) as $ attributeGroup ) {
229
+ foreach ($ this ->initialData ->getAttributeGroups (self :: TYPE_DEST ) as $ attributeGroup ) {
225
230
if ($ attributeGroup ['attribute_group_id ' ] == $ attributeGroupId ) {
226
231
$ attributeGroupCode = $ attributeGroup ['attribute_group_code ' ];
227
232
}
@@ -238,7 +243,7 @@ public function getDestAttributeGroupCodeFromId($attributeGroupId)
238
243
public function getSourceAttributeGroupNameFromId ($ attributeGroupId )
239
244
{
240
245
$ attributeGroupName = null ;
241
- foreach ($ this ->initialData ->getAttributeGroups (' source ' ) as $ attributeGroup ) {
246
+ foreach ($ this ->initialData ->getAttributeGroups (self :: TYPE_SOURCE ) as $ attributeGroup ) {
242
247
if ($ attributeGroup ['attribute_group_id ' ] == $ attributeGroupId ) {
243
248
$ attributeGroupName = $ attributeGroup ['attribute_group_name ' ];
244
249
}
@@ -278,14 +283,22 @@ public function getCustomProductAttributeGroups($attributeSetId)
278
283
public function getCustomAttributeIds ()
279
284
{
280
285
$ defaultAttributes = [];
281
- foreach ($ this ->initialData ->getAttributes ('dest ' ) as $ id => $ attribute ) {
282
- $ defaultAttributes [$ id ] = $ attribute ['attribute_code ' ] . '- ' . $ attribute ['entity_type_id ' ];
286
+ $ entityTypesSource = $ this ->initialData ->getEntityTypes (self ::TYPE_SOURCE );
287
+ $ entityTypesDest = $ this ->initialData ->getEntityTypes (self ::TYPE_DEST );
288
+ foreach ($ this ->initialData ->getAttributes (self ::TYPE_DEST ) as $ id => $ attribute ) {
289
+ $ defaultAttributes [$ id ] =
290
+ $ entityTypesDest [$ attribute ['entity_type_id ' ]]['entity_type_code ' ]
291
+ . '-- '
292
+ . $ attribute ['attribute_code ' ];
283
293
}
284
294
$ sourceAttributes = $ this ->ignoredAttributes ->clearIgnoredAttributes (
285
- $ this ->initialData ->getAttributes (' source ' )
295
+ $ this ->initialData ->getAttributes (self :: TYPE_SOURCE )
286
296
);
287
297
foreach ($ sourceAttributes as $ id => $ attribute ) {
288
- $ sourceAttributes [$ id ] = $ attribute ['attribute_code ' ] . '- ' . $ attribute ['entity_type_id ' ];
298
+ $ sourceAttributes [$ id ] =
299
+ $ entityTypesSource [$ attribute ['entity_type_id ' ]]['entity_type_code ' ]
300
+ . '-- '
301
+ . $ attribute ['attribute_code ' ];
289
302
}
290
303
return array_keys (array_diff ($ sourceAttributes , $ defaultAttributes ));
291
304
}
0 commit comments