You are here

public function CommerceSmartImporerService::createPhysicalMesurementLength in Commerce Smart Importer 8

Creates Length Physical Mesurement value based on field settings.

1 call to CommerceSmartImporerService::createPhysicalMesurementLength()
CommerceSmartImporerService::formatField in src/Plugin/CommerceSmartImporerService.php
Formats one field value based on field settings.

File

src/Plugin/CommerceSmartImporerService.php, line 828
Main Commerce Smart Importer Service.

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function createPhysicalMesurementLength($value, $field_settings) {
  $value = explode(' ', $value);
  if (count($value) != 2) {
    throw new Exception('Physical mesurement must have only value and unit(format: value unit)');
  }
  try {
    LengthUnit::assertExists($value[1]);
    return new Length($value[0], $value[1]);
  } catch (InvalidArgumentException $e) {
    throw new Exception($e
      ->getMessage());
  }
}