コード例 #1
0
ファイル: Multiline.php プロジェクト: jpbender/mage_virtual
 /**
  * Validate data
  * Return true or array of errors
  *
  * @param array|string $value
  * @return boolean|array
  */
 public function validateValue($value)
 {
     $errors = array();
     $attribute = $this->getAttribute();
     if ($value === false) {
         // try to load original value and validate it
         $value = $this->getEntity()->getDataUsingMethod($attribute->getAttributeCode());
         if (!is_array($value)) {
             $value = explode("\n", $value);
         }
     }
     for ($i = 0; $i < $attribute->getMultilineCount(); $i++) {
         if (!isset($value[$i])) {
             $value[$i] = null;
         }
         // validate first line
         if ($i == 0) {
             $result = parent::validateValue($value[$i]);
             if ($result !== true) {
                 $errors = $result;
             }
         } else {
             if (!empty($value[$i])) {
                 $result = parent::validateValue($value[$i]);
                 if ($result !== true) {
                     $errors = array_merge($errors, $result);
                 }
             }
         }
     }
     if (count($errors) == 0) {
         return true;
     }
     return $errors;
 }
コード例 #2
0
ファイル: Postcode.php プロジェクト: jpbender/mage_virtual
 /**
  * Validate postal/zip code
  * Return true and skip validation if country zip code is optional
  *
  * @param array|string $value
  * @return boolean|array
  */
 public function validateValue($value)
 {
     $countryId = $this->getExtractedData('country_id');
     $optionalZip = Mage::helper('directory')->getCountriesWithOptionalZip();
     if (!in_array($countryId, $optionalZip)) {
         return parent::validateValue($value);
     }
     return true;
 }