public function CommerceSmartImporerService::createPhysicalDimension in Commerce Smart Importer 8
Creates physical dimension value based on field settings.
1 call to CommerceSmartImporerService::createPhysicalDimension()
- CommerceSmartImporerService::formatField in src/
Plugin/ CommerceSmartImporerService.php - Formats one field value based on field settings.
File
- src/
Plugin/ CommerceSmartImporerService.php, line 372 - Main Commerce Smart Importer Service.
Class
- CommerceSmartImporerService
- This is main Commerce Smart Importer Service.
Namespace
Drupal\commerce_smart_importer\PluginCode
public function createPhysicalDimension($value, $field_settings) {
$field_value = [];
$value = explode(' ', $value);
if (count($value) != 2) {
throw new Exception('Dimension is in wrong format. Follow "LxWxH [unit]". For example 4x5x6 m.');
}
else {
$split_value = explode('x', $value[0]);
if (count($split_value) != 3) {
throw new Exception('Length, width and height values are required in the format "LxWxH [unit]."');
}
else {
$field_value['length'] = $split_value[0];
$field_value['width'] = $split_value[1];
$field_value['height'] = $split_value[2];
$field_value['unit'] = $value[1];
return $field_value;
}
}
}