/** * {@inheritdoc} */ public function saveInSetIncluding(\Magento\Framework\Model\AbstractModel $object, $attributeEntityId = null, $attributeSetId = null, $attributeGroupId = null, $attributeSortOrder = null) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'saveInSetIncluding'); if (!$pluginInfo) { return parent::saveInSetIncluding($object, $attributeEntityId, $attributeSetId, $attributeGroupId, $attributeSortOrder); } else { return $this->___callPlugins('saveInSetIncluding', func_get_args(), $pluginInfo); } }
/** * {@inheritdoc} */ public function assign($entityTypeCode, $attributeSetId, $attributeGroupId, $attributeCode, $sortOrder) { try { $attributeSet = $this->setRepository->get($attributeSetId); } catch (NoSuchEntityException $ex) { throw new NoSuchEntityException(__('AttributeSet with id "%1" does not exist.', $attributeSetId)); } $setEntityType = $this->entityTypeFactory->create()->getEntityType($attributeSet->getEntityTypeId()); if ($setEntityType->getEntityTypeCode() != $entityTypeCode) { throw new InputException(__('Wrong attribute set id provided')); } //Check if group exists. If not - expected exception $attributeGroup = $this->groupRepository->get($attributeGroupId); if ($attributeGroup->getAttributeSetId() != $attributeSetId) { throw new InputException(__('Attribute group does not belong to attribute set')); } /** @var \Magento\Eav\Api\Data\AttributeInterface $attribute */ $attribute = $this->attributeRepository->get($entityTypeCode, $attributeCode); $this->attributeResource->saveInSetIncluding($attribute, $attribute->getAttributeId(), $attributeSetId, $attributeGroupId, $sortOrder); $attribute->setAttributeSetId($attributeSetId); return $attribute->loadEntityAttributeIdBySet()->getData('entity_attribute_id'); }