public function CommerceSmartImporerService::createInteger in Commerce Smart Importer 8
Creates integer value based on field settings.
1 call to CommerceSmartImporerService::createInteger()
- CommerceSmartImporerService::formatField in src/
Plugin/ CommerceSmartImporerService.php - Formats one field value based on field settings.
File
- src/
Plugin/ CommerceSmartImporerService.php, line 638 - Main Commerce Smart Importer Service.
Class
- CommerceSmartImporerService
- This is main Commerce Smart Importer Service.
Namespace
Drupal\commerce_smart_importer\PluginCode
public function createInteger($number, $field_settings) {
$pass = TRUE;
if (!is_numeric($number)) {
$error = 'Must be number';
throw new Exception($error);
}
else {
if (!empty($field_settings['min'])) {
if ($number < $field_settings['min']) {
$error = 'Must be greater than ' . $field_settings['min'];
$pass = FALSE;
}
}
if (!empty($field_settings['max'])) {
if ($number > $field_settings['max']) {
$error = 'Must be smaller than ' . $field_settings['max'];
$pass = FALSE;
}
}
}
if ($field_settings['unsigned'] == TRUE) {
$number = abs($number);
}
if ($pass) {
return round($number);
}
else {
throw new Exception($error);
}
}