public function ProposedShipment::__construct in Commerce Shipping 8.2
Constructs a new ProposedShipment object.
Parameters
array $definition: The definition.
File
- src/
ProposedShipment.php, line 75
Class
- ProposedShipment
- Represents a proposed shipment.
Namespace
Drupal\commerce_shippingCode
public function __construct(array $definition) {
foreach ([
'type',
'order_id',
'title',
'items',
'shipping_profile',
] as $required_property) {
if (empty($definition[$required_property])) {
throw new \InvalidArgumentException(sprintf('Missing required property "%s".', $required_property));
}
}
foreach ($definition['items'] as $shipment_item) {
if (!$shipment_item instanceof ShipmentItem) {
throw new \InvalidArgumentException('Each shipment item under the "items" property must be an instance of ShipmentItem.');
}
}
$this->type = $definition['type'];
$this->orderId = $definition['order_id'];
$this->title = $definition['title'];
$this->items = $definition['items'];
$this->shippingProfile = $definition['shipping_profile'];
if (!empty($definition['package_type_id'])) {
$this->packageTypeId = $definition['package_type_id'];
}
if (!empty($definition['custom_fields'])) {
$this->customFields = $definition['custom_fields'];
}
}