/** * 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); $normalizationContext = $this->userContext->toArray() + ['filter_types' => ['pim.internal_api.product_value.view'], 'disable_grouping_separator' => true]; return new JsonResponse($this->normalizer->normalize($product, 'internal_api', $normalizationContext)); }
/** * 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; }
/** * 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); }
/** * @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())); }