/**
  * {@inheritdoc}
  */
 public function process($product)
 {
     $this->initSecurityContext($this->stepExecution);
     $this->productBuilder->addMissingProductValues($product);
     $parameters = $this->stepExecution->getJobParameters();
     $normalizerContext = $this->getNormalizerContext($parameters);
     $productStandard = $this->normalizer->normalize($product, 'json', $normalizerContext);
     if ($this->areAttributesToFilter($parameters)) {
         $productStandard = $this->filterProperties($productStandard, $parameters->get('selected_properties'));
     }
     if ($parameters->has('with_media') && $parameters->get('with_media')) {
         $directory = $this->stepExecution->getJobExecution()->getExecutionContext()->get(JobInterface::WORKING_DIRECTORY_PARAMETER);
         $this->fetchMedia($product, $directory);
     }
     $this->detacher->detach($product);
     return $productStandard;
 }
 /**
  * Find a product by its id or return a 404 response
  *
  * @param int $id the product id
  *
  * @throws NotFoundHttpException
  *
  * @return ProductInterface
  */
 protected function findProductOr404($id)
 {
     $product = $this->productRepository->findOneByWithValues($id);
     if (!$product) {
         throw new NotFoundHttpException(sprintf('Product with id %s could not be found.', (string) $id));
     }
     // With this version of the form we need to add missing values from family
     $this->productBuilder->addMissingProductValues($product);
     $this->productBuilder->addMissingAssociations($product);
     return $product;
 }
 /**
  * Build product values from template values raw data
  *
  * @param ProductTemplateInterface $template
  * @param AttributeInterface[]     $attributes
  * @param string                   $locale
  *
  * @return ProductValueInterface[]
  */
 protected function buildProductValuesFromTemplateValuesData(ProductTemplateInterface $template, array $attributes, $locale)
 {
     $options = ['locale' => $locale, 'disable_grouping_separator' => true];
     $values = $this->denormalizer->denormalize($template->getValuesData(), 'ProductValue[]', 'json', $options);
     $product = new $this->productClass();
     foreach ($values as $value) {
         $product->addValue($value);
     }
     foreach ($attributes as $attribute) {
         $this->productBuilder->addAttributeToProduct($product, $attribute);
     }
     $this->productBuilder->addMissingProductValues($product);
     return $product->getValues();
 }
 /**
  * {@inheritdoc}
  */
 public function process($product)
 {
     $parameters = $this->stepExecution->getJobParameters();
     $structure = $parameters->get('filters')['structure'];
     $channel = $this->channelRepository->findOneByIdentifier($structure['scope']);
     $this->productBuilder->addMissingProductValues($product, [$channel], $channel->getLocales()->toArray());
     $productStandard = $this->normalizer->normalize($product, 'json', ['channels' => [$channel->getCode()], 'locales' => array_intersect($channel->getLocaleCodes(), $parameters->get('filters')['structure']['locales'])]);
     if ($this->areAttributesToFilter($parameters)) {
         $attributesToFilter = $this->getAttributesToFilter($parameters);
         $productStandard['values'] = $this->filterValues($productStandard['values'], $attributesToFilter);
     }
     if ($parameters->has('with_media') && $parameters->get('with_media')) {
         $directory = $this->stepExecution->getJobExecution()->getExecutionContext()->get(JobInterface::WORKING_DIRECTORY_PARAMETER);
         $this->fetchMedia($product, $directory);
     } else {
         $mediaAttributes = $this->attributeRepository->findMediaAttributeCodes();
         $productStandard['values'] = array_filter($productStandard['values'], function ($attributeCode) use($mediaAttributes) {
             return !in_array($attributeCode, $mediaAttributes);
         }, ARRAY_FILTER_USE_KEY);
     }
     $this->detacher->detach($product);
     return $productStandard;
 }