You are here

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

File

merci_commerce/merci_commerce.module, line 10

Code

function merci_commerce_merci_line_item_validate($line_item, $form, &$form_state) {
  $line_item_wrapper = entity_metadata_wrapper('merci_line_item', $line_item);

  // Retreive the id for the Resource Display.
  // TODO: Commerce dependent move to merci_commerce.
  $product_id = $line_item_wrapper->{MERCI_RESOURCE_REFERENCE}
    ->getIdentifier();
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', MERCI_RESOURCE_DISPLAY_BUNDLE)
    ->fieldCondition('field_crp_product_reference', 'product_id', $product_id);
  $result = $query
    ->execute();
  if (isset($result['node'])) {
    $nids = array_keys($result['node']);
    $merci_resource_reference = reset($nids);
  }
  $line_item_wrapper->{MERCI_RESOURCE_DISPLAY}
    ->set($merci_resource_reference);
  $line_item_wrapper->line_item_label
    ->set($line_item_wrapper->{MERCI_RESOURCE_REFERENCE}->sku
    ->value());
}