You are here

function commerce_node_checkout_expire_node_in_cart in Commerce Node Checkout 7

Determine if a given node is in a given user's shopping cart.

Parameters

$node: The node object.

$account: Optionally supply the user account to load the cart for. If omitted, the current user will be used.

Return value

TRUE if the node is in the user's cart, otherwise FALSE.

2 calls to commerce_node_checkout_expire_node_in_cart()
commerce_node_checkout_expire_field_node_relist_form::render in commerce_node_checkout_expire/includes/views/handlers/commerce_node_checkout_expire_field_node_relist_form.inc
Implements parent::render().
commerce_node_checkout_expire_relist_form_validate in commerce_node_checkout_expire/commerce_node_checkout_expire.module
Validation handler for the node relist form.

File

commerce_node_checkout_expire/commerce_node_checkout_expire.module, line 524
Provides core hooks and the like for the module.

Code

function commerce_node_checkout_expire_node_in_cart($node, $account = NULL) {
  if (!$account) {
    global $user;
    $account = clone $user;
  }

  // Load the cart
  if ($order = commerce_cart_order_load($account->uid)) {

    // Create a wrapper for the order
    $wrapper = entity_metadata_wrapper('commerce_order', $order);

    // See if there are items present
    if ($lines = $wrapper->commerce_line_items
      ->value()) {

      // Iterate the lines to see if this node is present
      foreach ($lines as $line) {

        // See if this is a node checkout item
        if ($line->type == 'commerce_node_checkout') {

          // Extract the node
          if ($nid = $line->commerce_node_checkout_node[LANGUAGE_NONE][0]['target_id']) {
            if ($nid == $node->nid) {
              return TRUE;
            }
          }
        }
      }
    }
  }
  return FALSE;
}