You are here

function theme_commerce_wishlist_product_add_link in Commerce Wishlist 7.3

Add to wishlist theme callback.

2 theme calls to theme_commerce_wishlist_product_add_link()
commerce_wishlist_form_alter in ./commerce_wishlist.module
Implements hook_form_alter().
commerce_wishlist_product_remove_ajax in ./commerce_wishlist.module
Ajax callback to handle deletion of wish list item.

File

./commerce_wishlist.module, line 534
Provides a wish list for use in Drupal Commerce.

Code

function theme_commerce_wishlist_product_add_link($variables) {
  $user = $variables['user'];
  $product_id = $variables['product_id'];
  $url = 'user/' . $user->uid . '/wishlist/nojs/add/' . $product_id;
  $params = array(
    'attributes' => array(
      'class' => array(
        'ajax' => 'use-ajax',
        'add-to-wishlist',
      ),
      'id' => 'add-wishlist-' . $product_id,
    ),
    'query' => array(
      'destination' => $_GET['q'],
      'token' => drupal_get_token(),
    ),
  );

  // If the current user is not logged in, build a different link that
  // points to the login page and lists all other relevant details
  // (product ID, node ID and original URL) in query string.
  if ($user->uid == 0) {
    unset($params['attributes']['class']['ajax'], $params['query']);
    $params['query']['wishlist_product'] = $product_id;
    $params['query']['destination'] = $_GET['q'];
    $url = 'user/login';
  }
  return l(t('Add to Wishlist'), $url, $params);
}