function it_add_attributes_to_attribute_group($groupSaver, $attributeSaver, AttributeGroupInterface $default, AttributeGroupInterface $group, AttributeInterface $sku, AttributeInterface $name) { $group->getMaxAttributeSortOrder()->willReturn(5); $sku->setSortOrder(6)->shouldBeCalled(); $group->addAttribute($sku)->shouldBeCalled(); $name->setSortOrder(7)->shouldBeCalled(); $group->addAttribute($name)->shouldBeCalled(); $attributeSaver->saveAll([$sku, $name])->shouldBeCalled(); $groupSaver->save($group)->shouldBeCalled(); $this->addAttributes($group, [$sku, $name]); }
function it_updates_an_attribute_group($attributeRepository, AttributeGroupInterface $attributeGroup, AttributeInterface $attributeSize, AttributeInterface $attributeMainColor) { $values = ['code' => 'sizes', 'sort_order' => 1, 'attributes' => ['size', 'main_color'], 'label' => ['en_US' => 'Sizes', 'fr_FR' => 'Tailles']]; $attributeGroup->setCode('sizes')->shouldBeCalled(); $attributeGroup->setSortOrder(1)->shouldBeCalled(); $attributeRepository->findOneByIdentifier('size')->willReturn($attributeSize); $attributeRepository->findOneByIdentifier('main_color')->willReturn($attributeMainColor); $attributeGroup->addAttribute($attributeSize)->shouldBeCalled(); $attributeGroup->addAttribute($attributeMainColor)->shouldBeCalled(); $attributeGroup->setLocale('en_US')->shouldBeCalled(); $attributeGroup->setLocale('fr_FR')->shouldBeCalled(); $attributeGroup->setLabel('Sizes')->shouldBeCalled(); $attributeGroup->setLabel('Tailles')->shouldBeCalled(); $this->update($attributeGroup, $values, []); }
/** * Add attributes to a group * * @param AttributeGroupInterface $group * @param AttributeInterface[] $attributes */ public function addAttributes(AttributeGroupInterface $group, $attributes) { $maxOrder = $group->getMaxAttributeSortOrder(); foreach ($attributes as $attribute) { $maxOrder++; $attribute->setSortOrder($maxOrder); $group->addAttribute($attribute); } $this->attributeSaver->saveAll($attributes); $this->groupSaver->save($group); }
/** * @param AttributeGroupInterface $attributeGroup * @param string $field * @param mixed $data * * @throws \InvalidArgumentException */ protected function setData($attributeGroup, $field, $data) { if ('code' == $field) { $attributeGroup->setCode($data); } elseif ('sort_order' == $field) { $attributeGroup->setSortOrder($data); } elseif ('attributes' == $field) { foreach ($data as $attributeCode) { $attribute = $this->findAttribute($attributeCode); if (null !== $attribute) { $attributeGroup->addAttribute($attribute); } else { throw new \InvalidArgumentException(sprintf('Attribute with "%s" code does not exist', $attributeCode)); } } } elseif ('label' == $field) { foreach ($data as $locale => $label) { $attributeGroup->setLocale($locale); $attributeGroup->setLabel($label); } } }
/** * @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); } }