function it_gets_association_type_choices_from_repository($entityRepository, AssociationType $associationType)
 {
     $entityRepository->findBy([])->willReturn([$associationType]);
     $associationType->getCode()->willReturn('foo');
     $associationType->getLabel()->willReturn('Foo');
     $this->getAssociationTypeChoices()->shouldReturn(['foo' => 'Foo']);
 }
 function it_returns_association_type_field_names($managerRegistry, AssociationTypeRepository $repository, AssociationType $assocType1, AssociationType $assocType2)
 {
     $assocType1->getCode()->willReturn("ASSOC_TYPE_1");
     $assocType2->getCode()->willReturn("ASSOC_TYPE_2");
     $repository->findAll()->willReturn([$assocType1, $assocType2]);
     $managerRegistry->getRepository(self::ASSOC_TYPE_CLASS)->willReturn($repository);
     $this->getAssociationFieldNames()->shouldReturn(["ASSOC_TYPE_1-groups", "ASSOC_TYPE_1-products", "ASSOC_TYPE_2-groups", "ASSOC_TYPE_2-products"]);
 }
 /**
  * {@inheritdoc}
  */
 protected function normalizeLabel(AssociationType $associationType)
 {
     $values = array();
     foreach ($associationType->getTranslations() as $translation) {
         $values[sprintf('label-%s', $translation->getLocale())] = $translation->getLabel();
     }
     return $values;
 }
 function it_returns_association_from_an_association_type_code(Association $assoc1, Association $assoc2, AssociationType $assocType1, AssociationType $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);
 }
 /**
  * {@inheritdoc}
  * @return AssociationTypeInterface
  */
 protected function createEntity(array $data)
 {
     $associationType = new AssociationType();
     $associationType->setCode($data['code']);
     foreach ($this->getLabels($data) as $locale => $label) {
         $translation = $associationType->getTranslation($locale);
         $translation->setLabel($label);
         $associationType->addTranslation($translation);
     }
     return $associationType;
 }
 function it_normalizes_an_association_with_products_and_groups($mongoFactory, Association $assoc, AssociationType $assocType, \MongoId $mongoId, \MongoDBRef $ownerRef, ProductInterface $product1, \MongoDBRef $product1Ref, ProductInterface $product2, \MongoDBRef $product2Ref, Group $group1, Group $group2)
 {
     $assocType->getId()->willReturn(8);
     $assoc->getAssociationType()->willReturn($assocType);
     $context = ['_id' => '1234abc', 'collection_name' => 'product'];
     $mongoFactory->createMongoId()->willReturn($mongoId);
     $mongoFactory->createMongoDBRef('product', '1234abc')->willReturn($ownerRef);
     $mongoFactory->createMongoDBRef('product', 'product1')->willReturn($product1Ref);
     $mongoFactory->createMongoDBRef('product', 'product2')->willReturn($product2Ref);
     $product1->getId()->willReturn('product1');
     $product2->getId()->willReturn('product2');
     $assoc->getProducts()->willReturn([$product1, $product2]);
     $group1->getId()->willReturn(1);
     $group2->getId()->willReturn(2);
     $assoc->getGroups()->willReturn([$group1, $group2]);
     $this->normalize($assoc, 'mongodb_document', $context)->shouldReturn(['_id' => $mongoId, 'associationType' => 8, 'owner' => $ownerRef, 'products' => [$product1Ref, $product2Ref], 'groupIds' => [1, 2]]);
 }
 /**
  * Test getter/setter for translations property
  */
 public function testTranslations()
 {
     $this->assertCount(0, $this->associationType->getTranslations());
     // Change value and assert new
     $newTranslation = new AssociationTypeTranslation();
     $this->assertEntity($this->associationType->addTranslation($newTranslation));
     $this->assertCount(1, $this->associationType->getTranslations());
     $this->assertInstanceOf('Pim\\Bundle\\CatalogBundle\\Entity\\AssociationTypeTranslation', $this->associationType->getTranslations()->first());
     $this->associationType->addTranslation($newTranslation);
     $this->assertCount(1, $this->associationType->getTranslations());
     $this->assertEntity($this->associationType->removeTranslation($newTranslation));
     $this->assertCount(0, $this->associationType->getTranslations());
 }
 function it_normalizes_product_with_associations($filter, ProductInterface $product, AbstractAttribute $skuAttribute, AbstractProductValue $sku, Association $myCrossSell, AssociationType $crossSell, Association $myUpSell, AssociationType $upSell, Group $associatedGroup1, Group $associatedGroup2, ProductInterface $associatedProduct1, ProductInterface $associatedProduct2, AbstractProductValue $skuAssocProduct1, AbstractProductValue $skuAssocProduct2, Collection $values, Family $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->filter(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]);
 }
 /**
  * @param string $code
  * @param string $label
  */
 protected function createAssociationType($code, $label)
 {
     $associationType = new AssociationType();
     $associationType->setCode($code);
     $associationType->setLocale('en_US')->setLabel($label);
     $this->validate($associationType);
     $this->persist($associationType);
 }
 /**
  * @param AssociationType $associationType
  *
  * @Given /^I should be on the ("([^"]*)" association type) page$/
  */
 public function iShouldBeOnTheAssociationTypePage(AssociationType $associationType)
 {
     $expectedAddress = $this->getPage('AssociationType edit')->getUrl(array('id' => $associationType->getId()));
     $this->assertAddress($expectedAddress);
 }
 /**
  * {@inheritDoc}
  */
 public function getReference()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getReference', array());
     return parent::getReference();
 }
 /**
  * @param string $code
  * @param string $label
  */
 protected function createAssociationType($code, $label)
 {
     $associationType = new AssociationType();
     $associationType->setCode($code);
     $associationType->setLocale('en_US')->setLabel($label);
     $this->validate($associationType);
     $this->getContainer()->get('pim_catalog.saver.association_type')->save($associationType);
 }
 /**
  * Get the product association for an Association type
  *
  * @param AssociationType $type
  *
  * @return AbstractAssociation|null
  */
 public function getAssociationForType(AssociationType $type)
 {
     return $this->getAssociationForTypeCode($type->getCode());
 }
 /**
  * {@inheritdoc}
  */
 public function countForAssociationType(AssociationType $associationType)
 {
     $assocMatch = ['$and' => [['associationType' => $associationType->getId()], ['$or' => [['products' => ['$ne' => []]], ['groups' => ['$ne' => []]]]]]];
     $qb = $this->createQueryBuilder()->hydrate(false)->field('associations')->elemMatch($assocMatch)->select('_id');
     return $qb->getQuery()->execute()->count();
 }
 /**
  * {@inheritdoc}
  */
 public function getReference()
 {
     return $this->owner ? $this->owner->getIdentifier() . '.' . $this->associationType->getCode() : null;
 }