コード例 #1
0
 /**
  * {@inheritdoc}
  *
  * Convert flat array to structured array:
  *
  * Before:
  * [
  *     'code': 'mycode',
  *     'axis': 'main_color,'secondary_color'
  *     'label-fr_FR': 'T-shirt super beau',
  *     'label-en_US': 'T-shirt very beautiful',
  *     'type': 'VARIANT',
  *     'main_color': 'white',
  *     'tshirt_style': 'turtleneck,sportwear',
  *     'description-fr_FR-ecommerce': '<p>description</p>'
  *     'description-en_US-ecommerce': '<p>description</p>'
  * ]
  *
  * After:
  * {
  *     "code": "mycode",
  *     "labels": {
  *         "en_US": "T-shirt very beautiful",
  *         "fr_FR": "T-shirt super beau"
  *     }
  *     "axis": ["main_color", "secondary_color"],
  *     "type": "VARIANT",
  *     "values": {
  *         "main_color": "white",
  *         "tshirt_style": ["turtleneck","sportwear"],
  *         "description": [
  *              {
  *                  "locale": "fr_FR",
  *                  "scope": "ecommerce",
  *                  "data": "<p>description</p>",
  *              },
  *              {
  *                  "locale": "en_US",
  *                  "scope": "ecommerce",
  *                  "data": "<p>description</p>",
  *              }
  *          ]
  *     }
  * }
  */
 public function convert(array $item, array $options = [])
 {
     $this->validate($item);
     $convertedItem = ['labels' => []];
     foreach ($item as $field => $data) {
         if ('' !== $data) {
             $convertedItem = $this->convertField($convertedItem, $field, $data);
         }
     }
     if (isset($convertedItem['values'])) {
         $convertedItem['values'] = $this->productConverter->convert($convertedItem['values'], ['with_required_identifier' => false]);
         unset($convertedItem['values']['enabled']);
     }
     return $convertedItem;
 }
 /**
  * {@inheritdoc}
  *
  * Convert flat array to structured array by keeping only identifier and associations
  *
  * 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",
  *      }],
  *      "associations": {
  *          "XSELL": {
  *              "groups": ["akeneo_tshirt", "oro_tshirt"],
  *              "products": ["AKN_TS", "ORO_TSH"]
  *          }
  *      }
  * }
  */
 public function convert(array $item, array $options = [])
 {
     $convertedItem = $this->productConverter->convert($item, $options);
     $filteredItem = $this->filter($convertedItem);
     return $filteredItem;
 }