Exemple #1
0
function devis_page_alter(&$page)
{
    global $user;
    $path = current_path();
    $args = arg();
    // If admin viewing user pages, set a message to make him understand.
    if (in_array('manager', $user->roles) && isset($args[0]) && $args[0] == 'user' && isset($args[1]) && $args[1] != $user->uid) {
        drupal_set_message(t('Viewing as admin'), 'admin');
    }
    if (in_array('provider', $user->roles)) {
        $billing_id = commerce_addressbook_get_default_profile_id($user->uid, 'billing');
        $link = 'user/' . $user->uid . '/addressbook/billing/delete/' . $billing_id;
        if (isset($args[5]) && $args[5] == $billing_id && $path == $link) {
            watchdog('devis', t('Malicious user trying to delete address. User has been redirected.'), array(), WATCHDOG_ALERT, $link);
            drupal_goto('user/' . $user->uid . '/addressbook/billing/edit/' . $billing_id);
        }
    }
    // Delete message after setting password which gives the user the same message again.
    // Set the first step message on the account edit.
    if (strpos($_SERVER['QUERY_STRING'], 'pass-reset-token') === false) {
        // First stage message.
        if (in_array('provider', $user->roles)) {
            if ($path == 'user/' . $user->uid . '/edit-profile' || $path == 'user/' . $user->uid) {
                $messages = drupal_get_messages('status');
                if (isset($messages['status'])) {
                    foreach ($messages['status'] as $msg) {
                        if (strpos($msg, "Vous venez d'utiliser votre lien de connexion unique.") === false) {
                            drupal_set_message($msg, 'status');
                        }
                    }
                }
            }
            $profile = profile2_load_by_user($user);
            if (!$profile && $path == 'user/' . $user->uid . '/edit-profile') {
                drupal_set_message(t(variable_get('trois_devis_first_step_message')), 'warning');
            }
        }
    }
}
Exemple #2
0
"</pre>";
*/
// set the doc type - contract or offer
if (isset($o)) {
    $doc_type = "contract";
    // contract | offer
} else {
    $doc_type = "offer";
    // contract | offer
}
// CUSTOMER BILLING ADDRESS
$account = user_load($o->uid);
// $account = user_load( 890 );
$shipping_profile_id = $billing_profile_id = NULL;
if (module_exists('commerce_addressbook')) {
    $billing_profile_id = commerce_addressbook_get_default_profile_id($account->uid, 'billing');
}
//$order = commerce_order_load(28);
//$wrapper = entity_metadata_wrapper('commerce_order', $order);
print_r($order);
print_r($wrapper);
//print "teste";
if ($billing_profile_id) {
    $billing_profile = commerce_customer_profile_load($billing_profile_id);
    $billing_profile_render = entity_view('commerce_customer_profile', array($billing_profile), 'full');
    $billing_profile_render = reset($billing_profile_render);
    $billing_profile_output = drupal_render($billing_profile_render);
} else {
    $link = $base_url . "/user/" . $o->uid . "/addressbook";
    $billing_profile_output = '<p>' . t('No default billing profile - go here and edit user profiles') . " - " . l($link, $link) . '</p>';
}