/** * @param array $item * * @return array */ protected function convertItem(array $item) { $convertedItem = []; foreach ($item as $column => $value) { if ($this->fieldConverter->supportsColumn($column)) { $value = $this->fieldConverter->convert($column, $value); } else { $value = $this->convertValue($column, $value); } if (null !== $value) { $convertedItem = $this->mergeValueToResult($convertedItem, $value); } } return $convertedItem; }
/** * {@inheritdoc} * * Convert flat array to structured array: * * Before: * [ * 'sku': 'MySku', * 'name-fr_FR': 'T-shirt super beau', * 'description-en_US-mobile': 'My description', * 'price': '10 EUR, 24 USD', * 'price-CHF': '20', * 'length': '10 CENTIMETER', * 'enabled': '1', * 'categories': 'tshirt,men' * 'XSELL-groups': 'akeneo_tshirt, oro_tshirt', * 'XSELL-product': 'AKN_TS, ORO_TSH' * ] * * After: * { * "sku": [{ * "locale": null, * "scope": null, * "data": "MySku", * }], * "name": [{ * "locale": "fr_FR", * "scope": null, * "data": "T-shirt super beau", * }], * "description": [ * { * "locale": "en_US", * "scope": "mobile", * "data": "My description" * }, * { * "locale": "fr_FR", * "scope": "mobile", * "data": "Ma description mobile" * }, * { * "locale": "en_US", * "scope": "ecommerce", * "data": "My description for the website" * }, * ], * "price": [ * { * "locale": null, * "scope": ecommerce, * "data": [ * {"data": 10, "currency": "EUR"}, * {"data": 24, "currency": "USD"}, * {"data": 20, "currency": "CHF"} * ] * } * { * "locale": null, * "scope": mobile, * "data": [ * {"data": 11, "currency": "EUR"}, * {"data": 25, "currency": "USD"}, * {"data": 21, "currency": "CHF"} * ] * } * ], * "length": [{ * "locale": "en_US", * "scope": "mobile", * "data": {"data": "10", "unit": "CENTIMETER"} * }], * "enabled": true, * "categories": ["tshirt", "men"], * "associations": { * "XSELL": { * "groups": ["akeneo_tshirt", "oro_tshirt"], * "products": ["AKN_TS", "ORO_TSH"] * } * } * } */ public function convert(array $item, array $options = []) { $mappedItem = $item; if (isset($options['mapping'])) { $mappedItem = $this->columnsMapper->map($item, $options['mapping']); } $resolvedItem = $this->resolveConverterOptions($mappedItem, $options); $mergedItems = $this->columnsMerger->merge($resolvedItem); $result = []; foreach ($mergedItems as $column => $value) { if ($this->fieldConverter->supportsColumn($column)) { $value = $this->fieldConverter->convert($column, $value); } else { $value = $this->convertValue($column, $value); } if (null !== $value) { $result = $this->mergeValueToResult($result, $value); } } return $result; }