final class ShipmentItem in Commerce Shipping 8.2
Same name in this branch
- 8.2 src/ShipmentItem.php \Drupal\commerce_shipping\ShipmentItem
- 8.2 src/Plugin/DataType/ShipmentItem.php \Drupal\commerce_shipping\Plugin\DataType\ShipmentItem
- 8.2 src/Plugin/Field/FieldType/ShipmentItem.php \Drupal\commerce_shipping\Plugin\Field\FieldType\ShipmentItem
Represents a shipment item.
Hierarchy
- class \Drupal\commerce_shipping\ShipmentItem
Expanded class hierarchy of ShipmentItem
24 files declare their use of ShipmentItem
- DefaultPacker.php in src/
Packer/ DefaultPacker.php - DefaultPackerTest.php in tests/
src/ Unit/ Packer/ DefaultPackerTest.php - FilterShippingMethodsEventTest.php in tests/
src/ Kernel/ FilterShippingMethodsEventTest.php - OrderShipmentSummaryTest.php in tests/
src/ Kernel/ OrderShipmentSummaryTest.php - OrderWorkflowTest.php in tests/
src/ Kernel/ OrderWorkflowTest.php
File
- src/
ShipmentItem.php, line 11
Namespace
Drupal\commerce_shippingView source
final class ShipmentItem {
/**
* The source order item ID.
*
* @var int
*/
protected $orderItemId;
/**
* The title.
*
* @var string
*/
protected $title;
/**
* The quantity.
*
* @var string
*/
protected $quantity;
/**
* The weight.
*
* @var \Drupal\physical\Weight
*/
protected $weight;
/**
* The declared value.
*
* @var \Drupal\commerce_price\Price
*/
protected $declaredValue;
/**
* The tariff code.
*
* @var string
*/
protected $tariffCode;
/**
* Constructs a new ShipmentItem object.
*
* @param array $definition
* The definition.
*/
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'];
}
}
/**
* Gets the source order item ID.
*
* Note that an order item might correspond to multiple shipment items,
* depending on the used packer.
*
* @return int
* The order item ID.
*/
public function getOrderItemId() : int {
return $this->orderItemId;
}
/**
* Gets the title.
*
* Can be used on customs forms as a description.
*
* @return string
* The title.
*/
public function getTitle() : string {
return $this->title;
}
/**
* Gets the quantity.
*
* @return string
* The quantity.
*/
public function getQuantity() : string {
return $this->quantity;
}
/**
* Gets the weight.
*
* Represents the weight of the entire shipment item (unit weight * quantity).
*
* @return \Drupal\physical\Weight
* The weight.
*/
public function getWeight() : Weight {
return $this->weight;
}
/**
* Gets the declared value.
*
* Represents the value of the entire shipment item (unit value * quantity).
* Needed on customs forms.
*
* @return \Drupal\commerce_price\Price
* The declared value.
*/
public function getDeclaredValue() : Price {
return $this->declaredValue;
}
/**
* Gets the tariff code.
*
* This could be a Harmonized System (HS) code, or a Harmonized Tariff
* Schedule (HTS) code. Needed on customs forms.
*
* @return string|null
* The tariff code, or NULL if not defined.
*/
public function getTariffCode() {
return $this->tariffCode;
}
/**
* Gets the array representation of the shipment item.
*
* @return array
* The array representation of the shipment item.
*/
public function toArray() {
return [
'order_item_id' => $this
->getOrderItemId(),
'title' => $this
->getTitle(),
'quantity' => $this
->getQuantity(),
'weight' => $this
->getWeight()
->toArray(),
'declared_value' => $this
->getDeclaredValue()
->toArray(),
'tariff_code' => $this
->getTariffCode(),
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ShipmentItem:: |
protected | property | The declared value. | |
ShipmentItem:: |
protected | property | The source order item ID. | |
ShipmentItem:: |
protected | property | The quantity. | |
ShipmentItem:: |
protected | property | The tariff code. | |
ShipmentItem:: |
protected | property | The title. | |
ShipmentItem:: |
protected | property | The weight. | |
ShipmentItem:: |
public | function | Gets the declared value. | |
ShipmentItem:: |
public | function | Gets the source order item ID. | |
ShipmentItem:: |
public | function | Gets the quantity. | |
ShipmentItem:: |
public | function | Gets the tariff code. | |
ShipmentItem:: |
public | function | Gets the title. | |
ShipmentItem:: |
public | function | Gets the weight. | |
ShipmentItem:: |
public | function | Gets the array representation of the shipment item. | |
ShipmentItem:: |
public | function | Constructs a new ShipmentItem object. |