/**
  * Get completeness for a product
  *
  * @param int $id
  *
  * @return JSONResponse
  */
 public function getAction($id)
 {
     $product = $this->productRepository->getFullProduct($id);
     $this->completenessManager->generateMissingForProduct($product);
     $channels = $this->channelRepository->getFullChannels();
     $locales = $this->userContext->getUserLocales();
     $filteredLocales = $this->collectionFilter->filterCollection($locales, 'pim.internal_api.locale.view');
     $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $filteredLocales, $this->userContext->getCurrentLocale()->getCode());
     return new JsonResponse($this->completenessNormalizer->normalize($completenesses, 'internal_api'));
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function save($product, array $options = [])
 {
     if (!$product instanceof ProductInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a Pim\\Bundle\\CatalogBundle\\Model\\ProductInterface, "%s" provided', ClassUtils::getClass($product)));
     }
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->objectManager->persist($product);
     if (true === $options['schedule'] || true === $options['recalculate']) {
         $this->completenessManager->schedule($product);
     }
     if (true === $options['recalculate'] || true === $options['flush']) {
         $this->objectManager->flush();
     }
     if (true === $options['recalculate']) {
         $this->completenessManager->generateMissingForProduct($product);
     }
 }
 function it_does_not_flush_object_manager_when_persisting(ManagerRegistry $registry, ObjectManager $objectManager, CompletenessManager $completenessManager, ProductInterface $product)
 {
     $registry->getManagerForClass(get_class($product->getWrappedObject()))->willReturn($objectManager);
     $objectManager->persist($product)->shouldBeCalled();
     $objectManager->flush()->shouldNotBeCalled();
     $completenessManager->schedule($product)->shouldBeCalled();
     $completenessManager->generateMissingForProduct($product)->shouldNotBeCalled();
     $this->persist($product, ['recalculate' => false, 'flush' => false, 'schedule' => true]);
 }