/** * 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); }
/** * {@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; }
/** * 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')); }
/** * 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; }
/** * Test related method */ public function testGetAttributeAsLabelChoices() { $name = $this->getAttributeMock(); $address = $this->getAttributeMock(); $sku = $this->getAttributeMock('pim_catalog_identifier'); $phone = $this->getAttributeMock('phone'); $this->family->addAttribute($name); $this->family->addAttribute($address); $this->family->addAttribute($sku); $this->family->addAttribute($phone); $this->assertEquals([$name, $address, $sku], $this->family->getAttributeAsLabelChoices()); }
/** * {@inheritDoc} */ public function addAttribute(\Pim\Bundle\CatalogBundle\Model\AttributeInterface $attribute) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'addAttribute', array($attribute)); return parent::addAttribute($attribute); }
/** * 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()]); }
/** * 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())); }
/** * {@inheritdoc} */ protected function doPerform(Family $family) { foreach ($this->attRequirements as $attributeRequirement) { $family->addAttribute($attributeRequirement->getAttribute()); $family->addAttributeRequirement($this->factory->createAttributeRequirement($attributeRequirement->getAttribute(), $attributeRequirement->getChannel(), $attributeRequirement->isRequired())); } }