You are here

function commerce_pricelist_get_user_pricelists in Commerce Pricelist 7

Get pricelists for a user.

Return value

array

1 call to commerce_pricelist_get_user_pricelists()
commerce_pricelist_get_user_price in ./commerce_pricelist.module
Get the price for a quantity of a product for current user.

File

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

Code

function commerce_pricelist_get_user_pricelists($user) {
  $cache_id = 'commerce_pricelist_get_user_pricelists_' . $user->uid;
  $pricelists =& drupal_static($cache_id);
  if (!isset($pricelists)) {
    if ($cache = cache_get($cache_id)) {
      $pricelists = $cache->data;
    }
    else {
      $pricelists = array();
      $query = new EntityFieldQuery();
      $query
        ->entityCondition('entity_type', 'commerce_pricelist_list')
        ->propertyCondition('status', 1, '=')
        ->propertyOrderBy('weight');
      $result = $query
        ->execute();
      if (!empty($result['commerce_pricelist_list'])) {
        $pricelists = commerce_pricelist_list_load_multiple(array_keys($result['commerce_pricelist_list']));
      }

      // Let modules implementing hook_commerce_pricelists_alter() modify list.
      drupal_alter('commerce_pricelists', $pricelists, $user);
      foreach ($pricelists as $id => $pricelist) {
        if (isset($pricelist->score) && $pricelist->score < 0) {
          unset($pricelists[$id]);
        }
      }
      cache_set($cache_id, $pricelists, 'cache', time() + 3600);
    }
  }
  return $pricelists;
}