Index: ubercart_disable_tax.diff =================================================================== Index: uc_order/uc_order.order_pane.inc =================================================================== --- uc_order/uc_order.order_pane.inc (revision 96) +++ uc_order/uc_order.order_pane.inc (working copy) @@ -483,17 +483,28 @@ return $output; case 'edit-process': + $log = array(); if (is_array($arg1['line_items'])) { foreach ($arg1['line_items'] as $line) { if (is_numeric($line['li_id']) && intval($line['li_id']) > 0) { uc_order_update_line_item($line['li_id'], $line['title'], $line['amount']); + $log[] = t("Line Item ID " . $line['li_id'] . ", " . $line['title'] . " changed to " . $line['amount'] . '.'); } } } - if (intval($arg1['li_delete_id']) > 0) { + if (intval($arg1['li_delete_id']) > 0) { + $line_item = uc_order_get_line_item($arg1['li_delete_id']); uc_order_delete_line_item($arg1['li_delete_id']); + $log[] = t('Line item id ' . $arg1['li_delete_id'] . ' was deleted.'); + if($line_item->type == 'tax'){ + $order = uc_order_load($arg1['order_id']); + $order->data['taxes_disabled'] = TRUE; + db_query("UPDATE {uc_orders} SET data = '%s' WHERE order_id = %d", serialize($order->data), $order->order_id); + $order = uc_order_load($arg1['order_id']); + } drupal_set_message(t('Line item removed.')); } + uc_order_log_changes($arg1['order_id'], $log); return; case 'edit-ops': Index: uc_order/uc_order.line_item.inc =================================================================== --- uc_order/uc_order.line_item.inc (revision 96) +++ uc_order/uc_order.line_item.inc (working copy) @@ -137,6 +137,14 @@ } /** + * Return line item by ID + */ +function uc_order_get_line_item($id){ + $result = db_query("SELECT * FROM {uc_order_line_items} WHERE line_item_id = %d", $id); + return db_fetch_object($result); +} + +/** * Add a line item to an order. */ function uc_order_line_item_add($order_id, $type, $title, $amount, $weight = NULL, $data = NULL) { Index: uc_order/uc_order.admin.inc =================================================================== --- uc_order/uc_order.admin.inc (revision 98) +++ uc_order/uc_order.admin.inc (working copy) @@ -1249,14 +1249,17 @@ } } } - + // Load line items again, since some may have been updated by the form. $order->line_items = uc_order_load_line_items($order, TRUE); - + // Merge it with the defaultish line items. $order->line_items = array_merge($order->line_items, uc_order_load_line_items($order, FALSE)); usort($order->line_items, 'uc_weight_sort'); - + + //Merge w/ stored order data in case something has changed in the database. + $order->data = array_merge($order->data, uc_order_get_data($order->order_id)); + if (variable_get('uc_order_logging', TRUE)) { uc_order_log_changes($order->order_id, $log); } Index: uc_order/uc_order.module =================================================================== --- uc_order/uc_order.module (revision 98) +++ uc_order/uc_order.module (working copy) @@ -1123,6 +1123,7 @@ } uc_order_module_invoke('save', $order, NULL); + return TRUE; } /** @@ -1942,3 +1943,15 @@ return $can_delete; } + +/** + + * Return Data values for an order + */ +function uc_order_get_data($order_id, $leave_serialized = FALSE){ + $result = db_result(db_query("SELECT data FROM {uc_orders} WHERE order_id = %d", $order_id)); + if($leave_serialized){ + return $result; + } + return unserialize($result); +} \ No newline at end of file Index: uc_taxes/uc_taxes.module =================================================================== --- uc_taxes/uc_taxes.module (revision 96) +++ uc_taxes/uc_taxes.module (working copy) @@ -159,54 +159,57 @@ function uc_taxes_order($op, $arg1, $arg2) { switch ($op) { case 'save': - $changes = array(); - $callback = _line_item_data('tax', 'callback'); - $line_items = $callback('load', $arg1); - $context = array( - 'revision' => 'formatted', - 'type' => 'line_item', - 'subject' => array( - 'order' => $arg1, - ), - ); - if (is_array($arg1->line_items)) { - //drupal_set_message('
'. var_export($arg1->line_items, TRUE) .'
'); - foreach ($arg1->line_items as $i => $line) { - if ($line['type'] == 'tax') { - $delete = TRUE; - foreach ($line_items as $id => $new_line) { - if ($new_line['title'] == $line['title']) { - if ($new_line['amount'] != $line['amount']) { - $context['subject']['line_item'] = $new_line; - uc_order_update_line_item($line['line_item_id'], $new_line['title'], $new_line['amount'], $new_line['data']); - $arg1->line_items[$i]['amount'] = $new_line['amount']; - $changes[] = t('Changed %title to %amount.', array('%amount' => uc_price($new_line['amount'], $context), '%title' => $new_line['title'])); + $order_data = uc_order_get_data($arg1->order_id); + if(!isset($order_data['taxes_disabled']) || !$order_data['taxes_disabled']){ + $changes = array(); + $callback = _line_item_data('tax', 'callback'); + $line_items = $callback('load', $arg1); + $context = array( + 'revision' => 'formatted', + 'type' => 'line_item', + 'subject' => array( + 'order' => $arg1, + ), + ); + if (is_array($arg1->line_items)) { + //drupal_set_message('
'. var_export($arg1->line_items, TRUE) .'
'); + foreach ($arg1->line_items as $i => $line) { + if ($line['type'] == 'tax') { + $delete = TRUE; + foreach ($line_items as $id => $new_line) { + if ($new_line['title'] == $line['title']) { + if ($new_line['amount'] != $line['amount']) { + $context['subject']['line_item'] = $new_line; + uc_order_update_line_item($line['line_item_id'], $new_line['title'], $new_line['amount'], $new_line['data']); + $arg1->line_items[$i]['amount'] = $new_line['amount']; + $changes[] = t('Changed %title to %amount.', array('%amount' => uc_price($new_line['amount'], $context), '%title' => $new_line['title'])); + } + unset($line_items[$id]); + $delete = FALSE; + break; } - unset($line_items[$id]); - $delete = FALSE; - break; } + if ($delete) { + uc_order_delete_line_item($line['line_item_id']); + unset($arg1->line_items[$i]); + $changes[] = t('Removed %title.', array('%title' => $line['title'])); + } } - if ($delete) { - uc_order_delete_line_item($line['line_item_id']); - unset($arg1->line_items[$i]); - $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'], $line['data']); - $line['type'] = 'tax'; - $arg1->line_items[] = $line; - $context['subject']['line_item'] = $line; - $changes[] = t('Added %amount for %title.', array('%amount' => uc_price($line['amount'], $context), '%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'], $line['data']); + $line['type'] = 'tax'; + $arg1->line_items[] = $line; + $context['subject']['line_item'] = $line; + $changes[] = t('Added %amount for %title.', array('%amount' => uc_price($line['amount'], $context), '%title' => $line['title'])); + } } + if (count($changes)) { + uc_order_log_changes($arg1->order_id, $changes); + } } - if (count($changes)) { - uc_order_log_changes($arg1->order_id, $changes); - } break; } }