This patch checks to see if there are any donation products in the cart before adding the "Amount" column to the cart review table. I created this patch because having the "Amount" column in the cart table is confusing for the customer when there are no donation products in their cart.

This patch was applied against 6.x-2.x-dev. I've tested it with 6.x-2.0-beta3 and it seems to be working fine.

This is my first contributed patch, so please feel free to modify it if you find a better solution.

I'll explain the changes in case anyone runs into difficulty applying the patch.

In "uc_donation.module", I replaced lines 111 to 123:

<?php
if ($form_id == 'uc_cart_view_form') {
  $form['items']['#columns']['donate_amount'] = array('cell' => t('Amount'), 'weight' => 3);
  $form['items']['#columns']['qty']['weight']++;
  $form['items']['#columns']['total']['weight']++;
  $form['#validate'][] = 'uc_donation_cart_view_validate';

  // Add spacer to regular products for amount column
  foreach (element_children($form['items']) as $item) {
    if (isset($form['items'][$item]['module']) && $form['items'][$item]['module']['#value'] != 'uc_donation') {
      $form['items'][$item]['desc']['#cell_attributes']['colspan'] = '2';
    }
  }
}
?>

with the following:

<?php
if ($form_id == 'uc_cart_view_form') {
  // Determine if a donation product has been added to the cart
  $donation_in_cart = FALSE;
  foreach (element_children($form['items']) as $item) {
    if (isset($form['items'][$item]['module']) && $form['items'][$item]['module']['#value'] == 'uc_donation') {
      $donation_in_cart = TRUE;
    }
  }
  // If there is a donation product in the cart, alter the table
  if ($donation_in_cart) {
    $form['items']['#columns']['donate_amount'] = array('cell' => t('Amount'), 'weight' => 3);
    $form['items']['#columns']['qty']['weight']++;
    $form['items']['#columns']['total']['weight']++;
    // Add spacer to regular products for amount column
    foreach (element_children($form['items']) as $item) {
      if (isset($form['items'][$item]['module']) && $form['items'][$item]['module']['#value'] != 'uc_donation') {
        $form['items'][$item]['desc']['#cell_attributes']['colspan'] = '2';
      }
    }
  }
  $form['#validate'][] = 'uc_donation_cart_view_validate';
}
?>
CommentFileSizeAuthor
#1 uc_donation_table_column-2.patch1.83 KBcmoad
uc_donation_table_column.patch1.85 KBAnonymous (not verified)

Comments

cmoad’s picture

StatusFileSize
new1.83 KB

I am attaching a very slight modification to you original patch. I also have a module that adds a new column to the cart and you solution of adding a colspan to "desc" breaks it. Instead I simply add an empty "donate_amount" column to all non-donation products.

dkinzer’s picture

Was this patch ever committed? I'm experiencing this exact issue with one my installs.

dkinzer’s picture

Category: feature » bug
Priority: Normal » Major
Status: Active » Reviewed & tested by the community

I applied the patch my installation of 6.x-2.0-beta3 and it's working for me.

I'm changing the category of this issue to bug report because I think that the uc_donation module adding a column to the cart table when there are no donation items in the cart is a bug.