You are here

function commerce_shipping_example_service_details_form_submit in Commerce Shipping 7.2

Shipping service callback.

Increases the shipping line item's unit price if express delivery was selected.

1 string reference to 'commerce_shipping_example_service_details_form_submit'
commerce_shipping_example_commerce_shipping_service_info in modules/commerce_shipping_example.module
Implements hook_commerce_shipping_service_info().

File

modules/commerce_shipping_example.module, line 109
Defines an example shipping method for testing and development.

Code

function commerce_shipping_example_service_details_form_submit($details_form, $details_values, $line_item) {
  if ($details_values['express']) {
    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);

    // Build a price array for the express delivery fee.
    $express_price = array(
      'amount' => 1500,
      'currency_code' => $line_item_wrapper->commerce_unit_price->currency_code
        ->value(),
      'data' => array(),
    );

    // Add the express upcharge to the line item unit price.
    $line_item_wrapper->commerce_unit_price->amount = $line_item_wrapper->commerce_unit_price->amount
      ->value() + 1500;

    // Add the express delivery fee component to the unit price.
    $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add($line_item_wrapper->commerce_unit_price
      ->value(), 'example_shipping_service_express', $express_price, TRUE, FALSE);
  }
}