You are here

function uc_ajax_cart_callback in Ubercart AJAX Cart 7.2

Same name and namespace in other branches
  1. 6.2 uc_ajax_cart.module \uc_ajax_cart_callback()

@todo Please document this function.

See also

http://drupal.org/node/1354

1 string reference to 'uc_ajax_cart_callback'
uc_ajax_cart_menu in ./uc_ajax_cart.module
@todo Please document this function.

File

./uc_ajax_cart.module, line 115

Code

function uc_ajax_cart_callback($op, $nid = NULL, $data = NULL) {
  $cacheEnabled = variable_get('cache', 0);
  if ($cacheEnabled > 0 && !$user->uid) {
    $page = request_uri();
    global $base_root;
    cache_clear_all($base_root . 'uc_ajax_cart/show', 'cache_page');
    cache_clear_all($base_root . 'uc_ajax_cart/remove', 'cache_page');
    cache_clear_all($base_root . 'uc_ajax_cart/show-cart-view', 'cache_page');
    cache_clear_all($base_root . 'uc_ajax_cart/update', 'cache_page');
    cache_clear_all($base_root . 'uc_ajax_cart/link', 'cache_page');
  }
  switch ($op) {
    case 'remove':
      uc_ajax_cart_remove_item($_GET['nid'], unserialize(base64_decode($_GET['data'])));

      // TODO Please change this theme call to use an associative array for the $variables parameter.
      print theme('status_messages');
      break;
    case 'add':
      uc_ajax_cart_add_item($_POST);

      // TODO Please change this theme call to use an associative array for the $variables parameter.
      print theme('status_messages');
      break;
    case 'show':
      uc_ajax_cart_show_cart();
      break;
    case 'show-cart-view':
      include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'uc_cart') . '/uc_cart.pages.inc';
      $outputs = uc_cart_view();
      $output = drupal_render($outputs);
      print $output;
      break;
    case 'update':
      $formValues = array(
        'values' => $_POST,
      );
      $cart = new UcAjaxCart();
      $items = $cart
        ->getCartContents();
      drupal_form_submit('uc_cart_view_form', $formValues, $items);

      // TODO Please change this theme call to use an associative array for the $variables parameter.
      print theme('status_messages');
      break;
    case 'link':
      if (module_exists('uc_cart_links')) {
        $link = array_pop(explode('/', $_GET['href']));
        uc_ajax_cart_links_process($link);
      }
      else {
        drupal_set_message(t('Sorry link is not valid'), 'error');
      }

      // TODO Please change this theme call to use an associative array for the $variables parameter.
      print theme('status_messages');
      break;
  }
}