You are here

function merci_line_item_entity_insert in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

File

merci_line_item/merci_line_item.module, line 44
Defines the core MERCI line item entity and API functions interact with line items.

Code

function merci_line_item_entity_insert($entity, $type) {
  $field_items = field_get_items($type, $entity, MERCI_LINE_ITEM_REFERENCE);
  if ($field_items) {
    $entity_wrapper = entity_metadata_wrapper($type, $entity);
    $line_item_ids = array();
    foreach ($field_items as $item) {
      $line_item_ids[] = $item['target_id'];
    }
    $line_items = merci_line_item_load_multiple($line_item_ids);
    foreach ($line_items as $line_item) {
      $line_item->entity_id = $entity_wrapper
        ->getIdentifier();
      merci_line_item_save($line_item);
    }
  }
}