--- uc_cart.module 2010-08-11 17:09:54.000000000 +0200 +++ uc_cart.module 2010-10-03 20:14:20.000000000 +0200 @@ -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', ); + + $image = theme('image', drupal_get_path('module', 'uc_cart').'/images/delete.png', $alt = t('Remove from cart'), $title = t('Remove from cart')); + $form['items'][$i]['remove'] = array('#value' => l($image, 'cart/remove/'. $i .'/'. $item->nid, array('html' => TRUE, 'attributes' => array('class' => 'remove-from-cart')))); + $i++; } } @@ -1095,24 +1107,24 @@ 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' => 2, + 'weight' => 1, ), 'qty' => array( 'cell' => t('Qty.'), - 'weight' => 3, + 'weight' => 2, ), 'total' => array( 'cell' => t('Total'), + 'weight' => 3, + ), + 'remove' => array( + 'cell' => t('Remove'), 'weight' => 4, ), ); @@ -1592,6 +1604,25 @@ 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(); + $node = node_load($nid); + $item = check_plain($item); + if (uc_product_is_product($node)) { + $product = $cart[$item]; + uc_cart_remove_item($node->nid, NULL, $product->data); + drupal_set_message(t('!item was removed from your shopping cart.', array('!item' => l($product->title, 'node/'. $nid)))); + drupal_goto('cart'); + } + else { + drupal_set_message(t('!item could not removed from your shopping cart.', array('!item' => l($product->title, 'node/'. $nid)))); + drupal_goto('cart'); + } +} + +/** * Update the quantity of all the items in a cart object */ function uc_cart_update_item_object($cart) {