/** * Displays completeness for a product * * @param int $id * * @return Response */ public function completenessAction($id) { $product = $this->productRepository->getFullProduct($id); $channels = $this->channelRepository->getFullChannels(); $locales = $this->userContext->getUserLocales(); $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $locales, $this->userContext->getCurrentLocale()->getCode()); return $this->templating->renderResponse('PimEnrichBundle:Completeness:_completeness.html.twig', ['product' => $product, 'channels' => $channels, 'locales' => $locales, 'completenesses' => $completenesses]); }
/** * {@inheritdoc} */ public function initialize() { $channel = $this->getConfiguredChannel(); if (null !== $channel && $this->generateCompleteness) { $this->completenessManager->generateMissingForChannel($channel); } $filters = $this->getConfiguredFilters(); $this->products = $this->getProductsCursor($filters, $channel); }
/** * {@inheritdoc} */ public function saveAll(array $families, array $options = []) { if (empty($families)) { return; } $this->eventDispatcher->dispatch(StorageEvents::PRE_SAVE_ALL, new GenericEvent($families, $options)); foreach ($families as $family) { $this->validateFamily($family); $this->eventDispatcher->dispatch(StorageEvents::PRE_SAVE, new GenericEvent($family, $options)); $this->objectManager->persist($family); $this->completenessManager->scheduleForFamily($family); } $this->objectManager->flush(); foreach ($families as $family) { $this->eventDispatcher->dispatch(StorageEvents::POST_SAVE, new GenericEvent($family, $options)); } $this->eventDispatcher->dispatch(StorageEvents::POST_SAVE_ALL, new GenericEvent($families, $options)); }
/** * 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)); }