You are here

function commerce_wishlist_operations in Commerce Wishlist 7.2

Same name and namespace in other branches
  1. 7 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 562
Provides the wishlist for use in Drupal Commerce.

Code

function commerce_wishlist_operations() {
  $args = func_get_args();
  if (count($args) >= 4 && 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;
        }
        _commerce_wishlist_add_product(array(
          'uid' => $args[2],
          'product_id' => $args[3],
          'nid' => $args[4],
          'quantity' => 1,
        ));
        break;
    }
    if ($args[0] == 'ajax') {
      $commands = array();
      switch ($args[1]) {
        case 'add':
          $link = theme('commerce_wishlist_already_in_wishlist_link', array(
            'user_id' => $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);
    }
  }
}