You are here

function commerce_gc_line_item_set_price in Commerce GC 7

Set the price of a giftcard line item.

Parameters

array $price:

EntityDrupalWrapper $line_item_wrapper:

EntityDrupalWrapper $coupon_wrapper:

2 calls to commerce_gc_line_item_set_price()
commerce_gc_add_line_item in ./commerce_gc.module
Creates a giftcard use line item on the provided order.
commerce_gc_commerce_cart_order_refresh in ./commerce_gc.module

File

./commerce_gc.module, line 1056
Provides Giftcard coupon bundle, Giftcard Transaction entity and basic user interface elements.

Code

function commerce_gc_line_item_set_price($price, EntityDrupalWrapper $line_item_wrapper, EntityDrupalWrapper $coupon_wrapper) {

  // Initialize the line item unit price.
  $line_item_wrapper->commerce_unit_price->amount = $price['amount'];
  $line_item_wrapper->commerce_unit_price->currency_code = $price['currency_code'];

  // Reset the data array of the line item total field to only include a
  // base price component, set the currency code from the order.
  $base_price = array(
    'amount' => 0,
    'currency_code' => $price['currency_code'],
    'data' => array(),
  );
  $component_title = $coupon_wrapper->commerce_gc_name
    ->value() ? $coupon_wrapper->commerce_gc_name
    ->value() : 'giftcard';

  // Add some data elements to the price
  $price['data'] = array(
    'giftcard_component_title' => $component_title,
  );

  // Set components and save.
  $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add($base_price, 'giftcard', $price, TRUE);
}