--- uc_cart/uc_cart.module.orig 2010-08-11 11:09:54.000000000 -0400 +++ uc_cart/uc_cart.module 2010-09-25 19:32:57.000000000 -0400 @@ -170,6 +170,14 @@ function uc_cart_menu() { 'type' => MENU_CALLBACK, 'file' => 'uc_cart.pages.inc', ); + $items['cart/remove/%/%'] = array( + 'title' => 'Remove a cart item', + 'description' => 'Remove an item from the cart on click', + 'page callback' => 'uc_cart_button_remove', + 'page arguments' => array(2, 3), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); return $items; } @@ -959,6 +967,10 @@ function uc_cart_view_form($form_state, '#value' => uc_price($display_item['#total'], $context), '#theme' => 'uc_cart_view_price', ); + + // The $item->nid isn't 100% necessary, but might be good to check later on. + $form['items'][$i]['remove'] = array('#value' => l("Remove", 'cart/remove/'. $i .'/'. $item->nid)); + $i++; } } @@ -1095,16 +1107,16 @@ function uc_cart_view_table($table) { $table['#attributes'] = array('width' => '100%'); $table['#columns'] = array( - 'remove' => array( - 'cell' => t('Remove'), - 'weight' => 0, - ), 'image' => array( 'cell' => t('Products'), - 'weight' => 1, + 'weight' => 0, ), 'desc' => array( 'cell' => '', + 'weight' => 1, + ), + 'remove' => array( + 'cell' => t('Remove?'), 'weight' => 2, ), 'qty' => array( @@ -1592,6 +1604,23 @@ function uc_cart_remove_item($nid, $cid } /** + * Remove a row from the user's cart when the "Remove" link is clicked + */ +function uc_cart_button_remove($item, $nid) { + $cart = uc_cart_get_contents(); + if (uc_product_is_product(intval($nid)) == TRUE) { // Without intval() it fails for some reason + $product = $cart[$item]; + uc_cart_remove_item($nid, NULL, $product->data); + drupal_set_message(t(l($product->title, 'node/'. $nid).' removed from cart.')); + drupal_goto('cart'); + } + else { + drupal_set_message(t('An error has occurred. Please contact a site administrator.')); + drupal_goto('cart'); + } +} + +/** * Update the quantity of all the items in a cart object */ function uc_cart_update_item_object($cart) {