private function saveRelation() { if (!$this->attributeObj) { return array('result' => false, 'error' => "Attribute '{$this->code}' is not found."); } if (!$this->attributeSetObj) { return array('result' => false, 'error' => "Attribute Set '{$this->setId}' is not found."); } if ($this->checkIsAlreadyInSet()) { return array('result' => true); } $groupId = $this->getGroupId(); $sortOrder = !empty($this->params['sorder']) ? $this->params['sorder'] : $this->getMaxSortOrderByGroup($groupId) + 1; !empty($this->params['sorder_ofset']) && ($sortOrder += $this->params['sorder_ofset']); /* @var $collection \Magento\Eav\Model\ResourceModel\Entity\Attribute */ $relation = $this->attributeFactory->create(); $relation->setEntityTypeId($this->attributeSetObj->getEntityTypeId())->setAttributeSetId($this->attributeSetObj->getId())->setAttributeGroupId($groupId)->setAttributeId($this->attributeObj->getId())->setSortOrder($sortOrder); try { $relation->save(); } catch (\Exception $e) { return array('result' => false, 'error' => $e->getMessage()); } return array('result' => true, 'obj' => $relation); }
/** * Validate attribute set name * * @param \Magento\Eav\Model\Entity\Attribute\Set $object * @param string $attributeSetName * @return bool */ public function validate($object, $attributeSetName) { $adapter = $this->_getReadAdapter(); $bind = ['attribute_set_name' => trim($attributeSetName), 'entity_type_id' => $object->getEntityTypeId()]; $select = $adapter->select()->from($this->getMainTable())->where('attribute_set_name = :attribute_set_name')->where('entity_type_id = :entity_type_id'); if ($object->getId()) { $bind['attribute_set_id'] = $object->getId(); $select->where('attribute_set_id != :attribute_set_id'); } return !$adapter->fetchOne($select, $bind) ? true : false; }
/** * {@inheritdoc} */ public function getEntityTypeId() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getEntityTypeId'); if (!$pluginInfo) { return parent::getEntityTypeId(); } else { return $this->___callPlugins('getEntityTypeId', func_get_args(), $pluginInfo); } }