You are here

function commerce_pricelist_item_get_existing_id in Commerce Pricelist 7

Get the id of an existing pricelist item with these values. We do not want more than one item with these values.

Parameters

$entity:

Return value

int

1 call to commerce_pricelist_item_get_existing_id()
CommercePricelistItemController::save in includes/commerce_pricelist_item.controller.inc
Implements EntityAPIControllerInterface.

File

./commerce_pricelist.module, line 730
Implements the basic functionality required for price lists

Code

function commerce_pricelist_item_get_existing_id($pricelist_item) {
  $item_id = db_query("SELECT item_id FROM {commerce_pricelist_item} " . "WHERE item_id != :item_id AND sku = :sku AND valid_to = :valid_to AND valid_from = :valid_from " . "AND quantity = :quantity AND pricelist_id = :pricelist_id", array(
    ':item_id' => $pricelist_item->item_id,
    ':sku' => $pricelist_item->sku,
    ':valid_from' => $pricelist_item->valid_from,
    ':valid_to' => $pricelist_item->valid_to,
    ':quantity' => $pricelist_item->quantity,
    ':pricelist_id' => $pricelist_item->pricelist_id,
  ))
    ->fetchField();
  return $item_id;
}