Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function save($group, array $options = [])
 {
     /** @var GroupInterface */
     if (!$group instanceof GroupInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\GroupInterface", "%s" provided.', ClassUtils::getClass($group)));
     }
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->versionContext->addContextInfo(sprintf('Comes from variant group %s', $group->getCode()), $this->productClassName);
     $this->objectManager->persist($group);
     if (true === $options['flush']) {
         $this->objectManager->flush();
     }
     if (count($options['add_products']) > 0) {
         $this->addProducts($options['add_products']);
     }
     if (count($options['remove_products']) > 0) {
         $this->removeProducts($options['remove_products']);
     }
     if ($group->getType()->isVariant()) {
         $template = $group->getProductTemplate();
         if (null !== $template) {
             $this->templateMediaManager->handleProductTemplateMedia($template);
         }
     }
     if ($group->getType()->isVariant() && true === $options['copy_values_to_products']) {
         $this->copyVariantGroupValues($group);
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function save($channel, array $options = [])
 {
     if (!$channel instanceof ChannelInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\ChannelInterface", "%s" provided.', get_class($channel)));
     }
     $this->eventDispatcher->dispatch(StorageEvents::PRE_SAVE, new GenericEvent($channel));
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->objectManager->persist($channel);
     if (true === $options['flush']) {
         $this->objectManager->flush();
     }
     $this->eventDispatcher->dispatch(StorageEvents::POST_SAVE, new GenericEvent($channel));
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function save($channel, array $options = [])
 {
     if (!$channel instanceof ChannelInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\ChannelInterface", "%s" provided.', get_class($channel)));
     }
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->objectManager->persist($channel);
     if (true === $options['schedule']) {
         $this->completenessManager->scheduleForChannel($channel);
     }
     if (true === $options['flush']) {
         $this->objectManager->flush();
     }
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function save($family, array $options = [])
 {
     if (!$family instanceof FamilyInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\FamilyInterface", "%s" provided.', ClassUtils::getClass($family)));
     }
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->objectManager->persist($family);
     if (true === $options['flush']) {
         $this->objectManager->flush();
     }
     if (true === $options['schedule']) {
         $this->completenessManager->scheduleForFamily($family);
     }
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function saveAll(array $objects, array $options = [])
 {
     if (empty($objects)) {
         return;
     }
     $allOptions = $this->optionsResolver->resolveSaveAllOptions($options);
     $itemOptions = $allOptions;
     $itemOptions['flush'] = false;
     foreach ($objects as $object) {
         $this->save($object, $itemOptions);
     }
     if (true === $allOptions['flush']) {
         $this->objectManager->flush();
     }
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function saveAll(array $attributes, array $options = [])
 {
     if (empty($attributes)) {
         return;
     }
     $this->eventDispatcher->dispatch(AttributeEvents::PRE_SAVE_ALL, new GenericEvent($attributes));
     $allOptions = $this->optionsResolver->resolveSaveAllOptions($options);
     $itemOptions = $allOptions;
     $itemOptions['flush'] = false;
     foreach ($attributes as $attribute) {
         $this->save($attribute, $itemOptions);
     }
     if (true === $allOptions['flush']) {
         $this->objectManager->flush();
     }
     $this->eventDispatcher->dispatch(AttributeEvents::POST_SAVE_ALL, new GenericEvent($attributes));
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function saveAll(array $products, array $options = [])
 {
     if (empty($products)) {
         return;
     }
     $options = $this->optionsResolver->resolveSaveAllOptions($options);
     $this->eventDispatcher->dispatch(StorageEvents::PRE_SAVE_ALL, new GenericEvent($products, $options));
     $itemOptions = $options;
     $itemOptions['flush'] = false;
     foreach ($products as $product) {
         $this->save($product, $itemOptions);
     }
     if (true === $options['flush']) {
         $this->objectManager->flush();
     }
     $this->eventDispatcher->dispatch(StorageEvents::POST_SAVE_ALL, new GenericEvent($products, $options));
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function saveAll(array $groups, array $options = [])
 {
     if (empty($groups)) {
         return;
     }
     $this->eventDispatcher->dispatch(StorageEvents::PRE_SAVE_ALL, new GenericEvent($groups));
     $options = $this->optionsResolver->resolveSaveAllOptions($options);
     foreach ($groups as $group) {
         $this->validateGroup($group);
         $this->eventDispatcher->dispatch(StorageEvents::PRE_SAVE, new GenericEvent($group, $options));
         $this->persistGroup($group, $options);
     }
     $this->objectManager->flush();
     foreach ($groups as $group) {
         $this->eventDispatcher->dispatch(StorageEvents::POST_SAVE, new GenericEvent($group, $options));
     }
     $this->eventDispatcher->dispatch(StorageEvents::POST_SAVE_ALL, new GenericEvent($groups, $options));
 }