/**
  * @param array|string $data
  *
  * @return \Pim\Component\Catalog\Model\ProductInterface
  *
  * @Given /^a "([^"]*)" product$/
  */
 public function createProduct($data)
 {
     if (is_string($data)) {
         $data = ['sku' => $data];
     } elseif (isset($data['enabled']) && in_array($data['enabled'], ['yes', 'no'])) {
         $data['enabled'] = $data['enabled'] === 'yes';
     }
     foreach ($data as $key => $value) {
         $data[$key] = $this->replacePlaceholders($value);
     }
     $converter = $this->getContainer()->get('pim_connector.array_converter.flat_to_standard.product');
     $processor = $this->getContainer()->get('pim_connector.processor.denormalization.product');
     $jobExecution = new JobExecution();
     $provider = new ProductCsvImport(new SimpleCsvExport([]), []);
     $params = $provider->getDefaultValues();
     $params['enabledComparison'] = false;
     $params['dateFormat'] = LocalizerInterface::DEFAULT_DATE_FORMAT;
     $params['decimalSeparator'] = LocalizerInterface::DEFAULT_DECIMAL_SEPARATOR;
     $jobParameters = new JobParameters($params);
     $jobExecution->setJobParameters($jobParameters);
     $stepExecution = new StepExecution('processor', $jobExecution);
     $processor->setStepExecution($stepExecution);
     $convertedData = $converter->convert($data);
     $product = $processor->process($convertedData);
     $this->getProductSaver()->save($product);
     // reset the unique value set to allow to update product values
     $uniqueValueSet = $this->getContainer()->get('pim_catalog.validator.unique_value_set');
     $uniqueValueSet->reset();
     $this->refresh($product);
     return $product;
 }
 /**
  * {@inheritdoc}
  */
 protected function setupWriter(JobExecution $jobExecution)
 {
     $fileKey = strtr($this->getRelativeArchivePath($jobExecution), ['%filename%' => 'invalid_items.xlsx']);
     $this->filesystem->put($fileKey, '');
     $writeParams = $this->defaultValuesProvider->getDefaultValues();
     $writeParams['filePath'] = $this->filesystem->getAdapter()->getPathPrefix() . $fileKey;
     $writeParams['withHeader'] = true;
     $writeJobParameters = new JobParameters($writeParams);
     $writeJobExecution = new JobExecution();
     $writeJobExecution->setJobParameters($writeJobParameters);
     $stepExecution = new StepExecution('processor', $writeJobExecution);
     $this->writer->setStepExecution($stepExecution);
     $this->writer->initialize();
 }
 /**
  * @return array
  */
 protected function readOrderedRawJobData()
 {
     $rawJobs = [];
     $fileLocator = $this->getFileLocator();
     foreach ($this->jobsFilePaths as $jobsFilePath) {
         $yamlReader = $this->getYamlReader();
         $realPath = $fileLocator->locate('@' . $jobsFilePath);
         $jobExecution = new JobExecution();
         $jobParameters = new JobParameters(['filePath' => $realPath]);
         $jobExecution->setJobParameters($jobParameters);
         $stepExecution = new StepExecution('reader', $jobExecution);
         $yamlReader->setStepExecution($stepExecution);
         while ($rawJob = $yamlReader->read()) {
             $rawJobs[] = $rawJob;
         }
         usort($rawJobs, function ($item1, $item2) {
             if ($item1['order'] === $item2['order']) {
                 return 0;
             }
             return $item1['order'] < $item2['order'] ? -1 : 1;
         });
     }
     return $rawJobs;
 }