function it_updates_a_variant_group($attributeRepository, $groupTypeRepository, $productBuilder, GroupInterface $variantGroup, AttributeInterface $attribute, GroupTypeInterface $type, GroupTranslation $translatable, ProductInterface $product, ProductTemplateInterface $productTemplate)
 {
     $groupTypeRepository->findOneByIdentifier('VARIANT')->willReturn($type);
     $attributeRepository->findOneByIdentifier('main_color')->willReturn($attribute);
     $attributeRepository->findOneByIdentifier('secondary_color')->willReturn($attribute);
     $variantGroup->getTranslation()->willReturn($translatable);
     $translatable->setLabel('T-shirt super beau')->shouldBeCalled();
     $variantGroup->setCode('mycode')->shouldBeCalled();
     $variantGroup->setLocale('fr_FR')->shouldBeCalled();
     $variantGroup->setType($type)->shouldBeCalled();
     $variantGroup->getId()->willReturn(null);
     $variantGroup->addAxisAttribute(Argument::any())->shouldBeCalled();
     $productTemplate->getValuesData()->willReturn([]);
     $productTemplate->setValues(Argument::any())->shouldBeCalled();
     $productTemplate->setValuesData(['main_color' => [['locale' => null, 'scope' => null, 'data' => 'white']]])->shouldBeCalled();
     $variantGroup->getProductTemplate()->willReturn($productTemplate);
     $variantGroup->setProductTemplate($productTemplate)->shouldBeCalled();
     $productValue = new ProductValue();
     $identifierValue = new ProductValue();
     $productBuilder->createProduct()->willReturn($product);
     $product->getValues()->willReturn(new ArrayCollection([$productValue, $identifierValue]));
     $product->getIdentifier()->willReturn($identifierValue);
     $values = ['code' => 'mycode', 'axis' => ['main_color', 'secondary_color'], 'type' => 'VARIANT', 'labels' => ['fr_FR' => 'T-shirt super beau'], 'values' => ['main_color' => [['locale' => null, 'scope' => null, 'data' => 'white']]]];
     $this->update($variantGroup, $values, []);
 }
 /**
  * @param GroupInterface $group
  * @param array          $data
  */
 protected function setGroupType(GroupInterface $group, $data)
 {
     if (isset($data['type'])) {
         $typeCode = $data['type'];
         /** @var GroupType|null $type */
         $type = $this->groupTypeRepository->findOneByIdentifier($typeCode);
         if (!$type) {
             throw new \LogicException(sprintf('Group Type with identifier "%s" not found', $typeCode));
         }
         $group->setType($type);
     }
 }
 function it_updates_a_group($groupTypeRepository, GroupInterface $group, GroupTypeInterface $type, GroupTranslation $translatable)
 {
     $groupTypeRepository->findOneByIdentifier('RELATED')->willReturn($type);
     $group->getTranslation()->willReturn($translatable);
     $translatable->setLabel('T-shirt super beau')->shouldBeCalled();
     $group->setCode('mycode')->shouldBeCalled();
     $group->setLocale('fr_FR')->shouldBeCalled();
     $group->setType($type)->shouldBeCalled();
     $group->getId()->willReturn(null);
     $values = ['code' => 'mycode', 'type' => 'RELATED', 'labels' => ['fr_FR' => 'T-shirt super beau']];
     $this->update($group, $values, []);
 }
 function it_updates_a_group($groupTypeRepository, $attributeRepository, $pqbFactory, GroupInterface $group, GroupTypeInterface $type, GroupTranslation $translatable, AttributeInterface $attributeColor, AttributeInterface $attributeSize, ProductInterface $removedProduct, ProductInterface $addedProduct, ProductQueryBuilderInterface $pqb)
 {
     $groupTypeRepository->findOneByIdentifier('RELATED')->willReturn($type);
     $attributeRepository->findOneByIdentifier('color')->willReturn($attributeColor);
     $attributeRepository->findOneByIdentifier('size')->willReturn($attributeSize);
     $pqbFactory->create()->willReturn($pqb);
     $pqb->addFilter('id', 'IN', [2])->shouldBeCalled();
     $pqb->execute()->willReturn([$addedProduct]);
     $group->getTranslation()->willReturn($translatable);
     $translatable->setLabel('T-shirt super beau')->shouldBeCalled();
     $group->setCode('mycode')->shouldBeCalled();
     $group->setLocale('fr_FR')->shouldBeCalled();
     $group->setType($type)->shouldBeCalled();
     $group->setAxisAttributes([$attributeColor, $attributeSize])->shouldBeCalled();
     $group->getId()->willReturn(null);
     $group->removeProduct($removedProduct)->shouldBeCalled();
     $group->addProduct($addedProduct)->shouldBeCalled();
     $group->getProducts()->willReturn([$removedProduct]);
     $values = ['code' => 'mycode', 'type' => 'RELATED', 'labels' => ['fr_FR' => 'T-shirt super beau'], 'axis' => ['color', 'size'], 'products' => [2]];
     $this->update($group, $values, []);
 }
 function it_updates_an_empty_variant_group($groupTypeRepository, $productBuilder, $pqbFactory, GroupInterface $variantGroup, GroupTypeInterface $type, ProductInterface $product, ProductTemplateInterface $productTemplate)
 {
     $groupTypeRepository->findOneByIdentifier('VARIANT')->willReturn($type);
     $pqbFactory->create()->shouldNotBeCalled();
     $variantGroup->setCode('mycode')->shouldBeCalled();
     $variantGroup->setType($type)->shouldBeCalled();
     $variantGroup->setProductTemplate($productTemplate)->shouldBeCalled();
     $variantGroup->getId()->willReturn(null);
     $variantGroup->getProducts()->willReturn([]);
     $variantGroup->getProductTemplate()->willReturn($productTemplate);
     $productTemplate->getValuesData()->willReturn([]);
     $productTemplate->setValues(Argument::any())->shouldBeCalled();
     $productTemplate->setValuesData([])->shouldBeCalled();
     $productValue = new ProductValue();
     $identifierValue = new ProductValue();
     $productBuilder->createProduct()->willReturn($product);
     $product->getValues()->willReturn(new ArrayCollection([$productValue, $identifierValue]));
     $product->getIdentifier()->willReturn($identifierValue);
     $values = ['code' => 'mycode', 'axis' => [], 'type' => 'VARIANT', 'labels' => [], 'values' => [], 'products' => []];
     $this->update($variantGroup, $values, []);
 }
 /**
  * @param GroupInterface $group
  * @param string         $type
  *
  * @throws \InvalidArgumentException
  */
 protected function setType(GroupInterface $group, $type)
 {
     $groupType = $this->groupTypeRepository->findOneByIdentifier($type);
     if (null === $groupType) {
         throw new \InvalidArgumentException(sprintf('Type "%s" does not exist', $type));
     }
     if ($groupType->isVariant()) {
         throw new \InvalidArgumentException(sprintf('Cannot process variant group "%s", only groups are accepted', $group->getCode()));
     }
     $group->setType($groupType);
 }
 /**
  * @param GroupInterface $variantGroup
  * @param string         $type
  *
  * @throws \InvalidArgumentException
  */
 protected function setType(GroupInterface $variantGroup, $type)
 {
     $groupType = $this->groupTypeRepository->findOneByIdentifier($type);
     if (null !== $groupType) {
         $variantGroup->setType($groupType);
     } else {
         throw new \InvalidArgumentException(sprintf('Type "%s" does not exist', $type));
     }
 }