/**
  * 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->findOneById($id);
     if (!$product) {
         throw new NotFoundHttpException(sprintf('Product with id %s could not be found.', $id));
     }
     $this->productBuilder->addMissingAssociations($product);
     return $product;
 }
 /**
  * @param string $id Product id
  *
  * @throws NotFoundHttpException If product is not found or the user cannot see it
  *
  * @return JsonResponse
  */
 public function getAction($id)
 {
     $product = $this->findProductOr404($id);
     $this->productBuilder->addMissingAssociations($product);
     $channels = array_keys($this->userContext->getChannelChoicesWithUserChannel());
     $locales = $this->userContext->getUserLocaleCodes();
     return new JsonResponse($this->normalizer->normalize($product, 'internal_api', ['locales' => $locales, 'channels' => $channels, 'filter_type' => 'pim.internal_api.product_value.view']));
 }
 /**
  * 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 $this->createNotFoundException(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;
 }
 /**
  * @param string $id Product id
  *
  * @throws NotFoundHttpException If product is not found or the user cannot see it
  *
  * @return JsonResponse
  */
 public function getAction($id)
 {
     $product = $this->findProductOr404($id);
     $this->productBuilder->addMissingAssociations($product);
     return new JsonResponse($this->normalizer->normalize($product, 'internal_api', $this->buildContext()));
 }
 /**
  * Add missing associations (if association type has been added after the last processing)
  *
  * @param ProductInterface $product
  */
 protected function addMissingAssociations(ProductInterface $product)
 {
     $this->productBuilder->addMissingAssociations($product);
 }