public function OrderItemStorage::createFromPurchasableEntity in Commerce Core 8.2
Constructs a new order item using the given purchasable entity.
The new order item isn't saved.
Parameters
\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity.
array $values: (optional) An array of values to set, keyed by property name.
Return value
\Drupal\commerce_order\Entity\OrderItemInterface The created order item.
Overrides OrderItemStorageInterface::createFromPurchasableEntity
File
- modules/
order/ src/ OrderItemStorage.php, line 16
Class
- OrderItemStorage
- Defines the order item storage.
Namespace
Drupal\commerce_orderCode
public function createFromPurchasableEntity(PurchasableEntityInterface $entity, array $values = []) {
$values += [
'type' => $entity
->getOrderItemTypeId(),
'title' => $entity
->getOrderItemTitle(),
'purchased_entity' => $entity,
'unit_price' => $entity
->getPrice(),
];
return self::create($values);
}