/**
  * {@inheritdoc}
  *
  * Converts flat csv array to standard structured array:
  *
  * Before:
  * [
  *      'code'                => 'pc_monitors',
  *      'label-en_US'         => 'PC Monitors',
  *      'label-fr_FR'         => 'Moniteurs',
  *      'attributes'          => 'sku,name,description,price',
  *      'attribute_as_label'  => 'name',
  *      'requirements-print'  => 'sku,name,description',
  *      'requirements-mobile' => 'sku,name',
  * ]
  *
  * After:
  * [
  *      'code'                => 'pc_monitors',
  *      'attributes'          => ['sku', 'name', 'description', 'price'],
  *      'attribute_as_label'  => 'name',
  *      'requirements' => [
  *          'mobile' => ['sku', 'name'],
  *          'print'  => ['sku', 'name', 'description'],
  *      ],
  *      'labels' => [
  *          'fr_FR' => 'Moniteurs',
  *          'en_US' => 'PC Monitors',
  *      ],
  * ]
  */
 public function convert(array $item, array $options = [])
 {
     $this->validator->validateFields($item, ['code']);
     $convertedItem = ['labels' => [], 'requirements' => []];
     foreach ($item as $field => $data) {
         $convertedItem = $this->convertField($convertedItem, $field, $data);
     }
     return $convertedItem;
 }
 /**
  * {@inheritdoc}
  *
  * Converts flat csv array to standard structured array:
  *
  * Before:
  * [
  *      'code'         => 'ecommerce',
  *      'label'        => 'Ecommerce',
  *      'locales'      => 'en_US,fr_FR',
  *      'currencies'   => 'EUR,USD',
  *      'tree'         => 'master_catalog',
  *      'color'        => 'orange'
  * ]
  *
  * After:
  * [
  *     'code'   => 'ecommerce',
  *     'label'  => 'Ecommerce',
  *     'locales'    => ['en_US', 'fr_FR'],
  *     'currencies' => ['EUR', 'USD'],
  *     'tree'       => 'master_catalog',
  *     'color'      => 'orange'
  * ]
  */
 public function convert(array $item, array $options = [])
 {
     $this->validator->validateFields($item, ['code', 'tree', 'locales', 'currencies']);
     $convertedItem = [];
     foreach ($item as $field => $data) {
         $convertedItem = $this->convertField($convertedItem, $field, $data);
     }
     return $convertedItem;
 }
 /**
  * {@inheritdoc}
  *
  * Converts flat csv array to standard structured array:
  */
 public function convert(array $item, array $options = [])
 {
     $this->validator->validateFields($item, ['code']);
     $convertedItem = ['labels' => []];
     foreach ($item as $field => $data) {
         $booleanFields = ['localizable', 'useable_as_grid_filter', 'unique', 'required', 'scopable', 'wysiwyg_enabled', 'decimals_allowed', 'negative_allowed'];
         $convertedItem = $this->convertFields($field, $booleanFields, $data, $convertedItem);
     }
     return $convertedItem;
 }
 /**
  * @param array $item
  *
  * @throws ArrayConversionException
  */
 protected function validate(array $item)
 {
     $requiredFields = ['attribute', 'code'];
     $this->validator->validateFields($item, $requiredFields, false);
     $authorizedFields = array_merge($requiredFields, ['sortOrder', 'labels']);
     foreach ($item as $field => $data) {
         if (!in_array($field, $authorizedFields)) {
             throw new ArrayConversionException(sprintf('Field "%s" is provided, authorized fields are: "%s"', $field, implode(', ', $authorizedFields)));
         }
     }
     if (isset($item['labels']) && !is_array($item['labels'])) {
         throw new ArrayConversionException(sprintf('Field "labels" must be an array, data provided is "%s"', print_r($item['labels'], true)));
     }
 }
 /**
  * @param array $item
  *
  * @throws ArrayConversionException
  */
 protected function validate(array $item)
 {
     $requiredFields = ['attribute', 'code'];
     $this->validator->validateFields($item, $requiredFields, false);
     $authorizedFields = array_merge($requiredFields, ['sort_order']);
     $localeCodes = $this->localeRepository->getActivatedLocaleCodes();
     foreach ($localeCodes as $code) {
         $authorizedFields[] = 'label-' . $code;
     }
     foreach ($item as $field => $data) {
         if (!in_array($field, $authorizedFields)) {
             throw new ArrayConversionException(sprintf('Field "%s" is provided, authorized fields are: "%s"', $field, implode(', ', $authorizedFields)));
         }
     }
 }
 /**
  * @param array $item
  * @param bool  $withRequiredSku
  *
  * @throws ArrayConversionException
  */
 protected function validateItem(array $item, $withRequiredSku)
 {
     $requiredFields = $withRequiredSku ? [$this->attrColumnsResolver->resolveIdentifierField()] : [];
     $this->validator->validateFields($item, $requiredFields, false);
     $this->validateOptionalFields($item);
     $this->validateFieldValueTypes($item);
 }
 /**
  * @param array $item
  */
 protected function validate(array $item)
 {
     $this->validator->validateFields($item, ['code', 'type']);
     $this->validateAuthorizedFields($item, ['type', 'code']);
 }