function commerce_addressbook_profile_options_default in Commerce Addressbook 7.3
Same name and namespace in other branches
- 7.2 includes/commerce_addressbook.user.inc \commerce_addressbook_profile_options_default()
Page callback for setting a customer profile as default. Used for both ajax and non-ajax delivery of the customer profile updates.
1 string reference to 'commerce_addressbook_profile_options_default'
- commerce_addressbook_menu in ./
commerce_addressbook.module - Implements hook_menu().
File
- includes/
commerce_addressbook.user.inc, line 117 - Page callbacks and form callbacks for user addressbook pages.
Code
function commerce_addressbook_profile_options_default($account, $customer_profile, $type = 'ajax') {
// Check if the user already has defaults addresses to know which
// ajax command we should use.
$defaults_view = commerce_addressbook_retrieve_view('commerce_addressbook_defaults', 'default', array(
$account->uid,
$customer_profile->type,
));
commerce_addressbook_set_default_profile($customer_profile);
if ($type == 'ajax') {
$commands = array();
$list_view = commerce_addressbook_retrieve_view('commerce_addressbook', 'default', array(
$account->uid,
$customer_profile->type,
));
$commands[] = ajax_command_replace('#commerce-addressbook-' . $customer_profile->type . '-list', '<div id="commerce-addressbook-' . $customer_profile->type . '-list">' . $list_view
->render() . '</div>');
$defaults_html = '<div id="commerce-addressbook-' . $customer_profile->type . '-default">' . views_embed_view('commerce_addressbook_defaults', 'default', $account->uid, $customer_profile->type) . '</div>';
if (empty($defaults_view->result)) {
if (empty($list_view->result)) {
$commands[] = ajax_command_replace('#commerce-addressbook-' . $customer_profile->type . '-list', $defaults_html);
}
else {
$commands[] = ajax_command_after('#commerce-addressbook-' . $customer_profile->type . '-list', $defaults_html);
}
}
else {
$commands[] = ajax_command_replace('#commerce-addressbook-' . $customer_profile->type . '-default', $defaults_html);
}
ajax_deliver(array(
'#type' => 'ajax',
'#commands' => $commands,
));
}
else {
drupal_goto('user/' . $account->uid . '/addressbook/' . $customer_profile->type);
}
}