You are here

function commerce_shipping_line_item_populate in Commerce Shipping 7.2

Populates a shipping line item with the specified 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.

2 calls to commerce_shipping_line_item_populate()
commerce_shipping_line_item_add_form_submit in ./commerce_shipping.module
Adds the selected shipping information to a new shipping line item.
commerce_shipping_line_item_new in ./commerce_shipping.module
Creates a new shipping line item populated with the proper shipping values.

File

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

Code

function commerce_shipping_line_item_populate($line_item, $service, $unit_price) {

  // Use the label to store the display title of the shipping service.
  $line_item->line_item_label = commerce_shipping_service_get_title($service, 'display_title');
  $line_item->quantity = 1;

  // Store the full shipping status object in the data array.
  $line_item->data['shipping_service'] = commerce_shipping_service_load($service);

  // Set the service textfield and unit price.
  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  $line_item_wrapper->commerce_shipping_service = $service;
  $line_item_wrapper->commerce_unit_price = $unit_price;
}