public function CommerceSmartImporerService::createDecimal in Commerce Smart Importer 8
Creates decimal value based on field settings.
1 call to CommerceSmartImporerService::createDecimal()
- CommerceSmartImporerService::formatField in src/
Plugin/ CommerceSmartImporerService.php - Formats one field value based on field settings.
File
- src/
Plugin/ CommerceSmartImporerService.php, line 672 - Main Commerce Smart Importer Service.
Class
- CommerceSmartImporerService
- This is main Commerce Smart Importer Service.
Namespace
Drupal\commerce_smart_importer\PluginCode
public function createDecimal($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 ($pass) {
return $number;
}
else {
throw new Exception($error);
}
}