コード例 #1
0
 function it_does_not_update_attributes_from_the_default_group($attributeGroupRepository, AttributeGroupInterface $attributeGroup)
 {
     $values = ['code' => 'other', 'sort_order' => 1, 'attributes' => ['foo'], 'label' => ['en_US' => 'Other', 'fr_FR' => 'Autre']];
     $attributeGroup->getCode()->willReturn('other');
     $attributeGroup->setCode('other')->shouldBeCalled();
     $attributeGroup->setSortOrder(1)->shouldBeCalled();
     $attributeGroup->setLocale('en_US')->shouldBeCalled();
     $attributeGroup->setLocale('fr_FR')->shouldBeCalled();
     $attributeGroup->setLabel('Other')->shouldBeCalled();
     $attributeGroup->setLabel('Autre')->shouldBeCalled();
     $attributeGroupRepository->findDefaultAttributeGroup()->shouldNotBeCalled();
     $attributeGroup->getAttributes()->shouldNotBeCalled();
     $this->update($attributeGroup, $values, []);
 }
コード例 #2
0
 /**
  * @param AttributeGroupInterface $attributeGroup
  * @param string[]                $data
  */
 protected function setAttributes(AttributeGroupInterface $attributeGroup, array $data)
 {
     if ('other' === $attributeGroup->getCode()) {
         return;
     }
     $defaultGroup = $this->attributeGroupRepository->findDefaultAttributeGroup();
     foreach ($attributeGroup->getAttributes() as $attribute) {
         if (!in_array($attribute->getCode(), $data)) {
             $defaultGroup->addAttribute($attribute);
         }
     }
     foreach ($data as $attributeCode) {
         $attribute = $this->findAttribute($attributeCode);
         if (null === $attribute) {
             throw new \InvalidArgumentException(sprintf('Attribute with "%s" code does not exist', $attributeCode));
         }
         $attributeGroup->addAttribute($attribute);
     }
 }