Ejemplo n.º 1
0
 /**
  * Validate EAV model attributes with data models
  *
  * @param \Magento\Framework\Model\AbstractModel $entity
  * @return bool
  */
 public function isValid($entity)
 {
     /** @var $attributes Attribute[] */
     $attributes = $this->_getAttributes($entity);
     $data = [];
     if ($this->_data) {
         $data = $this->_data;
     } elseif ($entity instanceof \Magento\Framework\DataObject) {
         $data = $entity->getData();
     }
     foreach ($attributes as $attribute) {
         $attributeCode = $attribute->getAttributeCode();
         if (!$attribute->getDataModel() && !$attribute->getFrontendInput()) {
             continue;
         }
         $dataModel = $this->_attrDataFactory->create($attribute, $entity);
         $dataModel->setExtractedData($data);
         if (!isset($data[$attributeCode])) {
             $data[$attributeCode] = null;
         }
         $result = $dataModel->validateValue($data[$attributeCode]);
         if (true !== $result) {
             $this->_addErrorMessages($attributeCode, (array) $result);
         }
     }
     return count($this->_messages) == 0;
 }
Ejemplo n.º 2
0
 /**
  * Return attribute data model by attribute
  *
  * @param \Magento\Eav\Model\Entity\Attribute $attribute
  * @return \Magento\Eav\Model\Attribute\Data\AbstractData
  */
 protected function _getAttributeDataModel(\Magento\Eav\Model\Entity\Attribute $attribute)
 {
     $dataModel = $this->_attrDataFactory->create($attribute, $this->getEntity());
     $dataModel->setIsAjaxRequest($this->getIsAjaxRequest());
     return $dataModel;
 }