class ProposedShipment in Commerce Shipping 8.2
Represents a proposed shipment.
Proposed shipments are returned from the packing process, and then mapped to new or existing shipment entities. This allows the packers to be run whenever the order changes, while only modifying the shipments if they have changed.
Hierarchy
- class \Drupal\commerce_shipping\ProposedShipment
Expanded class hierarchy of ProposedShipment
8 files declare their use of ProposedShipment
- DefaultPacker.php in src/
Packer/ DefaultPacker.php - DefaultPackerTest.php in tests/
src/ Unit/ Packer/ DefaultPackerTest.php - PackerManagerTest.php in tests/
src/ Kernel/ PackerManagerTest.php - ProposedShipmentTest.php in tests/
src/ Unit/ ProposedShipmentTest.php - Shipment.php in src/
Entity/ Shipment.php
File
- src/
ProposedShipment.php, line 15
Namespace
Drupal\commerce_shippingView source
class ProposedShipment {
/**
* The shipment type.
*
* @var string
*/
protected $type;
/**
* The order ID.
*
* @var int
*/
protected $orderId;
/**
* The shipment title.
*
* @var string
*/
protected $title;
/**
* The shipment items.
*
* @var \Drupal\commerce_shipping\ShipmentItem[]
*/
protected $items = [];
/**
* The shipping profile.
*
* We can't store just the profile ID because
* the profile entity might not be saved yet.
*
* @var \Drupal\profile\Entity\ProfileInterface
*/
protected $shippingProfile;
/**
* The package type plugin ID.
*
* @var string
*/
protected $packageTypeId;
/**
* The custom fields.
*
* @var array
*/
protected $customFields = [];
/**
* Constructs a new ProposedShipment object.
*
* @param array $definition
* The definition.
*/
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'];
}
}
/**
* Gets the shipment type.
*
* @return string
* The shipment type.
*/
public function getType() : string {
return $this->type;
}
/**
* Gets the parent order ID.
*
* @return int
* The order ID.
*/
public function getOrderId() : int {
return $this->orderId;
}
/**
* Gets the shipment title.
*
* @return string
* The shipment title.
*/
public function getTitle() : string {
return $this->title;
}
/**
* Gets the shipment items.
*
* @return \Drupal\commerce_shipping\ShipmentItem[]
* The shipment items.
*/
public function getItems() : array {
return $this->items;
}
/**
* Gets the shipping profile.
*
* @return \Drupal\profile\Entity\ProfileInterface
* The shipping profile.
*/
public function getShippingProfile() : ProfileInterface {
return $this->shippingProfile;
}
/**
* Gets the package type plugin ID.
*
* If the proposed shipment returns no package type ID, shipping methods
* are expected to use their default package type.
*
* @return string|null
* The package type plugin ID, or NULL if unknown.
*/
public function getPackageTypeId() {
return $this->packageTypeId;
}
/**
* Gets the custom fields.
*
* @return array
* The custom fields, in the $field_name => $value format.
*/
public function getCustomFields() : array {
return $this->customFields;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ProposedShipment:: |
protected | property | The custom fields. | |
ProposedShipment:: |
protected | property | The shipment items. | |
ProposedShipment:: |
protected | property | The order ID. | |
ProposedShipment:: |
protected | property | The package type plugin ID. | |
ProposedShipment:: |
protected | property | The shipping profile. | |
ProposedShipment:: |
protected | property | The shipment title. | |
ProposedShipment:: |
protected | property | The shipment type. | |
ProposedShipment:: |
public | function | Gets the custom fields. | |
ProposedShipment:: |
public | function | Gets the shipment items. | |
ProposedShipment:: |
public | function | Gets the parent order ID. | |
ProposedShipment:: |
public | function | Gets the package type plugin ID. | |
ProposedShipment:: |
public | function | Gets the shipping profile. | |
ProposedShipment:: |
public | function | Gets the shipment title. | |
ProposedShipment:: |
public | function | Gets the shipment type. | |
ProposedShipment:: |
public | function | Constructs a new ProposedShipment object. |