Validates a submitted price rule
@return bool
354917
protected function validateEditPriceRule()
    {
        $this->setSubmitted('price_rule', null, false);
        $this->setSubmittedBool('status');
        $this->setSubmitted('update', $this->data_rule);

        $this->validateComponent('price_rule');

        return !$this->hasErrors();
    }
680313
protected function addPriceRule()
    {
        $this->controlAccess('price_rule_add');

        if ($this->price_rule->add($this->getSubmitted())) {
            $this->redirect('admin/sale/price', $this->text('Price rule has been added'), 'success');
        }

        $this->redirect('', $this->text('Price rule has not been added'), 'warning');
    }
1134642
public static function validate($price)
    {
        if (
            (\filter_var($price, FILTER_VALIDATE_FLOAT) || \filter_var($price, FILTER_VALIDATE_INT))
            && $price >= 0
        ) {
            return $price;
        }

        return false;
    }
153573
public function priceRule(array &$submitted, array $options = array())
    {
        $this->options = $options;
        $this->submitted = &$submitted;

        $this->validatePriceRule();
        $this->validateName();
        $this->validateWeight();
        $this->validateBool('status');
        $this->validateUsedPriceRule();
        $this->validateTriggerPriceRule();
        $this->validateCurrencyPriceRule();
        $this->validateValueTypePriceRule();
        $this->validateCodePriceRule();
        $this->validateValuePriceRule();

        $this->unsetSubmitted('update');

        return $this->getResult();
    }
730898
protected function getListPriceRule()
    {
        $conditions = $this->query_filter;
        $conditions['limit'] = $this->data_limit;

        return (array) $this->price_rule->getList($conditions);
    }
137268
public function validate()
    {
        if (!parent::validate()) {
            return false;
        }
        if ($this->hasPaymentToken()) {
            if ($this->hasPaymentMethodId()) {
                $this->setValidationError('Both paymentToken and paymentMethodID values are specified');
                return false;
            }
            if ($this->hasPaymentMethodData()) {
                $this->setValidationError('Both paymentToken and paymentData values are specified');
                return false;
            }
        } elseif ($this->hasPaymentMethodId()) {
            if ($this->hasPaymentMethodData()) {
                $this->setValidationError('Both paymentMethodID and paymentData values are specified');
                return false;
            }
        }
        return true;
    }
249158
public function isPayPalCheckValid()
    {
        $newBasketAmount = $this->getNewBasketAmount();
        $prevBasketAmount = $this->getOldBasketAmount();
        // check only if new price is different and bigger than old price
        if ($newBasketAmount > $prevBasketAmount) {
            return false;
        }

        return true;
    }
110207
public function cmdUpdatePriceRule()
    {
        $params = $this->getParam();

        if (empty($params[0]) || count($params) < 2) {
            $this->errorAndExit($this->text('Invalid command'));
        }

        if (!is_numeric($params[0])) {
            $this->errorAndExit($this->text('Invalid argument'));
        }

        $this->setSubmitted(null, $params);
        $this->setSubmitted('update', $params[0]);
        $this->validateComponent('price_rule');

        $this->updatePriceRule($params[0]);
        $this->output();
    }
1062763
protected function validateSubtractProduct()
    {
        $field = 'subtract';
        $value = $this->getSubmitted($field);

        if (isset($value)) {
            $this->setSubmitted($field, filter_var($value, FILTER_VALIDATE_BOOLEAN));
        }

        return true;
    }
584283
protected function validateOwner()
    {
        if (0 == ($valueLength = strlen($this->owner->getValue()))) {
            return true;
        }

        $allowedLength = $this->getConfig();
        if (is_scalar($allowedLength)) {
            return $valueLength == $allowedLength;
        } else {
            return (empty($allowedLength['min']) || $valueLength >= $allowedLength['min']) &&
                   (empty($allowedLength['max']) || $valueLength <= $allowedLength['max']);
        }
    }
416415
public function isValid()
    {
        $value = $this->field->getValue();

        if (is_array($value) || is_object($value)) {
            throw new \Exception("This validator only works on scalar types!");
        }

        // required but not given.
        if ($this->required && strval($value) === "") {
            return false;
        } // if the field is not required and the value is empty, then it's also valid
        elseif (!$this->required && strval($value) === '') {
            return true;
        }

        // check if the field contains a valid number value.
        if (!preg_match($this->getRegex(), $value)) {
            return false;
        }

        // check if the value is not to low.
        if ($this->isValueTooLow($value)) {
            return false;
        }

        // check if the value is not to high.
        if ($this->isValueTooHigh($value)) {
            return false;
        }

        return true;
    }
756654
protected function getListPriceRule()
    {
        $id = $this->getParam(0);

        if (!isset($id)) {
            return $this->price_rule->getList(array('limit' => $this->getLimit()));
        }

        if (!is_numeric($id)) {
            $this->errorAndExit($this->text('Invalid argument'));
        }

        if ($this->getParam('trigger')) {
            return $this->price_rule->getList(array('trigger_id' => $id, 'limit' => $this->getLimit()));
        }

        $result = $this->price_rule->get($id);

        if (empty($result)) {
            $this->errorAndExit($this->text('Unexpected result'));
        }

        return array($result);
    }
525291
protected function validateEditProduct()
    {
        $this->setSubmitted('product', null, false);
        $this->setSubmittedBool('status');
        $this->setSubmittedBool('subtract');
        $this->setSubmitted('form', true);
        $this->setSubmitted('update', $this->data_product);

        if (isset($this->data_product['product_id'])) {
            $this->setSubmitted('user_id', $this->data_product['user_id']);
            $this->setSubmitted('created', $this->data_product['created']);
            $this->setSubmitted('modified', $this->data_product['modified']);
            $this->setSubmitted('currency', $this->data_product['currency']);
            $this->setSubmitted('product_id', $this->data_product['product_id']);
        } else {
            $this->setSubmitted('user_id', $this->uid);
            $this->setSubmitted('currency', $this->currency->getDefault());
        }

        $this->validateComponent('product');

        return !$this->hasErrors();
    }
654834
public function validateValidItem()
    {
        if (!$this->value) {
            return;
        }

        // load allowed values in values_list
        // @todo Imants: Actually we don't need to load all values from Model in
        //       array, just to check couple of posted values.
        //       Probably we should do SELECT * FROM t WHERE id IN ($values) or
        //       something like that to limit array size and time spent on
        //       parsing all DB records in Model.
        $this->getValueList();

        $values = explode($this->separator, $this->value);
        foreach ($values as $v) {
            if (!isset($this->value_list[$v])) {
                $this->displayFieldError("Value $v is not one of the offered values");

                return $this->validate();
            }
        }
    }
344008
public function validate()
    {
        $confirmationInput = $this->inputName.'_confirmation';

        if (isset($this->input[$confirmationInput]) &&
            $this->input[$confirmationInput] == $this->getValue()) {
            return true;
        }

        return false;
    }
899645
protected function validateRequired()
  {
    if ($this->isRequired() && empty($this->value)) {
      $this->addError(sprintf($this->tmpl_err_required, $this->getName()));

      return false;
    }

    return true;
  }
556877
protected function validateEditCurrency()
    {
        $this->setSubmitted('currency');
        $this->setSubmittedBool('status');
        $this->setSubmittedBool('default');
        $this->setSubmitted('update', $this->data_currency);

        $this->validateComponent('currency');

        return !$this->hasErrors();
    }