/**
  * Normalize the attributes
  *
  * @param Family $family
  *
  * @return array
  */
 protected function normalizeAttributes(Family $family)
 {
     $attributes = array();
     foreach ($family->getAttributes() as $attribute) {
         $attributes[] = $attribute->getCode();
     }
     return $attributes;
 }
Ejemplo n.º 2
0
 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']]);
 }
 /**
  * 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];
 }
 /**
  * {@inheritDoc}
  */
 public function getAttributes()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getAttributes', array());
     return parent::getAttributes();
 }
 /**
  * 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()]);
 }
Ejemplo n.º 7
0
 /**
  * Test related method
  */
 public function testAddAttribute()
 {
     $attribute = $this->getAttributeMock();
     $this->assertEntity($this->family->addAttribute($attribute));
     $this->assertEquals(array($attribute), $this->family->getAttributes()->toArray());
 }
 /**
  * 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()));
 }