--- uc_cart.module 2010-08-11 17:09:54.000000000 +0200 +++ uc_cart.module 2010-10-04 02:42:00.000000000 +0200 @@ -959,6 +959,13 @@ function uc_cart_view_form($form_state, '#value' => uc_price($display_item['#total'], $context), '#theme' => 'uc_cart_view_price', ); + + $form['items'][$i]['remove'] = array( + '#type' => 'submit', + '#value' => t('Remove'), + '#name' => "item[$i][$item->nid]" + ); + $i++; } } @@ -1015,6 +1022,12 @@ function uc_cart_view_form_submit($form, unset($_SESSION['cart_order']); } + if (substr($form_state['clicked_button']['#name'], 0, 4) == 'item') { + foreach($form_state['clicked_button']['#post']['item'] AS $item => $nid) { + uc_cart_button_remove($item, key($nid)); + } + } + // Update the items in the shopping cart based on the form values. uc_cart_update_item_object((object)$form_state['values']); @@ -1095,24 +1108,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 +1605,26 @@ 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); + // Without intval() it fails for some reason. + 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) {