/** * test relatede method */ public function testAddMissingProductValues() { $builder = $this->getProductBuilder(); $product = new Product(); $this->assertEquals(count($product->getValues()), 0); $family = new Family(); $attribute = new Attribute(); $attribute->setCode('one'); $family->addAttribute($attribute); $product->setFamily($family); $builder->addMissingProductValues($product); $this->assertValues($product, array('one')); $attributeTwo = new Attribute(); $attributeTwo->setCode('two'); $attributeTwo->setLocalizable(true); $family->addAttribute($attributeTwo); $builder->addMissingProductValues($product); $this->assertValues($product, array('one', 'twoen_US', 'twofr_FR')); $attributeThree = new Attribute(); $attributeThree->setCode('three'); $attributeThree->setScopable(true); $family->addAttribute($attributeThree); $builder->addMissingProductValues($product); $this->assertValues($product, array('one', 'twoen_US', 'twofr_FR', 'threeecom', 'threeprint')); $attributeFour = new Attribute(); $attributeFour->setCode('four'); $attributeFour->setLocalizable(true); $attributeFour->setScopable(true); $family->addAttribute($attributeFour); $builder->addMissingProductValues($product); $this->assertValues($product, array('one', 'twoen_US', 'twofr_FR', 'threeecom', 'threeprint', 'fouren_USecom', 'fouren_USprint', 'fourfr_FRecom', 'fourfr_FRprint')); }
function it_has_family(Family $family) { $family->getId()->willReturn(42); $this->setFamily($family); $this->getFamily()->shouldReturn($family); $this->getFamilyId()->shouldReturn(42); }
function it_returns_null_if_family_is_not_found(Family $family, $entityRepository, $mappingCollection) { $entityRepository->findOneBy(['family' => $family, 'magentoUrl' => ''])->willReturn(null); $mappingCollection->getTarget('colors')->willReturn('colors'); $family->getCode()->willReturn('colors'); $this->getIdFromFamily($family, '', $mappingCollection)->shouldReturn(null); }
public function let(ObjectManager $objectManager, EntityRepository $entityRepository, Family $family, AttributeGroup $group) { $this->beConstructedWith($objectManager, 'Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoAttributeMapping'); $objectManager->getRepository('Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoAttributeMapping')->willReturn($entityRepository); $group->getCode()->willReturn(12); $family->getCode()->willReturn(5); }
/** * Test related method */ public function testPreSetData() { $mobile = $this->getChannelMock('mobile'); $ecommerce = $this->getChannelMock('ecommerce'); $channelManager = $this->getChannelManagerMock(array($mobile, $ecommerce)); $name = $this->getAttributeMock('name'); $description = $this->getAttributeMock('description'); $family = new Family(); $family->addAttribute($name); $family->addAttribute($description); $event = $this->getEventMock($family); $subscriber = new AddAttributeRequirementsSubscriber($channelManager); $existingRequirement = $this->getAttributeRequirementMock($name, $mobile); $family->setAttributeRequirements(array($existingRequirement)); $subscriber->preSetData($event); $requirements = $family->getAttributeRequirements(); $this->assertArrayHasKey('name_mobile', $requirements); $this->assertArrayHasKey('name_ecommerce', $requirements); $this->assertArrayHasKey('description_mobile', $requirements); $this->assertArrayHasKey('description_ecommerce', $requirements); $this->assertAttributeRequirement($requirements, 'name_ecommerce', $family, $name, $ecommerce); $this->assertAttributeRequirement($requirements, 'description_mobile', $family, $description, $mobile); $this->assertAttributeRequirement($requirements, 'description_ecommerce', $family, $description, $ecommerce); $this->assertEquals($requirements['name_mobile'], $existingRequirement); }
function it_normalizes_an_existing_product_into_mongodb_document($mongoFactory, $serializer, ProductInterface $product, \MongoId $mongoId, \MongoDate $mongoDate, Association $assoc1, Association $assoc2, CategoryInterface $category1, CategoryInterface $category2, Group $group1, Group $group2, AbstractProductValue $value1, AbstractProductValue $value2, Family $family) { $mongoFactory->createMongoId('product1')->willReturn($mongoId); $mongoFactory->createMongoDate()->willReturn($mongoDate); $family->getId()->willReturn(36); $category1->getId()->willReturn(12); $category2->getId()->willReturn(34); $group1->getId()->willReturn(56); $group2->getId()->willReturn(78); $product->getId()->willReturn('product1'); $product->getCreated()->willReturn(null); $product->getFamily()->willReturn($family); $product->isEnabled()->willReturn(true); $product->getGroups()->willReturn([$group1, $group2]); $product->getCategories()->willReturn([$category1, $category2]); $product->getAssociations()->willReturn([$assoc1, $assoc2]); $product->getValues()->willReturn([$value1, $value2]); $context = ['_id' => $mongoId]; $serializer->normalize($product, 'mongodb_json')->willReturn(['data' => 'data', 'completenesses' => 'completenesses']); $serializer->normalize($value1, 'mongodb_document', $context)->willReturn('my_value_1'); $serializer->normalize($value2, 'mongodb_document', $context)->willReturn('my_value_2'); $serializer->normalize($assoc1, 'mongodb_document', $context)->willReturn('my_assoc_1'); $serializer->normalize($assoc2, 'mongodb_document', $context)->willReturn('my_assoc_2'); $this->normalize($product, 'mongodb_document')->shouldReturn(['_id' => $mongoId, 'created' => $mongoDate, 'updated' => $mongoDate, 'family' => 36, 'enabled' => true, 'groupIds' => [56, 78], 'categoryIds' => [12, 34], 'associations' => ['my_assoc_1', 'my_assoc_2'], 'values' => ['my_value_1', 'my_value_2'], 'normalizedData' => ['data' => 'data'], 'completenesses' => []]); }
function it_normalizes_family($normalizer, Family $family, AbstractAttribute $sku) { $sku->getCode()->willReturn('sku'); $family->getCode()->willReturn('mongo'); $family->getAttributeAsLabel()->willReturn($sku); $normalizer->normalize($family, 'mongodb_json', [])->willReturn(['label' => 'translations']); $this->normalize($family, 'mongodb_json', [])->shouldReturn(['code' => 'mongo', 'label' => 'translations', 'attributeAsLabel' => 'sku']); }
function it_does_not_add_violation_when_a_immutable_property_has_not_been_modified($context, $entityManager, UnitOfWork $unitOfWork, Immutable $constraint) { $family = new Family(); $family->setCode('MyOriginalCode'); $entityManager->getUnitOfWork()->willReturn($unitOfWork); $unitOfWork->getOriginalEntityData($family)->willReturn(['code' => 'MyOriginalCode']); $context->buildViolation(Argument::any(), Argument::any())->shouldNotBeCalled(); $constraint->properties = ['code']; $this->validate($family, $constraint); }
/** * @param Family $family * * @return array */ public function getAllSources(Family $family = null) { $sources = []; if ($this->isValid()) { $families = $this->familyManager->getFamilies(); foreach ($families as $family) { $sources[] = ['id' => $family->getCode(), 'name' => $family->getCode()]; } } return $sources; }
/** * Create and configure a family intance * * @return Family */ public function createFamily() { $family = new Family(); $identifier = $this->productManager->getIdentifierAttribute(); $family->addAttribute($identifier); $family->setAttributeAsLabel($identifier); foreach ($this->getChannels() as $channel) { $family->addAttributeRequirement($this->factory->createAttributeRequirement($identifier, $channel, true)); } return $family; }
/** * Normalize the requirements * * @param Family $family * * @return array */ protected function normalizeRequirements(Family $family) { $required = array(); foreach ($family->getAttributeRequirements() as $requirement) { $channelCode = $requirement->getChannel()->getCode(); if (!isset($required[$channelCode])) { $required[$channelCode] = array(); } if ($requirement->isRequired()) { $required[$channelCode][] = $requirement->getAttribute()->getCode(); } } return $required; }
/** * Register a new group mapping. * * @param AttributeGroup $pimGroup * @param Family $pimFamily * @param integer $magentoGroupId * @param string $magentoUrl */ public function registerGroupMapping(AttributeGroup $pimGroup, Family $pimFamily, $magentoGroupId, $magentoUrl) { $groupMapping = $this->getEntityRepository()->findOneBy(['pimGroupCode' => $pimGroup->getCode(), 'pimFamilyCode' => $pimFamily->getCode(), 'magentoUrl' => $magentoUrl]); $magentoGroupMapping = new $this->className(); if ($groupMapping) { $magentoGroupMapping = $groupMapping; } $magentoGroupMapping->setPimGroupCode($pimGroup->getCode()); $magentoGroupMapping->setPimFamilyCode($pimFamily->getCode()); $magentoGroupMapping->setMagentoGroupId($magentoGroupId); $magentoGroupMapping->setMagentoUrl($magentoUrl); $this->objectManager->persist($magentoGroupMapping); $this->objectManager->flush(); }
/** * {@inheritdoc} * * @return Family */ protected function createEntity(array $data) { $family = new Family(); $family->setCode('mycode'); foreach ($this->getLabels($data) as $locale => $label) { $translation = $family->getTranslation($locale); $translation->setLabel($label); $family->addTranslation($translation); } $codes = array('attribute1', 'attribute2', 'attribute3'); $attributes = array(); foreach ($codes as $code) { $attribute = new Attribute(); $attribute->setCode($code); $family->addAttribute($attribute); $attributes[] = $attribute; } $family->setAttributeAsLabel(current($attributes)); $channel1 = new Channel(); $channel1->setCode('channel1'); $channel2 = new Channel(); $channel2->setCode('channel2'); $requirements = array(array('attribute' => $attributes[0], 'channel' => $channel1, 'required' => true), array('attribute' => $attributes[1], 'channel' => $channel1, 'required' => true), array('attribute' => $attributes[2], 'channel' => $channel1, 'required' => false), array('attribute' => $attributes[0], 'channel' => $channel2, 'required' => true), array('attribute' => $attributes[1], 'channel' => $channel2, 'required' => false), array('attribute' => $attributes[2], 'channel' => $channel2, 'required' => true)); $attrRequirements = array(); foreach ($requirements as $requirement) { $attrRequirement = new AttributeRequirement(); $attrRequirement->setAttribute($requirement['attribute']); $attrRequirement->setChannel($requirement['channel']); $attrRequirement->setRequired($requirement['required']); $attrRequirements[] = $attrRequirement; } $family->setAttributeRequirements($attrRequirements); return $family; }
function it_normalizes_a_family_and_its_attributes(Family $family, Collection $attributes, \Iterator $iterator, AbstractAttribute $attribute1) { $family->getCode()->willReturn('bar'); $family->getAttributes()->willReturn($attributes); $attribute1->getCode()->willReturn('att1'); $attributes->getIterator()->willReturn($iterator); $iterator->rewind()->willReturn($attribute1); $iterator->current()->willReturn($attribute1); $iterator->next()->willReturn($attribute1); $valueCount = 1; $iterator->valid()->will(function () use(&$valueCount) { return $valueCount-- > 0; }); $this->normalize($family, 'json')->shouldReturn(['code' => 'bar', 'attributes' => ['att1']]); }
/** * Test related methods */ public function testGuessUpdates() { $versionables = array('Pim\\Bundle\\CatalogBundle\\Entity\\Attribute', 'Pim\\Bundle\\CatalogBundle\\Entity\\Family'); $attribute = new Attribute(); $attribute->setCode('my code'); $guesser = new VersionableUpdateGuesser($versionables); $em = $this->getEntityManagerMock(); $updates = $guesser->guessUpdates($em, $attribute, UpdateGuesserInterface::ACTION_UPDATE_ENTITY); $this->assertEquals(1, count($updates)); $this->assertEquals($attribute, $updates[0]); $family = new Family(); $family->setCode('my code'); $updates = $guesser->guessUpdates($em, $family, UpdateGuesserInterface::ACTION_UPDATE_ENTITY); $this->assertEquals(1, count($updates)); $this->assertEquals($family, $updates[0]); }
/** * Test getter/setter for translations property */ public function testTranslations() { $this->assertCount(0, $this->family->getTranslations()); // Change value and assert new $newTranslation = new FamilyTranslation(); $this->assertEntity($this->family->addTranslation($newTranslation)); $this->assertCount(1, $this->family->getTranslations()); $this->assertInstanceOf('Pim\\Bundle\\CatalogBundle\\Entity\\FamilyTranslation', $this->family->getTranslations()->first()); $this->family->addTranslation($newTranslation); $this->assertCount(1, $this->family->getTranslations()); $this->assertEntity($this->family->removeTranslation($newTranslation)); $this->assertCount(0, $this->family->getTranslations()); }
/** * Check if an attribute can be removed from the product * * @param AbstractAttribute $attribute * * @return boolean */ public function isAttributeRemovable(AbstractAttribute $attribute) { if ('pim_catalog_identifier' === $attribute->getAttributeType()) { return false; } if (null !== $this->family && $this->family->getAttributes()->contains($attribute)) { return false; } foreach ($this->groups as $group) { if ($group->getType()->isVariant()) { if ($group->getAttributes()->contains($attribute)) { return false; } } } return true; }
/** * Get non-identifier attribute from family * * @param Family $family * * @return Attribute[] */ protected function getAttributesFromFamily(Family $family) { $familyCode = $family->getCode(); if (!isset($this->attributesByFamily[$familyCode])) { $this->attributesByFamily[$familyCode] = []; $attributes = $family->getAttributes(); foreach ($attributes as $attribute) { if ($attribute->getCode() !== $this->identifierCode) { $this->attributesByFamily[$familyCode][$attribute->getCode()] = $attribute; } } } return $this->attributesByFamily[$familyCode]; }
/** * @param Family $family * * @return string[] */ public function findAllIdsForFamily(Family $family) { $qb = $this->createQueryBuilder('p')->hydrate(false)->field('family')->equals($family->getId())->select('_id'); $results = $qb->getQuery()->execute()->toArray(); return array_keys($results); }
/** * Normalizes a family * * @param Family $family */ protected function normalizeFamily(Family $family = null) { $this->results[self::FIELD_FAMILY] = $family ? $family->getCode() : ''; }
/** * @param Family $family * * @Given /^I should be on the ("([^"]*)" family) page$/ */ public function iShouldBeOnTheFamilyPage(Family $family) { $expectedAddress = $this->getPage('Family edit')->getUrl(['id' => $family->getId()]); $this->assertAddress($expectedAddress); }
/** * Set family * * @param Family $family * * @return AbstractProduct */ public function setFamily(Family $family = null) { if (null !== $family) { $this->familyId = $family->getId(); } $this->family = $family; return $this; }
function it_normalizes_product_with_a_multiselect_value($filter, $serializer, ProductInterface $product, AbstractAttribute $skuAttribute, AbstractAttribute $colorsAttribute, AbstractProductValue $sku, AbstractProductValue $colors, AttributeOption $red, AttributeOption $blue, Collection $values, Family $family) { $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'); $colorsAttribute->getCode()->willReturn('colors'); $colorsAttribute->isLocalizable()->willReturn(false); $colorsAttribute->isScopable()->willReturn(false); $colors->getAttribute()->willReturn($colorsAttribute); $colors->getData()->willReturn([$red, $blue]); $product->getIdentifier()->willReturn($sku); $product->getFamily()->willReturn($family); $product->isEnabled()->willReturn(true); $product->getGroupCodes()->willReturn(''); $product->getCategoryCodes()->willReturn(''); $product->getAssociations()->willReturn([]); $product->getValues()->willReturn($values); $filter->filter($values, ['identifier' => $sku, 'scopeCode' => null, 'localeCodes' => []])->willReturn([$sku, $colors]); $serializer->normalize($sku, 'flat', Argument::any())->willReturn(['sku' => 'sku-001']); $serializer->normalize($colors, 'flat', Argument::any())->willReturn(['colors' => 'red, blue']); $this->normalize($product, 'flat', [])->shouldReturn(['sku' => 'sku-001', 'family' => 'shoes', 'groups' => '', 'categories' => '', 'colors' => 'red, blue', 'enabled' => 1]); }
/** * {@inheritDoc} */ public function getReference() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getReference', array()); return parent::getReference(); }
/** * Add attributes to a family * * @param Family $family * * @AclAncestor("pim_enrich_family_edit_attributes") * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function addAttributesAction(Family $family) { $availableAttributes = new AvailableAttributes(); $attributesForm = $this->getAvailableAttributesForm($family->getAttributes()->toArray(), $availableAttributes); $attributesForm->submit($this->getRequest()); foreach ($availableAttributes->getAttributes() as $attribute) { $family->addAttribute($attribute); } $this->familySaver->save($family); $this->addFlash('success', 'flash.family.attributes added'); return $this->redirectToRoute('pim_enrich_family_edit', ['id' => $family->getId()]); }
/** * Sets the requirements for a channel * * @param string $class * @param Family $family * @param string $channelCode * @param array $attributeCodes */ protected function setChannelRequirements($class, Family $family, $channelCode, $attributeCodes) { foreach ($attributeCodes as $attributeCode) { $data = array('attribute' => $attributeCode, 'channel' => $channelCode, 'required' => true); $requirement = $this->transformNestedEntity($class, 'requirements', $this->requirementClass, $data); if ($requirement->getAttribute() === null) { throw new \Exception(sprintf('The attribute "%s" used as requirement in family "%s" is not known', $attributeCode, $family->getCode())); } $family->addAttributeRequirement($requirement); } }
/** * Test if an attribute set exist on prestashop. * * @param Family $family Family of attribute * @param array $prestashopAttributesSet Attribute sets from prestashop * * @return boolean Return true if the family exist on prestashop */ protected function prestashopAttributeSetExists(Family $family, array $prestashopAttributesSet) { return array_key_exists($family->getCode(), $prestashopAttributesSet); }
function it_normalizes_a_family(Family $family) { $family->getCode()->willReturn('family_code'); $this->normalize($family)->shouldReturn(['attributeSetName' => 'family_code']); }
/** * Add attributes to a family * * @param Family $family * * @AclAncestor("pim_enrich_family_edit_attributes") * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function addAttributesAction(Family $family) { $availableAttributes = new AvailableAttributes(); $attributesForm = $this->getAvailableAttributesForm($family->getAttributes()->toArray(), $availableAttributes); $attributesForm->submit($this->getRequest()); foreach ($availableAttributes->getAttributes() as $attribute) { $family->addAttribute($attribute); } $this->getManagerForClass('PimCatalogBundle:Family')->flush(); $this->addFlash('success', 'flash.family.attributes added'); return $this->redirectToRoute('pim_enrich_family_edit', array('id' => $family->getId())); }
/** * Schedule recalculation of completenesses for all product * of a family * * @param Family $family */ public function scheduleForFamily(Family $family) { if ($family->getId()) { $this->generator->scheduleForFamily($family); } }