You are here

function commerce_wishlist_remove in Commerce Wishlist 7.2

Remove a wishlist product.

1 string reference to 'commerce_wishlist_remove'
commerce_wishlist_menu in ./commerce_wishlist.module
Implements hook_menu().

File

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

Code

function commerce_wishlist_remove($account, $item_id) {

  // Invoke the appropriate rules event.
  $wishlist_item = db_select('commerce_wishlist_item', 'wi')
    ->addTag('commerce_wishlist')
    ->fields('wi')
    ->condition('item_id', $item_id)
    ->execute()
    ->fetchObject();
  if ($wishlist_item) {
    $product = commerce_product_load($wishlist_item->product_id);
    $node = node_load($wishlist_item->nid);
    rules_invoke_event('commerce_wishlist_event_product_removed', $account, $product, $node);

    // Remove the wishlist from the database.
    db_delete('commerce_wishlist_item')
      ->condition('item_id', $item_id)
      ->execute();
    drupal_set_message(t('@product has been removed from your wishlist.', array(
      '@product' => $product->title,
    )));
  }
  else {
    drupal_set_message(t('Unable to remove that item from your wishlist'), 'error');
  }
  drupal_goto('user/wishlist/' . $account->uid . '/wishlist');
}