function it_normalize_products($productNormalizer, $versionNormalizer, $versionManager, $localeRepository, $structureVersionProvider, $formProvider, $localizedConverter, ProductInterface $mug, AssociationInterface $upsell, AssociationTypeInterface $groupType, GroupInterface $group, ArrayCollection $groups)
 {
     $options = ['decimal_separator' => ',', 'date_format' => 'dd/MM/yyyy'];
     $productNormalized = ['enabled' => true, 'categories' => ['kitchen'], 'family' => '', 'values' => ['normalized_property' => ['data' => 'a nice normalized property', 'locale' => null, 'scope' => null], 'number' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'metric' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'prices' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'date' => ['data' => '2015-01-31', 'locale' => null, 'scope' => null]]];
     $valuesLocalized = ['normalized_property' => ['data' => 'a nice normalized property', 'locale' => null, 'scope' => null], 'number' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'metric' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'prices' => ['data' => '12,5', 'locale' => null, 'scope' => null], 'date' => ['data' => '31/01/2015', 'locale' => null, 'scope' => null]];
     $productNormalizer->normalize($mug, 'json', $options)->willReturn($productNormalized);
     $localizedConverter->convertToLocalizedFormats($productNormalized['values'], $options)->willReturn($valuesLocalized);
     $mug->getId()->willReturn(12);
     $versionManager->getOldestLogEntry($mug)->willReturn('create_version');
     $versionNormalizer->normalize('create_version', 'internal_api')->willReturn('normalized_create_version');
     $versionManager->getNewestLogEntry($mug)->willReturn('update_version');
     $versionNormalizer->normalize('update_version', 'internal_api')->willReturn('normalized_update_version');
     $localeRepository->getActivatedLocaleCodes()->willReturn(['en_US', 'fr_FR']);
     $mug->getLabel('en_US')->willReturn('A nice Mug!');
     $mug->getLabel('fr_FR')->willReturn('Un très beau Mug !');
     $mug->getAssociations()->willReturn([$upsell]);
     $upsell->getAssociationType()->willReturn($groupType);
     $groupType->getCode()->willReturn('group');
     $upsell->getGroups()->willReturn($groups);
     $groups->toArray()->willReturn([$group]);
     $group->getId()->willReturn(12);
     $structureVersionProvider->getStructureVersion()->willReturn(12);
     $formProvider->getForm($mug)->willReturn('product-edit-form');
     $this->normalize($mug, 'internal_api', $options)->shouldReturn(['enabled' => true, 'categories' => ['kitchen'], 'family' => '', 'values' => $valuesLocalized, 'meta' => ['form' => 'product-edit-form', 'id' => 12, 'created' => 'normalized_create_version', 'updated' => 'normalized_update_version', 'model_type' => 'product', 'structure_version' => 12, 'label' => ['en_US' => 'A nice Mug!', 'fr_FR' => 'Un très beau Mug !'], 'associations' => ['group' => ['groupIds' => [12]]]]]);
 }
 function it_massively_insert_and_update_objects($bulkSaver, $bulkDetacher, $stepExecution, ProductInterface $product1, ProductInterface $product2, AssociationInterface $association2)
 {
     $bulkSaver->saveAll([$product1, $product2]);
     $bulkDetacher->detachAll([$product1, $product2]);
     $product1->getId()->willReturn(null);
     $association1 = new Association();
     $product1->getAssociations()->willReturn(new ArrayCollection([$association1]));
     $stepExecution->incrementSummaryInfo('process')->shouldBeCalled();
     $product2->getId()->willReturn(42);
     $association2->getId()->willReturn(1);
     $product2->getAssociations()->willReturn(new ArrayCollection([$association2]));
     $stepExecution->incrementSummaryInfo('process')->shouldBeCalled();
     $this->write([$product1, $product2]);
 }
 function it_normalizes_a_product_associations_in_standard_format_only(ProductInterface $product, AssociationInterface $association1, AssociationInterface $association2, AssociationTypeInterface $associationType1, AssociationTypeInterface $associationType2, GroupInterface $group1, ProductInterface $productAssociated)
 {
     $group1->getCode()->willReturn('group_code');
     $associationType1->getCode()->willReturn('XSELL');
     $association1->getAssociationType()->willReturn($associationType1);
     $association1->getGroups()->willReturn([$group1]);
     $association1->getProducts()->willReturn([]);
     $productAssociated->getReference()->willReturn('product_code');
     $associationType2->getCode()->willReturn('PACK');
     $association2->getAssociationType()->willReturn($associationType2);
     $association2->getGroups()->willReturn([]);
     $association2->getProducts()->willReturn([$productAssociated]);
     $product->getAssociations()->willReturn([$association1, $association2]);
     $this->normalize($product, 'standard')->shouldReturn(['PACK' => ['groups' => [], 'products' => ['product_code']], 'XSELL' => ['groups' => ['group_code'], 'products' => []]]);
 }
 function it_saves_associations($registry, AssociationInterface $association1, AssociationInterface $association2, ProductInterface $product1, ProductInterface $product2, GroupInterface $group1, GroupInterface $group2, ObjectManager $manager)
 {
     $registry->getManagerForClass(Argument::any())->willReturn($manager);
     $registry->getManagers()->willReturn([$manager]);
     $association1->getProducts()->willReturn([$product1, $product2]);
     $association1->getGroups()->willReturn([$group1, $group2]);
     $association1->getId()->willReturn(2);
     $association2->getProducts()->willReturn([$product1, $product2]);
     $association2->getGroups()->willReturn([$group1, $group2]);
     $association2->getId()->willReturn(null);
     $manager->persist($association1)->shouldBeCalled();
     $manager->persist($association2)->shouldBeCalled();
     $manager->flush()->shouldBeCalled();
     $this->write([$association1, $association2]);
 }
 function it_normalizes_the_associations_of_the_product(ProductInterface $product, AssociationInterface $association1, AssociationInterface $association2, AssociationTypeInterface $type1, AssociationTypeInterface $type2, ProductInterface $productAssociated1, ProductInterface $productAssociated2, ProductInterface $productAssociated3, GroupInterface $groupAssociated1, GroupInterface $groupAssociated2)
 {
     $type1->getCode()->willReturn('wahou the type');
     $type2->getCode()->willReturn('such a type');
     $groupAssociated1->getCode()->willReturn('group 1');
     $groupAssociated2->getCode()->willReturn('group 2');
     $productAssociated1->getReference()->willReturn('product 1');
     $productAssociated2->getReference()->willReturn('product 2');
     $productAssociated3->getReference()->willReturn('product 3');
     $association1->getAssociationType()->willReturn($type1);
     $association2->getAssociationType()->willReturn($type2);
     $association1->getGroups()->willReturn([$groupAssociated1]);
     $association2->getGroups()->willReturn([$groupAssociated1, $groupAssociated2]);
     $association1->getProducts()->willReturn([]);
     $association2->getProducts()->willReturn([$productAssociated1, $productAssociated2, $productAssociated3]);
     $product->getAssociations()->willReturn([$association1, $association2]);
     $this->normalize($product, 'json')->shouldReturn(['such a type' => ['groups' => ['group 1', 'group 2'], 'products' => ['product 1', 'product 2', 'product 3']], 'wahou the type' => ['groups' => ['group 1'], 'products' => []]]);
 }
 function it_normalize_products($productNormalizer, $versionNormalizer, $versionManager, $localeRepository, $structureVersionProvider, $formProvider, ProductInterface $mug, AssociationInterface $upsell, AssociationTypeInterface $groupType, GroupInterface $group, ArrayCollection $groups)
 {
     $productNormalizer->normalize($mug, 'json', [])->willReturn(['normalized_property' => 'a nice normalized property']);
     $mug->getId()->willReturn(12);
     $versionManager->getOldestLogEntry($mug)->willReturn('create_version');
     $versionNormalizer->normalize('create_version', 'internal_api')->willReturn('normalized_create_version');
     $versionManager->getNewestLogEntry($mug)->willReturn('update_version');
     $versionNormalizer->normalize('update_version', 'internal_api')->willReturn('normalized_update_version');
     $localeRepository->getActivatedLocaleCodes()->willReturn(['en_US', 'fr_FR']);
     $mug->getLabel('en_US')->willReturn('A nice Mug!');
     $mug->getLabel('fr_FR')->willReturn('Un très beau Mug !');
     $mug->getAssociations()->willReturn([$upsell]);
     $upsell->getAssociationType()->willReturn($groupType);
     $groupType->getCode()->willReturn('group');
     $upsell->getGroups()->willReturn($groups);
     $groups->toArray()->willReturn([$group]);
     $group->getId()->willReturn(12);
     $structureVersionProvider->getStructureVersion()->willReturn(12);
     $formProvider->getForm($mug)->willReturn('product-edit-form');
     $this->normalize($mug, 'internal_api', [])->shouldReturn(['normalized_property' => 'a nice normalized property', 'meta' => ['form' => 'product-edit-form', 'id' => 12, 'created' => 'normalized_create_version', 'updated' => 'normalized_update_version', 'model_type' => 'product', 'structure_version' => 12, 'label' => ['en_US' => 'A nice Mug!', 'fr_FR' => 'Un très beau Mug !'], 'associations' => ['group' => ['groupIds' => [12]]]]]);
 }
 /**
  * @param AssociationInterface $association
  * @param array                $groupsCodes
  */
 protected function setAssociatedGroups(AssociationInterface $association, $groupsCodes)
 {
     foreach ($groupsCodes as $groupCode) {
         $associatedGroup = $this->groupRepository->findOneByIdentifier($groupCode);
         if (!$associatedGroup) {
             throw InvalidArgumentException::expected('associations', 'existing group code', 'setter', 'association', $groupCode);
         }
         $association->addGroup($associatedGroup);
     }
 }