You are here

function uc_ajax_cart_handler in Ubercart AJAX Cart 6

1 string reference to 'uc_ajax_cart_handler'
uc_ajax_cart_menu in ./uc_ajax_cart.module
override hook menu

File

./uc_ajax_cart.module, line 417

Code

function uc_ajax_cart_handler() {
  if (isset($_REQUEST['products']) && is_array($_REQUEST['products'])) {
    uc_ajax_cart_handler_kit();
  }
  header("Cache-Control: no-cache, must-revalidate");

  // HTTP/1.1
  header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

  // past date
  $formID = $_REQUEST['form_id'];
  $nid = $_REQUEST['pnid'];
  if (isset($_REQUEST['uc-ajax-cart-callback'])) {
    $formID = $_REQUEST['uc-ajax-cart-callback'];
  }
  $formValues = $_REQUEST;
  $formValues['nid'] = $nid;
  if (is_numeric($nid) && $nid > 0) {
    $node = node_load($nid);
    if (is_object($node) && uc_product_is_product($node)) {
      if (!isset($_REQUEST['qty']) || !is_numeric($_REQUEST['qty'])) {
        $qty = 1;
      }
      else {
        $qty = $_REQUEST['qty'];
      }
      $result = (array) module_invoke_all('add_to_cart', $nid, $qty, $formValues);
      if (is_array($result) && count($result) > 0) {
        if ($row['success'] === FALSE) {
          foreach ($result as $key => $val) {
            $val['nid'] = $nid;
          }
        }
        uc_ajax_cart_create_ajax_msg($formID, $result);
      }
      else {
        uc_cart_add_item($nid, $qty, module_invoke_all('add_to_cart_data', $formValues), null, false, false);
      }
    }
  }
  if (true == variable_get('uc_ajax_cart_del_cache', false)) {
    uc_cart_get_contents(null, 'rebuild');
  }
  $output = "";
  if (true == variable_get('uc_ajax_cart_rebuild', false)) {
    uc_cart_get_contents(null, 'rebuild');
  }
  $cart = uc_cart_block('view');
  $output = $cart['content'];
  $data = array(
    'form_id' => $formID,
    'content' => $output,
    'success' => true,
  );
  print drupal_to_js($data);
  exit;
}