/** * Adding attribute to entity * * @param AbstractAttribute $attribute * @return $this */ public function addAttribute(AbstractAttribute $attribute) { $attribute->setEntity($this); $attributeCode = $attribute->getAttributeCode(); $this->_attributesByCode[$attributeCode] = $attribute; if ($attribute->isStatic()) { $this->_staticAttributes[$attributeCode] = $attribute; } else { $this->_attributesByTable[$attribute->getBackendTable()][$attributeCode] = $attribute; } return $this; }
/** * Get attribute type for upcoming validation. * * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute|\Magento\Eav\Model\Entity\Attribute $attribute * @return string */ public static function getAttributeType(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute) { $frontendInput = $attribute->getFrontendInput(); if ($attribute->usesSource() && in_array($frontendInput, ['select', 'multiselect', 'boolean'])) { return $frontendInput; } elseif ($attribute->isStatic()) { return $frontendInput == 'date' ? 'datetime' : 'varchar'; } else { return $attribute->getBackendType(); } }
/** * Get attribute type for upcoming validation. * * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute|\Magento\Eav\Model\Entity\Attribute $attribute * @return string */ public static function getAttributeType(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute) { if ($attribute->usesSource()) { return $attribute->getFrontendInput() == 'multiselect' ? 'multiselect' : 'select'; } elseif ($attribute->isStatic()) { return $attribute->getFrontendInput() == 'date' ? 'datetime' : 'varchar'; } else { return $attribute->getBackendType(); } }