You are here

function commerce_product_attributes_access_to_line_item in Commerce Product Attributes 7

This function is used to check if a user has access to update an line item. The access depends on the fact that the order is related to the user and the order is in "cart" state.

1 call to commerce_product_attributes_access_to_line_item()
commerce_product_attributes_field_attach_view_alter in ./commerce_product_attributes.module
Implements hook_field_attach_view_alter().

File

./commerce_product_attributes.module, line 189
This module adds some improvements to the Drupal Commerce core.

Code

function commerce_product_attributes_access_to_line_item($line_item, $account = NULL) {
  global $user;
  static $access = array();
  $account = isset($account) ? $account : clone $user;
  $key = NULL;
  if (isset($line_item->line_item_id) && isset($account->uid)) {
    $key = $line_item->line_item_id . '__' . $account->uid;
    if (isset($access[$key])) {
      return $access[$key];
    }
  }

  // If the user has the administration permission, return TRUE now.
  if (user_access('administer line items', $account)) {
    $access[$key] = TRUE;
    return $access[$key];
  }
  if (!empty($line_item->order_id) && module_exists('commerce_order')) {
    $order = commerce_order_load($line_item->order_id);
    if ($order->status == 'cart' && ($order->uid === 0 || $order->uid == $account->uid)) {
      $access[$key] = TRUE;
      return $access[$key];
    }
  }
  $access[$key] = FALSE;
  return $access[$key];
}