function uc_ajax_cart_block in Ubercart AJAX Cart 6.2
Same name and namespace in other branches
- 5 uc_ajax_cart.module \uc_ajax_cart_block()
- 6 uc_ajax_cart.module \uc_ajax_cart_block()
File
- ./
uc_ajax_cart.module, line 202
Code
function uc_ajax_cart_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
// Retrieve block informations
$blocks[0] = array(
'info' => t('Ajax shopping cart'),
'cache' => BLOCK_NO_CACHE,
);
return $blocks;
}
elseif ($op == 'view') {
// Add standard JS if we are to enable ajax only when block is visible
// Otherwise, _uc_ajax_cart_init() gets called from hook_init().
if (variable_get('uc_ajax_cart_enably_only_when_visible', FALSE)) {
_uc_ajax_cart_init();
}
//Only a wrapper to uc_cart_block
$cartContent = uc_cart_get_contents();
if (count($cartContent) > 0) {
$hasItems = TRUE;
}
$content['subject'] = theme('uc_ajax_cart_block_header', $hasItems);
global $user;
$cacheEnabled = variable_get('cache', 0);
$loadOnPageView = variable_get($user->uid ? 'uc_ajax_cart_registered_users_cart_cached_load' : 'uc_ajax_cart_cart_cached_load', 0);
$loadOnPageViewClass = $loadOnPageView ? ' class="load-on-view"' : '';
// Anonymous users w/ page caching caching get a cached block.
if (!$user->uid && $cacheEnabled > 0) {
$content['content'] = '<div id="ajaxCartUpdate" ' . $loadOnPageViewClass . '>' . theme('uc_ajax_cart_block_content_cached') . '</div>';
}
elseif ($hasItems == TRUE) {
$content['content'] = '<div id="ajaxCartUpdate" ' . $loadOnPageViewClass . '>' . theme('uc_ajax_cart_block_content', $cartContent) . '</div>';
}
else {
$content['content'] = '<div id="ajaxCartUpdate" ' . $loadOnPageViewClass . '>' . theme('uc_ajax_cart_block_content_empty') . '</div>';
}
return $content;
}
elseif ($op == 'configure') {
$form['text'] = array(
'#title' => t('Ajax cart settings'),
'#type' => 'fieldset',
'#description' => t('Advanced settings for ajax cart are !here', array(
'!here' => l(t('here'), 'admin/store/settings/uc_ajax_cart'),
)),
);
return $form;
}
}