You are here

function uc_ajax_cart_block in Ubercart AJAX Cart 6

Same name and namespace in other branches
  1. 5 uc_ajax_cart.module \uc_ajax_cart_block()
  2. 6.2 uc_ajax_cart.module \uc_ajax_cart_block()

override hook_block

Parameters

$op String $op :

$delta:

$edit:

Return value

unknown_type

See also

http://api.drupal.org/api/function/hook_block/6

File

./uc_ajax_cart.module, line 80

Code

function uc_ajax_cart_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {

    // Retrieve block informations
    $cBlocks = uc_cart_block('list');
    $blocks[0] = $cBlocks[0];
    $blocks[0]['info'] = t('Ubercart ajax shopping cart');
    return $blocks;
  }
  elseif ($op == 'view') {

    //Only a wrapper to uc_cart_block
    $content = uc_cart_block($op, $delta, $edit);
    $content['content'] = '<div id="ajaxCartUpdate">' . $content['content'] . '</div>';
    return $content;
  }
  elseif ($op == 'configure') {

    // Get settings for from uc_cart block
    $form = uc_cart_block($op, $delta, $edit);
    $form['ajaxSettings'] = array(
      '#type' => 'fieldset',
      '#collapsed' => false,
      '#title' => t('Ajax Cart Options'),
      '#description' => t('Set some options for Ajax Cart.'),
    );

    //Rebuild cache after ajax call ?
    $form['ajaxSettings']['rebuildCache'] = array(
      '#type' => 'checkbox',
      '#return_value' => true,
      '#title' => t('Rebuild cart cache.'),
      '#description' => t("Rebuild cart cache on every ajax call."),
      '#default_value' => variable_get('uc_ajax_cart_rebuild', false),
    );

    //Clear cache option
    $form['ajaxSettings']['clearCache'] = array(
      '#type' => 'checkbox',
      '#return_value' => true,
      '#title' => t('Clear cart cache on every ajax call.'),
      '#description' => t("With this option enabled, cart content is rebuilded every request."),
      '#default_value' => variable_get('uc_ajax_cart_del_cache', false),
    );

    //Disable button on ajax request ?
    $form['ajaxSettings']['buttonDisable'] = array(
      '#type' => 'checkbox',
      '#return_value' => 1,
      '#title' => t('Disable button on ajax call.'),
      '#description' => t("Disable the button , so you don't have multiple requests."),
      '#default_value' => variable_get('uc_ajax_cart_button_disable', 1),
    );

    //Alternate button text
    $form['ajaxSettings']['alternateText'] = array(
      '#type' => 'textfield',
      '#title' => t('Change button text.'),
      '#default_value' => variable_get('uc_ajax_cart_button_txt', ""),
    );

    //Ajax button class
    $form['ajaxSettings']['alternateButtonClass'] = array(
      '#type' => 'textfield',
      '#title' => t('Button class for an ajax call.'),
      '#description' => t('Giving the button this class for request time.'),
      '#default_value' => variable_get('uc_ajax_cart_button_class', ""),
    );

    //Alternate button text for products already in cart
    $form['ajaxSettings']['alternateTextCart'] = array(
      '#type' => 'textfield',
      '#title' => t('Change button text for products already in cart.'),
      '#description' => t('Be aware does not work with attributes!'),
      '#default_value' => variable_get('uc_ajax_cart_button_c', ""),
    );

    //Effects ?
    $form['ajaxSettings']['effects'] = array(
      '#type' => 'checkbox',
      '#return_value' => 1,
      '#title' => t('Use jquery ui effects.'),
      '#description' => t('Highlights cart and product after ajax call.'),
      '#default_value' => variable_get('uc_ajax_cart_effects', false),
    );
    $form['#submit'] = array_merge(array(
      'uc_ajax_cart_block_submit' => array(),
    ), (array) $form['#submit']);
    return $form;
  }
  elseif ($op == 'save' && isset($edit['uc_cart_block_empty_hide'])) {

    //Set configuration
    variable_set('uc_ajax_cart_js_src', $edit['alternateJS']);
    variable_set('uc_ajax_cart_button_txt', $edit['alternateText']);
    variable_set('uc_ajax_cart_button_c', $edit['alternateTextCart']);
    variable_set('uc_ajax_cart_button_class', $edit['alternateButtonClass']);
    variable_set('uc_ajax_cart_button_disable', $edit['buttonDisable']);
    if ($edit['rebuildCache'] == true) {
      variable_set('uc_ajax_cart_rebuild', true);
    }
    else {
      variable_set('uc_ajax_cart_rebuild', false);
    }
    if ($edit['effects'] == true) {
      variable_set('uc_ajax_cart_effects', true);
    }
    else {
      variable_set('uc_ajax_cart_effects', false);
    }
    variable_set('uc_ajax_cart_button_disable', $edit['buttonDisable']);

    //Set configuration for cart block
    uc_cart_block($op, $delta, $edit);
  }
}