/**
  * {@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)));
     }
     $this->eventDispatcher->dispatch(GroupEvents::PRE_SAVE, new GenericEvent($group));
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->versionContext->addContextInfo(sprintf('Comes from variant group %s', $group->getCode()), $this->productClassName);
     if ($group->getType()->isVariant()) {
         $template = $group->getProductTemplate();
         if (null !== $template) {
             $this->templateMediaManager->handleProductTemplateMedia($template);
         }
     }
     $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() && true === $options['copy_values_to_products']) {
         $this->copyVariantGroupValues($group);
     }
     $this->eventDispatcher->dispatch(GroupEvents::POST_SAVE, new GenericEvent($group));
 }
 /**
  * Add context in version manager
  *
  * @param JobExecutionEvent $event
  */
 public function addContext(JobExecutionEvent $event)
 {
     $jobInstance = $event->getJobExecution()->getJobInstance();
     if ($jobInstance->getType() === JobInstance::TYPE_IMPORT) {
         $this->versionContext->addContextInfo(sprintf('%s "%s"', JobInstance::TYPE_IMPORT, $jobInstance->getCode()));
     }
 }
 /**
  * @param       $group
  * @param array $options
  */
 protected function persistGroup($group, array $options)
 {
     $context = $this->productClassName;
     $this->versionContext->addContextInfo(sprintf('Comes from variant group %s', $group->getCode()), $context);
     if ($group->getType()->isVariant()) {
         $template = $group->getProductTemplate();
         if (null !== $template) {
             $this->templateMediaManager->handleProductTemplateMedia($template);
         }
     }
     $this->objectManager->persist($group);
     $this->saveAssociatedProducts($group);
     if ($group->getType()->isVariant() && true === $options['copy_values_to_products']) {
         $this->copyVariantGroupValues($group);
         $this->detacher->detachAll($group->getProducts()->toArray());
     }
     $this->versionContext->unsetContextInfo($context);
 }