/** * Get completeness for a product * * @param int|string $id * * @return JSONResponse */ public function getAction($id) { $product = $this->productRepository->getFullProduct($id); if (null === $product->getFamily()) { return new JsonResponse(); } $this->completenessManager->generateMissingForProduct($product); // Product have to be refreshed to have the completeness values generated by generateMissingForProduct() // (on ORM, completeness is not calculated the same way and product doesn't need to be refreshed) if (AkeneoStorageUtilsExtension::DOCTRINE_MONGODB_ODM === $this->storageDriver) { $this->productManager->refresh($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); return new JsonResponse($this->compNormalizer->normalize($completenesses, 'internal_api')); }
/** * {@inheritdoc} */ public function saveAll(array $products, array $options = []) { if (empty($products)) { return; } $this->eventDispatcher->dispatch(StorageEvents::PRE_SAVE_ALL, new GenericEvent($products, $options)); foreach ($products as $product) { $this->validateProduct($product); $this->eventDispatcher->dispatch(StorageEvents::PRE_SAVE, new GenericEvent($product, $options)); $this->completenessManager->schedule($product); $this->objectManager->persist($product); } $this->objectManager->flush(); foreach ($products as $product) { $this->completenessManager->generateMissingForProduct($product); $this->eventDispatcher->dispatch(StorageEvents::POST_SAVE, new GenericEvent($product, $options)); } $this->eventDispatcher->dispatch(StorageEvents::POST_SAVE_ALL, new GenericEvent($products, $options)); }