/**
  * Find a product by its id or return a 404 response
  *
  * @param string $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));
     }
     return $product;
 }
 /**
  * Inject current product in the datagrid configuration
  */
 protected function addCurrentProduct()
 {
     $path = $this->getSourcePath(self::CURRENT_PRODUCT_KEY);
     $id = $this->requestParams->get('product', null);
     $product = null !== $id ? $this->productRepository->findOneByWithValues($id) : null;
     $this->configuration->offsetSetByPath($path, $product);
 }
 /**
  * Find a product by its id or return a 404 response
  *
  * @param string $id the product id
  *
  * @throws NotFoundHttpException
  *
  * @return ProductInterface
  */
 protected function findProductOr404($id)
 {
     $product = $this->productRepository->findOneByWithValues($id);
     $product = $this->objectFilter->filterObject($product, 'pim.internal_api.product.view') ? null : $product;
     if (!$product) {
         throw new NotFoundHttpException(sprintf('Product with id %s could not be found.', $id));
     }
     return $product;
 }
 /**
  * @return ProductInterface
  */
 protected function getCurrentProduct()
 {
     $productId = $this->extractor->getDatagridParameter('product');
     if (!$productId) {
         throw new \LogicException('The current product type must be configured');
     }
     $product = $this->productRepository->findOneByWithValues($productId);
     return $product;
 }
 /**
  * Find previous sequential edit entity
  *
  * @param SequentialEdit $sequentialEdit
  * @param int            $currentKey
  *
  * @return null|ProductInterface
  */
 protected function findPrevious(SequentialEdit $sequentialEdit, $currentKey)
 {
     $previous = null;
     $objectSet = $sequentialEdit->getObjectSet();
     while ($currentKey-- > 0 && null === $previous) {
         $previous = $this->productRepository->findOneByWithValues($objectSet[$currentKey]);
     }
     return $previous;
 }
 /**
  * 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;
 }