You are here

function commerce_shipping_line_item_new in Commerce Shipping 7.2

Same name and namespace in other branches
  1. 7 commerce_shipping.module \commerce_shipping_line_item_new()

Creates a new shipping line item populated with the proper shipping values.

Parameters

string $service: The machine-name of the shipping service the line item represents.

array $unit_price: A price array used to initialize the value of the line item's unit price.

int $order_id: The ID of the order the line item belongs to.

array $data: An array value to initialize the line item's data array with.

string $type: The name of the line item type being created; defaults to 'shipping'.

Return value

Object The shipping line item for the specified service initialized to the given unit price.

3 calls to commerce_shipping_line_item_new()
commerce_shipping_pane_checkout_form_submit in includes/commerce_shipping.checkout_pane.inc
Checkout pane callback: submit the shipping checkout pane.
commerce_shipping_rate_apply in ./commerce_shipping.rules.inc
Action: Apply a shipping rate to an order.
commerce_shipping_service_rate_calculate in ./commerce_shipping.module
Creates a shipping line item and passes it through Rules.

File

./commerce_shipping.module, line 961
Defines a system for calculating shipping costs associated with an order.

Code

function commerce_shipping_line_item_new($service, $unit_price, $order_id = 0, $data = array(), $type = 'shipping') {

  // Ensure a default product line item type.
  if (empty($type)) {
    $type = 'shipping';
  }

  // Create the new line item.
  $line_item = entity_create('commerce_line_item', array(
    'type' => $type,
    'order_id' => $order_id,
    'quantity' => 1,
    'data' => $data,
  ));

  // Populate it with the shipping service and unit price data.
  commerce_shipping_line_item_populate($line_item, $service, $unit_price);

  // Allow other modules to add additional data to the line item if necessary.
  drupal_alter('commerce_shipping_line_item_new', $line_item);

  // Return the line item.
  return $line_item;
}