commerce_pricelist_on_users.module in Commerce Pricelist 7
Summary
Description
File
commerce_pricelist_on_users/commerce_pricelist_on_users.moduleView source
<?php
/**
* @file
* Summary
*
* Description
*/
/**
* Filter out lists not tagged with current user
*
* @param $pricelists
*/
function commerce_pricelist_on_users_commerce_pricelists_alter(&$pricelists, $user) {
$user_pricelists = array();
try {
$wrapper = entity_metadata_wrapper('user', $user);
$user_pricelists = $wrapper->user_commerce_pricelists
->value();
} catch (EntityMetadataWrapperException $exc) {
}
if (!empty($user_pricelists)) {
// This user has pricelists assigned
$user_pricelist_ids = array();
foreach ($user_pricelists as $user_pricelist) {
$user_pricelist_ids[] = $user_pricelist->list_id;
}
foreach ($pricelists as &$pricelist) {
if (in_array($pricelist->list_id, $user_pricelist_ids)) {
$pricelist->score = isset($pricelist->score) ? ++$pricelist->score : 1;
}
}
}
}
/**
* @param $form
* @param $form_state
* @param $form_id
*/
function commerce_pricelist_on_users_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
if (!user_access('administer commerce_pricelist_list entities')) {
$form['user_commerce_pricelists']['#access'] = FALSE;
}
}
/**
* Implements hook_user_update().
*
* @param $edit
* @param $account
* @param $category
*/
function commerce_pricelist_on_users_user_update(&$edit, $account, $category) {
// Clear pricelist cache for this user
$cache_id = 'commerce_pricelist_get_user_pricelists_' . $account->uid;
if (cache_get($cache_id)) {
cache_clear_all($cache_id, 'cache');
}
}
Functions
Name | Description |
---|---|
commerce_pricelist_on_users_commerce_pricelists_alter | Filter out lists not tagged with current user |
commerce_pricelist_on_users_form_user_profile_form_alter | _state _id |
commerce_pricelist_on_users_user_update | Implements hook_user_update(). |