Programmatically adding line items to Ubercart order Can someone please suggest how do we add line items to an Ubercart order in Drupal 8? When I look at the references in Ubercart module, I get this:

// Load line items... has to be last after everything has been loaded.
$order-&gt;line_items = $order-&gt;getLineItems();


I am already setting product details to the order. However when I set line items by above line of code, system doesn't allow me to proceed ahead and doesn't even show any error.

Thanks in advance for any help or suggestions.
The issue was I was assigning the value in order total manually from the product details, instead of using ubercart's $order->getTotal() , which defines line item initially. Hence, this worked for me to get the order generated after setting product and other payment details in order:

$order-&gt;total               = $order-&gt;getTotal();
$order-&gt;line_items          = $order-&gt;getLineItems();
$order-&gt;save();