You are here

function uc_order_line_item_add in Ubercart 8.4

Same name and namespace in other branches
  1. 5 uc_order/uc_order_line_item.inc \uc_order_line_item_add()
  2. 6.2 uc_order/uc_order.line_item.inc \uc_order_line_item_add()
  3. 7.3 uc_order/uc_order.line_item.inc \uc_order_line_item_add()

Adds a line item to an order.

5 calls to uc_order_line_item_add()
AddLineItemForm::submitForm in uc_order/src/Form/AddLineItemForm.php
Form submission handler.
LineItems::addLineItem in uc_order/src/Plugin/Ubercart/OrderPane/LineItems.php
Order pane submit callback: Add a line item to an order.
QuotePane::prepare in shipping/uc_quote/src/Plugin/Ubercart/CheckoutPane/QuotePane.php
Prepares a pane for display.
Quotes::applyQuote in shipping/uc_quote/src/Plugin/Ubercart/OrderPane/Quotes.php
Ajax callback: Manually applies a shipping quote to an order.
uc_tax_uc_order_update in uc_tax/uc_tax.module
Implements hook_uc_order_update().

File

uc_order/uc_order.line_item.inc, line 65
Callbacks and helper functions for the default order line items.

Code

function uc_order_line_item_add($order_id, $type, $title, $amount, $weight = NULL, $data = NULL) {
  if (is_null($weight)) {
    $line_item_manager = \Drupal::service('plugin.manager.uc_order.line_item');
    $weight = $line_item_manager
      ->getDefinition($type)['weight'];
  }
  $line_item = [
    'order_id' => $order_id,
    'type' => $type,
    'title' => $title,
    'amount' => $amount,
    'weight' => $weight,
    'data' => serialize($data),
  ];
  $line_item['line_item_id'] = db_insert('uc_order_line_items')
    ->fields($line_item)
    ->execute();
  $line_item['data'] = $data;
  return $line_item;
}