コード例 #1
0
 /**
  * Return EAV entity Form instance
  *
  * @return Mage_Eav_Model_Form
  */
 public function getForm()
 {
     if (is_null($this->_form)) {
         $this->_form = Mage::getModel($this->_formModelPath)->setFormCode($this->_formCode)->setEntity($this->getEntity());
         if ($this->_entityType) {
             $this->_form->setEntityType($this->_entityType);
         }
         $this->_form->initDefaultValues();
     }
     return $this->_form;
 }
コード例 #2
0
 /**
  * Test validateData method
  *
  * @dataProvider validateDataProvider
  *
  * @param bool $isValid
  * @param bool|array $expected
  * @param null|array $messages
  */
 public function testValidateDataPassed($isValid, $expected, $messages = null)
 {
     $validator = $this->getMockBuilder('Mage_Eav_Model_Validator_Attribute_Data')->disableOriginalConstructor()->setMethods(array('isValid', 'getMessages'))->getMock();
     $validator->expects($this->once())->method('isValid')->will($this->returnValue($isValid));
     if ($messages) {
         $validator->expects($this->once())->method('getMessages')->will($this->returnValue($messages));
     } else {
         $validator->expects($this->never())->method('getMessages');
     }
     $this->_model->expects($this->once())->method('_getValidator')->will($this->returnValue($validator));
     $data = array('test' => true);
     $this->assertEquals($expected, $this->_model->validateData($data));
 }
コード例 #3
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;
 }
コード例 #4
0
ファイル: Form.php プロジェクト: relue/magento2
 /**
  * Get EAV Entity Form Attribute Collection for Customer
  * exclude 'created_at'
  *
  * @return Mage_Customer_Model_Resource_Form_Attribute_Collection
  */
 protected function _getFormAttributeCollection()
 {
     return parent::_getFormAttributeCollection()->addFieldToFilter('attribute_code', array('neq' => 'created_at'));
 }