You are here

public function MerciLineItemEntityControllerDeprecated::save in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

Saves a line item.

Parameters

$line_item: The full line item object to save.

$transaction: An optional transaction object.

Return value

SAVED_NEW or SAVED_UPDATED depending on the operation performed.

Overrides MerciDefaultEntityController::save

File

merci_line_item/includes/merci_line_item.controller.inc, line 473
Provides a central controller for Drupal Commerce.

Class

MerciLineItemEntityControllerDeprecated
The controller class for line items contains methods for the line item CRUD operations. The load method is inherited from the default controller.

Code

public function save($line_item, DatabaseTransaction $transaction = NULL) {
  if (!isset($transaction)) {
    $transaction = db_transaction();
    $started_transaction = TRUE;
  }
  $wrapper = entity_metadata_wrapper('merci_line_item', $line_item);
  try {

    // Set the timestamp fields.
    if (empty($line_item->line_item_id) && empty($line_item->created)) {
      $line_item->created = REQUEST_TIME;
    }
    else {

      // Otherwise if the line item is not new but comes from an entity_create()
      // or similar function call that initializes the created timestamp to an
      // empty string, unset it to prevent destroying existing data in that
      // property on update.
      if ($line_item->created === '') {
        unset($line_item->created);
      }
    }

    //  return parent::save($line_item, $transaction);
  } catch (Exception $e) {
    if (!empty($started_transaction)) {
      $transaction
        ->rollback();
      watchdog_exception($this->entityType, $e);
    }
    throw $e;
  }
  return parent::save($line_item, $transaction);
}