You are here

function commerce_wishlist_add_form_validate in Commerce Wishlist 7

Same name and namespace in other branches
  1. 7.3 commerce_wishlist.module \commerce_wishlist_add_form_validate()
  2. 7.2 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 222
Provides the wishlist for use in Drupal Commerce.

Code

function commerce_wishlist_add_form_validate($form, &$form_state) {
  global $user;
  if ($form_state['values']['op'] == t('Add to Wishlist')) {

    // Verify if is a registed user_access
    if (!$user->uid) {
      form_set_error('add_to_wishlist', t('<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 prodcut 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.'));
    }
  }
}