protected function validateCityAddress()
    {
        $field = 'city_id';

        if ($this->isExcluded($field) || $this->isError('country')) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('City');
        $format = $this->getCountryFormatAddress();

        if (empty($value) && !empty($format['city_id']['required'])) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        // City ID can be either numeric ID or non-numeric human name
        if (is_numeric($value)) {
            if ($this->city->get($value)) {
                return true;
            }
            $this->setErrorUnavailable($field, $label);
            return false;
        }

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

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

        // Try to convert human name to a numeric ID
        $country = $this->getSubmitted('country');
        $state_id = $this->getSubmitted('state_id');

        if (empty($country) || empty($state_id)) {
            return true;
        }

        $conditions = array(
            'name' => $value,
            'country' => $country,
            'state_id' => $state_id
        );

        foreach ((array) $this->city->getList($conditions) as $city) {
            if (strcasecmp($city['name'], $value) === 0) {
                $this->setSubmitted($field, $city['city_id']);
                break;
            }
        }

        return true;
    }
protected function validateCityAddress()
    {
        $field = 'city_id';

        if ($this->isExcluded($field) || $this->isError('country')) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('City');
        $format = $this->getCountryFormatAddress();

        if (empty($value) && !empty($format['city_id']['required'])) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        // City ID can be either numeric ID or non-numeric human name
        if (is_numeric($value)) {
            if ($this->city->get($value)) {
                return true;
            }
            $this->setErrorUnavailable($field, $label);
            return false;
        }

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

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

        // Try to convert human name to a numeric ID
        $country = $this->getSubmitted('country');
        $state_id = $this->getSubmitted('state_id');

        if (empty($country) || empty($state_id)) {
            return true;
        }

        $conditions = array(
            'name' => $value,
            'country' => $country,
            'state_id' => $state_id
        );

        foreach ((array) $this->city->getList($conditions) as $city) {
            if (strcasecmp($city['name'], $value) === 0) {
                $this->setSubmitted($field, $city['city_id']);
                break;
            }
        }

        return true;
    }
protected function validateCityAddress ( ) { $ field = 'city_id' ; if ( $ this -> isExcluded ( $ field ) || $ this -> isError ( 'country' ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isUpdating ( ) && ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'City' ) ; $ format = $ this -> getCountryFormatAddress ( ) ; if ( empty ( $ value ) && ! empty ( $ format [ 'city_id' ] [ 'required' ] ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } // City ID can be either numeric ID or non-numeric human name if ( is_numeric ( $ value ) ) { if ( $ this -> city -> get ( $ value ) ) { return true ; } $ this -> setErrorUnavailable ( $ field , $ label ) ; return false ; } if ( empty ( $ value ) ) { return true ; } if ( mb_strlen ( $ value ) > 255 ) { $ this -> setErrorLengthRange ( $ field , $ label ) ; return false ; } // Try to convert human name to a numeric ID $ country = $ this -> getSubmitted ( 'country' ) ; $ state_id = $ this -> getSubmitted ( 'state_id' ) ; if ( empty ( $ country ) || empty ( $ state_id ) ) { return true ; } $ conditions = array ( 'name' => $ value , 'country' => $ country , 'state_id' => $ state_id ) ; foreach ( ( array ) $ this -> city -> getList ( $ conditions ) as $ city ) { if ( strcasecmp ( $ city [ 'name' ] , $ value ) === 0 ) { $ this -> setSubmitted ( $ field , $ city [ 'city_id' ] ) ; break ; } } return true ; }
Validates a city
@return boolean|null
Validates a city