Exemplo n.º 1
0
 /**
  * Validate entity.
  * If the $partial parameter is TRUE, then we validate only those parameters that were passed.
  *
  * If fails validation, then this method returns false, and
  * getErrors() will return an array of errors that explain why the
  * validation failed.
  *
  * @param array $data
  * @param bool $partial
  * @return bool
  */
 public function isValidData(array $data, $partial = false)
 {
     $errors = array();
     foreach ($this->_eavForm->getAttributes() as $attribute) {
         if ($partial && !array_key_exists($attribute->getAttributeCode(), $data)) {
             continue;
         }
         if ($this->_eavForm->ignoreInvisible() && !$attribute->getIsVisible()) {
             continue;
         }
         $attrValue = isset($data[$attribute->getAttributeCode()]) ? $data[$attribute->getAttributeCode()] : null;
         $result = Mage_Eav_Model_Attribute_Data::factory($attribute, $this->_eavForm->getEntity())->setExtractedData($data)->validateValue($attrValue);
         if ($result !== true) {
             $errors = array_merge($errors, $result);
         } else {
             $result = $this->_validateAttributeWithSource($attribute, $attrValue);
             if (true !== $result) {
                 $errors = array_merge($errors, $result);
             }
         }
     }
     $this->_setErrors($errors);
     return $errors ? false : true;
 }
Exemplo n.º 2
0
 /**
  * Return attribute data model by attribute
  *
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @return Mage_Eav_Model_Attribute_Data_Abstract
  */
 protected function _getAttributeDataModel(Mage_Eav_Model_Entity_Attribute $attribute)
 {
     $dataModel = Mage_Eav_Model_Attribute_Data::factory($attribute, $this->getEntity());
     $dataModel->setIsAjaxRequest($this->getIsAjaxRequest());
     return $dataModel;
 }
Exemplo n.º 3
0
 /**
  * 
  * @param type $code
  * @param type $value
  * @param type $model
  * @return type
  */
 public function getAttributeOptionText($value, $attributeCode = 'select_customer_type', $entityType = 'customer')
 {
     $entityType = Mage::getModel('eav/config')->getEntityType($entityType);
     $entityTypeId = $entityType->getEntityTypeId();
     $attribute = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attributeCode)->setEntityTypeFilter($entityTypeId)->getFirstItem();
     $dataModel = Mage_Eav_Model_Attribute_Data::factory($attribute, $entityType);
     $dataModel->compactValue($value);
     $text = strtolower($dataModel->outputValue());
     if ($text == 'government institution') {
         $text = 'government';
     }
     if ($text == 'non-profit') {
         $text = 'nonprofit';
     }
     return $text;
 }