Download & Extend

Can't delete or edit the uc_fee line item in order

Project:Ubercart Fee
Version:6.x-1.0-beta2
Component:Code
Category:bug report
Priority:major
Assigned:Unassigned
Status:active

Issue Summary

First off, thank you for a great module!

I'm having some trouble figuring out the best conditional action setup for a particular case. I'm learning through trial & error. Because of that, i've wrongfuly applied fees that i need to delete or edit on a number of orders. But when I edit or delete the uc_fee line item in an order and click the Submit changes button, changes are not saved. I guess that's what you would call sticky fees! :-) See attachment.

I've tried deactivating and reactivating the module. Still the same. I'm thinking about deactivating & uninstalling the module before reactivating but I'm affraid this will delete all applied fees, including those which are OK. Am I right?

Help!

AttachmentSize
Picture 3.jpg105.88 KB

Comments

#1

I had the same problem, same headache. I couldn't come up with a definite solution, but here's a hack. It basically ignores the module while in the admin edit screen. Not clean, but in my case acceptable...

In uc_fee.module , replace the uc_fee_order function with the code below. The only new code here is the bit with the comment starting "// TK"

<?php
function uc_fee_order($op, $arg1, $arg2) {
  switch (
$op) {
    case
'save':
     
$changes = array();
     
$line_items = uc_fee_line_item_fee('load', $arg1);
     
           
// TK ignore the following if we are in an admin edit screen
           
$args = arg(NULL);
            if (
$args[0] == 'admin' && $args[1] == 'store' && $args[2] == 'orders' && $args[4] == 'edit') {
                break;       
            }
           
            if (
is_array($arg1->line_items)) {
       
//drupal_set_message('<pre>'. var_export($arg1->line_items, TRUE) .'</pre>');
       
foreach ($arg1->line_items as $line) {
          if (
$line['type'] == 'fee') {
           
$delete = TRUE;
            foreach (
$line_items as $id => $new_line) {
              if (
$new_line['title'] == $line['title']) {
                if (
$new_line['amount'] != $line['amount']) {
                 
uc_order_update_line_item($line['line_item_id'], $new_line['title'], $new_line['amount']);
                 
$changes[] = t('Changed %title to %amount.', array('%amount' => uc_currency_format($new_line['amount']), '%title' => $new_line['title']));
                }
                unset(
$line_items[$id]);
               
$delete = FALSE;
                break;
              }
            }
            if (
$delete) {
             
uc_order_delete_line_item($line['line_item_id']);
             
$changes[] = t('Removed %title.', array('%title' => $line['title']));
            }
          }
        }
      }
      if (
is_array($line_items)) {
        foreach (
$line_items as $line) {
         
uc_order_line_item_add($arg1->order_id, $line['id'], $line['title'], $line['amount'], $line['weight']);
         
$changes[] = t('Added %amount for %title.', array('%amount' => uc_currency_format($line['amount']), '%title' => $line['title']));
        }
      }
      if (
count($changes)) {
       
uc_order_log_changes($arg1->order_id, $changes);
      }
    break;
  }
}
?>

#2

I have attached a patch for branch 6.x-2.x similar to the change above but instead of checking the path components, it checks the order's status to determine if it is in checkout (fees should be set automatically) or not (honour changes made by the user).

If the order is in checkout, then the behaviour of the function is not changed. If the order is not, then the function breaks out immediately and the line items are not modified. This prevents uc_fee from changing the total on a previous order when a fee amount has changed since that order, and allows users to make manual changes or deletions to uc_fee line items.

AttachmentSize
regen_fees_in_checkout_only-889706-2.patch 732 bytes
nobody click here