/** * @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); } }