You are here

function commerce_wishlist_product_added_to_cart in Commerce Wishlist 7.3

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

Form submit handler: wishlist product added to the cart.

1 string reference to 'commerce_wishlist_product_added_to_cart'
commerce_wishlist_form_alter in ./commerce_wishlist.module
Implements hook_form_alter().

File

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

Code

function commerce_wishlist_product_added_to_cart($form, &$form_state) {

  // Load the line item, add wishlist user ID in additional data, and then save
  // back the changes.
  $line_item = commerce_line_item_load($form_state['line_item']->line_item_id);
  $line_item->data['wishlist_products'][] = array(
    'user_id' => $form_state['values']['uid'],
    'product_id' => $form_state['values']['product_id'],
  );
  commerce_line_item_save($line_item);
  $account = user_load($form_state['values']['uid']);
  $product = commerce_product_load($form_state['values']['product_id']);
  $wishlist = commerce_wishlist_order_load($account->uid);
  rules_invoke_event('commerce_wishlist_product_add_to_cart', $account, $product, $wishlist);
}