You are here

public function ShipmentItem::__construct in Commerce Shipping 8.2

Constructs a new ShipmentItem object.

Parameters

array $definition: The definition.

File

src/ShipmentItem.php, line 61

Class

ShipmentItem
Represents a shipment item.

Namespace

Drupal\commerce_shipping

Code

public function __construct(array $definition) {
  foreach ([
    'order_item_id',
    'title',
    'quantity',
    'weight',
    'declared_value',
  ] as $required_property) {
    if (empty($definition[$required_property])) {
      throw new \InvalidArgumentException(sprintf('Missing required property "%s".', $required_property));
    }
  }
  $this->orderItemId = $definition['order_item_id'];
  $this->title = $definition['title'];
  $this->quantity = $definition['quantity'];
  $this->weight = $definition['weight'];
  $this->declaredValue = $definition['declared_value'];
  if (!empty($definition['tariff_code'])) {
    $this->tariffCode = $definition['tariff_code'];
  }
}