You are here

function commerce_wishlist_operations in Commerce Wishlist 7

Same name and namespace in other branches
  1. 7.2 commerce_wishlist.module \commerce_wishlist_operations()

Menu callback: Perform various actions (add to wishlist etc)

1 string reference to 'commerce_wishlist_operations'
commerce_wishlist_menu in ./commerce_wishlist.module
Implements hook_menu().

File

./commerce_wishlist.module, line 306
Provides the wishlist for use in Drupal Commerce.

Code

function commerce_wishlist_operations() {
  $args = func_get_args();
  if (isset($args[0]) && isset($args[1]) && isset($args[2]) && isset($args[3]) && (isset($_GET['token']) && drupal_valid_token($_GET['token']))) {
    switch ($args[1]) {
      case 'add':
        if (commerce_wishlist_in_wishlist($args[2], $args[3], $args[4])) {
          return;
        }
        $fields = array(
          'uid' => $args[2],
          'product_id' => $args[3],
          'nid' => $args[4],
          'quantity' => 1,
        );
        commerce_wishlist_add_product($fields);
        break;
    }
    if ($args[0] == 'ajax') {
      $commands = array();
      switch ($args[1]) {
        case 'add':
          $link = _commerce_wishlist_link($args[2]);
          $commands[] = ajax_command_replace('a#add-wishlist-' . $args[3], $link);
          break;
      }
      ajax_deliver(array(
        '#type' => 'ajax',
        '#commands' => $commands,
      ));
    }
    else {
      $destination = isset($_GET['destination']) ? $_GET['destination'] : '';
      drupal_goto($destination);
    }
  }
}