/**
  * Finalize the operation
  */
 public function finalize()
 {
     if (null === $this->productSaver) {
         throw new \LogicException('Product saver must be configured');
     }
     $products = $this->getObjectsToMassEdit();
     $this->productSaver->saveAll($products, $this->getSavingOptions());
 }
 /**
  * {@inheritdoc}
  */
 public function apply(ProductTemplateInterface $template, array $products)
 {
     $this->templateUpdater->update($template, $products);
     $results = $this->validateProducts($products);
     $validProducts = $results['products'];
     $violations = $results['violations'];
     $this->productSaver->saveAll($validProducts);
     return $violations;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     $this->versionManager->setRealTimeVersioning($this->realTimeVersioning);
     foreach ($items as $item) {
         $this->incrementCount($item);
     }
     $this->productSaver->saveAll($items, ['recalculate' => false]);
     $this->cacheClearer->clear();
 }
 /**
  * {@inheritdoc}
  *
  * We need to save a default group because all attributes must have a group.
  *
  * For example, we want to remove the price attribute from the product information group. We must put it
  * in the default group so we make sure it is always saved
  */
 public function write(array $objects)
 {
     $this->incrementCount($objects);
     if (null !== ($defaultGroup = $this->attributeGroupRepository->findDefaultAttributeGroup())) {
         $objects[] = $defaultGroup;
     }
     $this->bulkSaver->saveAll($objects);
     $this->bulkDetacher->detachAll($objects);
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     $this->versionManager->setRealTimeVersioning($this->realTimeVersioning);
     foreach ($items as $item) {
         $this->incrementCount($item);
     }
     $this->mediaManager->handleAllProductsMedias($items);
     $this->productSaver->saveAll($items, ['recalculate' => false]);
     $this->detacher->detachAll($items);
 }
 /**
  * {@inheritdoc}
  */
 public function write(array $variantGroups)
 {
     $jobParameters = $this->stepExecution->getJobParameters();
     $isCopyValues = $jobParameters->get('copyValues');
     if ($isCopyValues) {
         $this->copyValuesToProducts($variantGroups);
     }
     $this->incrementCount($variantGroups);
     $this->bulkSaver->saveAll($variantGroups);
     $this->bulkDetacher->detachAll($variantGroups);
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     $jobParameters = $this->stepExecution->getJobParameters();
     $realTimeVersioning = $jobParameters->get('realTimeVersioning');
     $this->versionManager->setRealTimeVersioning($realTimeVersioning);
     foreach ($items as $item) {
         $this->incrementCount($item);
     }
     $this->productSaver->saveAll($items);
     $this->detacher->detachAll($items);
 }
 /**
  * Add attributes to a group
  *
  * @param AttributeGroupInterface $group
  * @param AttributeInterface[]    $attributes
  */
 public function addAttributes(AttributeGroupInterface $group, $attributes)
 {
     $maxOrder = $group->getMaxAttributeSortOrder();
     foreach ($attributes as $attribute) {
         $maxOrder++;
         $attribute->setSortOrder($maxOrder);
         $group->addAttribute($attribute);
     }
     $this->attributeSaver->saveAll($attributes);
     $this->groupSaver->save($group);
 }
 /**
  * Update attribute option sorting
  *
  * @param AttributeInterface $attribute
  * @param array              $sorting
  */
 public function updateSorting(AttributeInterface $attribute, array $sorting = [])
 {
     foreach ($attribute->getOptions() as $option) {
         if (isset($sorting[$option->getId()])) {
             $option->setSortOrder($sorting[$option->getId()]);
         } else {
             $option->setSortOrder(0);
         }
     }
     $this->optionSaver->saveAll($attribute->getOptions()->toArray());
 }
 /**
  * @param RemoveEvent $event
  */
 public function postRemove(RemoveEvent $event)
 {
     $subject = $event->getSubject();
     if (!$subject instanceof CategoryInterface) {
         return;
     }
     $productsToUpdate = [];
     foreach ($subject->getProducts() as $product) {
         $product->removeCategory($subject);
         $productsToUpdate[] = $product;
     }
     if (count($productsToUpdate) > 0) {
         $this->saver->saveAll($productsToUpdate);
     }
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function notify(NotificationInterface $notification, array $users)
 {
     $userNotifications = [];
     foreach ($users as $user) {
         try {
             $user = is_object($user) ? $user : $this->userProvider->loadUserByUsername($user);
             $userNotifications[] = $this->userNotifFactory->createUserNotification($notification, $user);
         } catch (UsernameNotFoundException $e) {
             continue;
         }
     }
     $this->notificationSaver->save($notification);
     $this->userNotifsSaver->saveAll($userNotifications);
     return $this;
 }
 /**
  * @param RemoveEvent $event
  */
 public function postRemove(RemoveEvent $event)
 {
     $subject = $event->getSubject();
     if (!$subject instanceof CategoryInterface) {
         return;
     }
     $productsToUpdate = [];
     foreach ($subject->getProducts() as $product) {
         $product->removeCategory($subject);
         $productsToUpdate[] = $product;
     }
     if (count($productsToUpdate) > 0) {
         $this->saver->saveAll($productsToUpdate, ['flush' => $event->getArgument('flush'), 'recalculate' => false, 'schedule' => false]);
     }
 }
 /**
  * @param GenericEvent $event
  */
 public function updateChannel(GenericEvent $event)
 {
     $channel = $event->getSubject();
     if (!$channel instanceof ChannelInterface) {
         return;
     }
     $oldLocales = $this->repository->getDeletedLocalesForChannel($channel);
     $newLocales = $channel->getLocales();
     $updatedLocales = [];
     foreach ($oldLocales as $locale) {
         $locale->removeChannel($channel);
         $updatedLocales[] = $locale;
         if (null !== $this->completeness) {
             $this->completeness->scheduleForChannelAndLocale($channel, $locale);
         }
     }
     foreach ($newLocales as $locale) {
         if (!$locale->hasChannel($channel)) {
             $locale->addChannel($channel);
             $updatedLocales[] = $locale;
         }
     }
     if (!empty($updatedLocales)) {
         $this->saver->saveAll($updatedLocales);
     }
 }
Ejemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function remove($category, array $options = [])
 {
     if (!$category instanceof CategoryInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "%s", "%s" provided.', 'Pim\\Bundle\\CatalogBundle\\Model\\CategoryInterface', ClassUtils::getClass($category)));
     }
     $options = $this->optionsResolver->resolveRemoveOptions($options);
     $eventName = $category->isRoot() ? CategoryEvents::PRE_REMOVE_TREE : CategoryEvents::PRE_REMOVE_CATEGORY;
     $this->eventDispatcher->dispatch($eventName, new GenericEvent($category));
     $productsToUpdate = [];
     foreach ($category->getProducts() as $product) {
         $product->removeCategory($category);
         $productsToUpdate[] = $product;
     }
     $this->objectManager->remove($category);
     if (true === $options['flush']) {
         $this->objectManager->flush();
     }
     if (count($productsToUpdate) > 0) {
         $this->productSaver->saveAll($productsToUpdate, ['flush' => $options['flush'], 'recalculate' => false, 'schedule' => false]);
     }
 }
 /**
  * Remove channel
  *
  * @param Request $request
  * @param Channel $channel
  *
  * @AclAncestor("pim_enrich_channel_remove")
  *
  * @return Response
  */
 public function removeAction(Request $request, Channel $channel)
 {
     $channelCount = $this->getRepository('PimCatalogBundle:Channel')->countAll();
     if ($channelCount <= 1) {
         throw new DeleteException($this->getTranslator()->trans('flash.channel.not removable'));
     }
     foreach ($channel->getLocales() as $locale) {
         $locale->removeChannel($channel);
     }
     $locales = $channel->getLocales() ? $channel->getLocales()->toArray() : [];
     $this->localeSaver->saveAll($locales);
     $this->channelRemover->remove($channel);
     if ($request->isXmlHttpRequest()) {
         return new Response('', 204);
     } else {
         return $this->redirect($this->generateUrl('pim_enrich_channel_index'));
     }
 }
 /**
  * Edit AttributeGroup sort order
  *
  * @param Request $request
  *
  * @AclAncestor("pim_enrich_attributegroup_sort")
  *
  * @return Response
  */
 public function sortAction(Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         return new RedirectResponse($this->router->generate('pim_enrich_attributegroup_create'));
     }
     $data = $request->request->all();
     if (!empty($data)) {
         $groups = [];
         foreach ($data as $id => $sort) {
             $group = $this->attributeGroupRepo->find((int) $id);
             if ($group) {
                 $group->setSortOrder((int) $sort);
                 $groups[] = $group;
             }
         }
         $this->attributeSaver->saveAll($groups);
         return new Response(1);
     }
     return new Response(0);
 }
 /**
  * Edit AttributeInterface sort order
  *
  * @param Request $request
  *
  * @AclAncestor("pim_enrich_attribute_sort")
  *
  * @return Response
  */
 public function sortAction(Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         return $this->redirectToRoute('pim_enrich_attribute_index');
     }
     $data = $request->request->all();
     if (!empty($data)) {
         $attributes = [];
         foreach ($data as $id => $sort) {
             $attribute = $this->attributeRepository->find((int) $id);
             if ($attribute) {
                 $attribute->setSortOrder((int) $sort);
                 $attributes[] = $attribute;
             }
         }
         $this->attributeSaver->saveAll($attributes);
         return new Response(1);
     }
     return new Response(0);
 }
