public function __construct( protected string
$id,
protected string
$type,
protected ?string
$referencedId = null,
int
$quantity = 1
) { $this->uniqueIdentifier = Uuid::
randomHex();
$this->children =
new LineItemCollection();
if ($quantity < 1
) { throw CartException::
invalidQuantity($quantity);
} $this->quantity =
$quantity;
} /**
* @throws CartException
*/
public static function createFromLineItem(LineItem
$lineItem): self
{ $self =
new self($lineItem->id,
$lineItem->type,
$lineItem->
getReferencedId(),
$lineItem->quantity
);