function commerce_wishlist_order_id in Commerce Wishlist 7.3
Returns the current wish list order ID for the given user.
Parameters
int $uid: The uid of the customer whose wishlist to load. If left 0, attempts to load an anonymous order from the session.
Return value
int The requested cart order ID or FALSE if none was found.
1 call to commerce_wishlist_order_id()
- commerce_wishlist_order_load in ./
commerce_wishlist.module - Loads the default wishlist order for the specified user.
File
- ./
commerce_wishlist.module, line 885 - Provides a wish list for use in Drupal Commerce.
Code
function commerce_wishlist_order_id($uid = 0) {
// Cart order IDs will be cached keyed by $uid.
$cart_order_ids =& drupal_static(__FUNCTION__);
// Cache the user's cart order ID if it hasn't been set already.
if (isset($cart_order_ids[$uid])) {
return $cart_order_ids[$uid];
}
// First let other modules attempt to provide a valid order ID for the given
// uid. Instead of invoking hook_commerce_cart_order_id() directly, we invoke
// it in each module implementing the hook and return the first valid order ID
// returned (if any).
foreach (module_implements('commerce_wishlist_order_id') as $module) {
$order_id = module_invoke($module, 'commerce_wishlist_order_id', $uid);
// If a hook said the user should not have a cart, that overrides any other
// potentially valid order ID. Return FALSE now.
if ($order_id === FALSE) {
$cart_order_ids[$uid] = FALSE;
return FALSE;
}
// Otherwise only return a valid order ID.
if (!empty($order_id) && is_int($order_id)) {
$cart_order_ids[$uid] = $order_id;
return $order_id;
}
}
// Create an array of valid shopping cart order statuses.
$status_ids = array(
'wishlist',
);
// If a customer uid was specified...
if ($uid) {
// Look for the user's most recent shopping cart order, although they
// should never really have more than one.
$cart_order_ids[$uid] = db_query('SELECT order_id FROM {commerce_order} WHERE uid = :uid AND status IN (:status_ids) ORDER BY order_id DESC', array(
':uid' => $uid,
':status_ids' => $status_ids,
))
->fetchField();
}
return $cart_order_ids[$uid];
}