You are here

function commerce_wishlist_add_form_validate in Commerce Wishlist 7.2

Same name and namespace in other branches
  1. 7.3 commerce_wishlist.module \commerce_wishlist_add_form_validate()
  2. 7 commerce_wishlist.module \commerce_wishlist_add_form_validate()

Validate callback for commerce_cart_add_to_cart_form().

1 string reference to 'commerce_wishlist_add_form_validate'
commerce_wishlist_add_form in ./commerce_wishlist.module
Form callback for add a new button of commerce_cart_add_to_cart_form()

File

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

Code

function commerce_wishlist_add_form_validate($form, &$form_state) {
  global $user;
  if ($form_state['triggering_element']['#name'] == 'commerce-wishlist-add-product') {

    // Verify if the user is logged in.
    if (!$user->uid) {
      form_set_error('add_to_wishlist', t('Please <a href="@login">log in</a> or <a href="@register">register</a> to add this product to your wishlist.', array(
        '@login' => url('user/login', array(
          'query' => drupal_get_destination(),
        )),
        '@register' => url('user/register'),
      )));
    }

    // Get nid from context information.
    $nid = _commerce_wishlist_get_context_entity_id($form_state['build_info']['args'][2]);

    // Verify if this product has been added to wishlist.
    $in_wishlist = _commerce_wishlist_in_wishlist($user->uid, $form_state['values']['product_id'], $nid);
    if ($in_wishlist) {
      form_set_error('add_to_wishlist', t('This product is already in your wishlist.'));
    }
  }
}