/**
  * {@inheritdoc}
  */
 public function process($product)
 {
     $contextChannel = $this->channelManager->getChannelByCode($this->channel);
     $this->productBuilder->addMissingProductValues($product, [$contextChannel], $contextChannel->getLocales()->toArray());
     $data['media'] = [];
     $mediaValues = $this->getMediaProductValues($product);
     foreach ($mediaValues as $mediaValue) {
         $data['media'][] = $this->serializer->normalize($mediaValue->getMedia(), 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $mediaValue]);
     }
     $data['product'] = $this->serializer->normalize($product, 'flat', $this->getNormalizerContext());
     return $data;
 }
 /**
  * {@inheritdoc}
  */
 public function process($product)
 {
     if (null !== $this->productBuilder) {
         $this->productBuilder->addMissingProductValues($product);
     }
     $data['media'] = [];
     $productMedias = $this->getProductMedias($product);
     if (count($productMedias) > 0) {
         try {
             $data['media'] = $this->serializer->normalize($productMedias, 'flat', ['field_name' => 'media', 'prepare_copy' => true]);
         } catch (FileNotFoundException $e) {
             throw new InvalidItemException($e->getMessage(), ['item' => $product->getIdentifier()->getData(), 'uploadDirectory' => $this->uploadDirectory]);
         }
     }
     $data['product'] = $this->serializer->normalize($product, 'flat', $this->getNormalizerContext());
     return $data;
 }
 /**
  * Find a product by identifier
  * Also ensure that it contains all required values
  *
  * @param string $identifier
  *
  * @return ProductInterface|null
  */
 public function findByIdentifier($identifier)
 {
     $product = $this->getProductRepository()->findOneByIdentifier($identifier);
     if ($product) {
         $this->builder->addMissingProductValues($product);
     }
     return $product;
 }
 /**
  * Find a product by identifier
  * Also ensure that it contains all required values
  *
  * @param string $identifier
  *
  * @return Product|null
  */
 public function findByIdentifier($identifier)
 {
     $product = $this->getProductRepository()->findOneBy([['attribute' => $this->getIdentifierAttribute(), 'value' => $identifier]]);
     if ($product) {
         $this->builder->addMissingProductValues($product);
     }
     return $product;
 }
 /**
  * Build product values from template values raw data
  *
  * @param ProductTemplateInterface $template
  * @param AttributeInterface[]     $attributes
  *
  * @return ProductValueInterface[]
  */
 protected function buildProductValuesFromTemplateValuesData(ProductTemplateInterface $template, array $attributes)
 {
     $values = $this->denormalizer->denormalize($template->getValuesData(), 'ProductValue[]', 'json');
     $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();
 }
 /**
  * Build product values from template values raw data
  *
  * @param ProductTemplateInterface $template
  * @param AttributeInterface[]     $attributes
  *
  * @return ProductValueInterface[]
  */
 protected function buildProductValuesFromTemplateValuesData(ProductTemplateInterface $template, array $attributes)
 {
     $options = ['locale' => $this->localeResolver->getCurrentLocale(), '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();
 }