Ejemplo n.º 18
0
 /**
  * Save associated products updated by the variant group update
  *
  * @param  GroupInterface $group
  */
 protected function saveAssociatedProducts(GroupInterface $group)
 {
     $productInGroup = $group->getProducts();
     $productsToUpdate = $productInGroup->toArray();
     $productToUpdateIds = array_map(function ($product) {
         return $product->getId();
     }, $productsToUpdate);
     if (null !== $group->getId()) {
         $pqb = $this->productQueryBuilderFactory->create();
         $pqb->addFilter('groups.id', Operators::IN_LIST, [$group->getId()]);
         $oldProducts = $pqb->execute();
         foreach ($oldProducts as $oldProduct) {
             if (!in_array($oldProduct->getId(), $productToUpdateIds)) {
                 $oldProduct->removeGroup($group);
                 $productsToUpdate[] = $oldProduct;
                 $productToUpdateIds[] = $oldProduct->getId();
             }
         }
     }
     if (!empty($productsToUpdate)) {
         $this->productSaver->saveAll($productsToUpdate);
     }
 }
 /**
  * Save multiple products
  *
  * @param ProductInterface[] $products The products to save
  * @param array              $options  Saving options
  *
  * @deprecated will be removed in 1.4, use saveAll()
  */
 public function saveAllProducts(array $products, array $options = [])
 {
     $this->productBulkSaver->saveAll($products, $options);
 }
 /**
  * {@inheritdoc}
  */
 public function write(array $objects)
 {
     $this->incrementCount($objects);
     $this->bulkSaver->saveAll($objects);
     $this->bulkDetacher->detachAll($objects);
 }
Ejemplo n.º 21
0
 /**
  * @param ProductInterface[] $products
  */
 protected function removeProducts(array $products)
 {
     $this->productSaver->saveAll($products, ['recalculate' => false, 'schedule' => false]);
 }