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->line_items = $order->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->total               = $order->getTotal();
$order->line_items          = $order->getLineItems();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.