protected function validateCodePriceRule()
    {
        $field = 'code';
        $value = $this->getSubmitted($field);

        if (empty($value)) {
            return null;
        }

        $updating = $this->getUpdating();

        if (isset($updating['code']) && $updating['code'] === $value) {
            return true;
        }

        $label = $this->translation->text('Code');

        if (mb_strlen($value) > 255) {
            $this->setErrorLengthRange($field, $label, 0, 255);
            return false;
        }

        $rules = $this->price_rule->getList(array('code' => $value));

        if (empty($rules)) {
            return true;
        }

        foreach ((array) $rules as $rule) {
            if ($rule['code'] === $value) {
                $this->setErrorExists($field, $label);
                return false;
            }
        }

        return true;
    }