function it_resolves_association_type_field_names($assocTypeRepo, AssociationTypeInterface $assocType1, AssociationTypeInterface $assocType2)
 {
     $assocType1->getCode()->willReturn("ASSOC_TYPE_1");
     $assocType2->getCode()->willReturn("ASSOC_TYPE_2");
     $assocTypeRepo->findAll()->willReturn([$assocType1, $assocType2]);
     $this->resolveAssociationColumns()->shouldReturn(["ASSOC_TYPE_1-groups", "ASSOC_TYPE_1-products", "ASSOC_TYPE_2-groups", "ASSOC_TYPE_2-products"]);
 }
 function it_returns_association_from_an_association_type_code(Association $assoc1, Association $assoc2, AssociationTypeInterface $assocType1, AssociationTypeInterface $assocType2)
 {
     $assocType1->getCode()->willReturn('ASSOC_TYPE_1');
     $assocType2->getCode()->willReturn('ASSOC_TYPE_2');
     $assoc1->getAssociationType()->willReturn($assocType1);
     $assoc2->getAssociationType()->willReturn($assocType2);
     $this->setAssociations([$assoc1, $assoc2]);
     $this->getAssociationForTypeCode('ASSOC_TYPE_2')->shouldReturn($assoc2);
 }
 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_retrieves_field_list_with_product_with_attributes($productRepository, $attributeRepository, $assocTypeRepo, AttributeInterface $bar, AttributeInterface $baz, AssociationTypeInterface $association)
 {
     $bar->getCode()->willReturn('bar-code');
     $bar->isLocalizable()->willReturn(false);
     $bar->isScopable()->willReturn(false);
     $bar->getAttributeType()->willReturn(null);
     $baz->getCode()->willReturn('baz-code');
     $baz->isLocalizable()->willReturn(false);
     $baz->isScopable()->willReturn(false);
     $baz->getAttributeType()->willReturn(null);
     $association->getCode()->willReturn('association-type-code');
     $assocTypeRepo->findAll()->willReturn([$association]);
     $productRepository->getAvailableAttributeIdsToExport(['foo'])->willReturn(['bar', 'baz']);
     $attributeRepository->findBy(['id' => ['bar', 'baz']])->willReturn([$bar, $baz]);
     $this->getFieldsList(['foo'])->shouldReturn(["bar-code", "baz-code", "family", "categories", "groups", "association-type-code-groups", "association-type-code-products"]);
 }
 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_normalizes_product_with_associations($filter, ProductInterface $product, AttributeInterface $skuAttribute, ProductValueInterface $sku, Association $myCrossSell, AssociationTypeInterface $crossSell, Association $myUpSell, AssociationTypeInterface $upSell, GroupInterface $associatedGroup1, GroupInterface $associatedGroup2, ProductInterface $associatedProduct1, ProductInterface $associatedProduct2, ProductValueInterface $skuAssocProduct1, ProductValueInterface $skuAssocProduct2, Collection $values, FamilyInterface $family, $serializer)
 {
     $family->getCode()->willReturn('shoes');
     $skuAttribute->getCode()->willReturn('sku');
     $skuAttribute->getAttributeType()->willReturn('pim_catalog_identifier');
     $skuAttribute->isLocalizable()->willReturn(false);
     $skuAttribute->isScopable()->willReturn(false);
     $sku->getAttribute()->willReturn($skuAttribute);
     $sku->getData()->willReturn('sku-001');
     $crossSell->getCode()->willReturn('cross_sell');
     $myCrossSell->getAssociationType()->willReturn($crossSell);
     $myCrossSell->getGroups()->willReturn([]);
     $myCrossSell->getProducts()->willReturn([]);
     $upSell->getCode()->willReturn('up_sell');
     $myUpSell->getAssociationType()->willReturn($upSell);
     $associatedGroup1->getCode()->willReturn('associated_group1');
     $associatedGroup2->getCode()->willReturn('associated_group2');
     $myUpSell->getGroups()->willReturn([$associatedGroup1, $associatedGroup2]);
     $skuAssocProduct1->getAttribute()->willReturn($skuAttribute);
     $skuAssocProduct2->getAttribute()->willReturn($skuAttribute);
     $skuAssocProduct1->__toString()->willReturn('sku_assoc_product1');
     $skuAssocProduct2->__toString()->willReturn('sku_assoc_product2');
     $associatedProduct1->getIdentifier()->willReturn($skuAssocProduct1);
     $associatedProduct2->getIdentifier()->willReturn($skuAssocProduct2);
     $myUpSell->getProducts()->willReturn([$associatedProduct1, $associatedProduct2]);
     $product->getIdentifier()->willReturn($sku);
     $product->getFamily()->willReturn($family);
     $product->isEnabled()->willReturn(true);
     $product->getGroupCodes()->willReturn(['group1,group2', 'variant_group_1']);
     $product->getCategoryCodes()->willReturn(['nice shoes', 'converse']);
     $product->getAssociations()->willReturn([$myCrossSell, $myUpSell]);
     $product->getValues()->willReturn($values);
     $filter->filterCollection($values, 'pim.transform.product_value.flat', Argument::cetera())->willReturn([$sku]);
     $serializer->normalize($sku, 'flat', Argument::any())->willReturn(['sku' => 'sku-001']);
     $this->normalize($product, 'flat', [])->shouldReturn(['sku' => 'sku-001', 'family' => 'shoes', 'groups' => 'group1,group2,variant_group_1', 'categories' => 'nice shoes,converse', 'cross_sell-groups' => '', 'cross_sell-products' => '', 'up_sell-groups' => 'associated_group1,associated_group2', 'up_sell-products' => 'sku_assoc_product1,sku_assoc_product2', 'enabled' => 1]);
 }
 /**
  * {@inheritdoc}
  */
 public function getReference()
 {
     return $this->owner ? $this->owner->getIdentifier() . '.' . $this->associationType->getCode() : null;
 }
 function it_normalizes_association_type($transnormalizer, AssociationTypeInterface $association)
 {
     $transnormalizer->normalize(Argument::cetera())->willReturn([]);
     $association->getCode()->willReturn('PACK');
     $this->normalize($association)->shouldReturn(['code' => 'PACK']);
 }
 /**
  * {@inheritdoc}
  */
 public function getAssociationForType(AssociationTypeInterface $type)
 {
     return $this->getAssociationForTypeCode($type->getCode());
 }