public static function addOptionValidation(RequestValidator $validator, $option, $fieldName) { $app = ActiveRecordModel::getApplication(); if (ProductOption::TYPE_FILE == $option['type']) { $checks = array(new IsFileUploadedCheck($app->translate('_err_option_upload')), new IsNotEmptyCheck($app->translate('_err_option_upload'))); $validator->addCheck($fieldName, new OrCheck(array('upload_' . $fieldName, $fieldName), $checks, $validator->getRequest())); if ($types = ProductOption::getFileExtensions($option['fileExtensions'])) { $validator->addCheck('upload_' . $fieldName, new IsFileTypeValidCheck($app->maketext('_err_option_filetype', implode(', ', $types)), $types)); } $validator->addCheck('upload_' . $fieldName, new MaxFileSizeCheck($app->maketext('_err_option_filesize', $option['maxFileSize']), $option['maxFileSize'])); } else { $validator->addCheck($fieldName, new IsNotEmptyCheck($app->translate('_err_option_' . $option['type']))); } }
public function setValidation(RequestValidator $validator, $filtersOnly = false, $fieldPrefix = '') { $specFields = $this->getSpecificationFieldSet(ActiveRecordModel::LOAD_REFERENCES); $application = ActiveRecordModel::getApplication(); foreach ($specFields as $key => $field) { $fieldname = $fieldPrefix . $field->getFormFieldName(); // validate numeric values if (EavFieldCommon::TYPE_NUMBERS_SIMPLE == $field->type->get()) { if (!$filtersOnly) { $validator->addCheck($fieldname, new IsNumericCheck($application->translate('_err_numeric'))); } $validator->addFilter($fieldname, new NumericFilter()); } // validate required fields if ($field->isRequired->get() && !$filtersOnly) { if (!($field->isSelector() && $field->isMultiValue->get())) { $validator->addCheck($fieldname, new IsNotEmptyCheck($application->translate('_err_specfield_required'))); } else { ClassLoader::import('application.helper.check.SpecFieldIsValueSelectedCheck'); $validator->addCheck($fieldname, new SpecFieldIsValueSelectedCheck($application->translate('_err_specfield_multivaluerequired'), $field, $application->getRequest())); } } } }
public function addInventoryValidator(RequestValidator $validator) { if ($this->config->get('INVENTORY_TRACKING') != 'DISABLE') { $validator->addCheck('stockCount', new IsNotEmptyCheck($this->translate('_err_stock_required'))); $validator->addCheck('stockCount', new IsNumericCheck($this->translate('_err_stock_not_numeric'))); $validator->addCheck('stockCount', new MinValueCheck($this->translate('_err_stock_negative'), 0)); } $validator->addFilter('stockCount', new NumericFilter()); return $validator; }
private function validatePassword(RequestValidator $validator) { ClassLoader::import("application.helper.check.PasswordMatchCheck"); $validator->addCheck('password', new MinLengthCheck(sprintf($this->translate('_err_short_password'), self::PASSWORD_MIN_LENGTH), self::PASSWORD_MIN_LENGTH)); $validator->addCheck('password', new IsNotEmptyCheck($this->translate('_err_enter_password'))); $validator->addCheck('confpassword', new IsNotEmptyCheck($this->translate('_err_enter_password'))); $validator->addCheck('confpassword', new PasswordMatchCheck($this->translate('_err_password_match'), $this->request, 'password', 'confpassword')); }
protected function validateAddress(RequestValidator $validator, $prefix) { $someValidator = $this->getValidator('foo', $this->request); ClassLoader::import('application.controller.UserController'); $con = new UserController($this->application); $con->validateAddress($someValidator, $prefix, 'shipping_' == $prefix); foreach ($someValidator->getValidatorVars() as $field => $var) { foreach ($var->getChecks() as $check) { $validator->addCheck($field, new OrCheck(array($field, substr($prefix, 0, -1) . 'Address'), array($check, new IsNotEmptyCheck('')), $this->request)); } } }
private function setFieldValidation(RequestValidator $validator, Tax $tax, TaxClass $class = null) { $field = $this->getFieldName($tax, $class); $validator->addCheck($field, new IsNumericCheck($this->translate("_error_rate_should_be_numeric_value"))); $validator->addCheck($field, new MinValueCheck($this->translate("_error_rate_should_be_greater_than_zero"), 0)); $validator->addFilter($field, new NumericFilter()); }