diff --git a/uc_taxes/uc_taxes.module b/uc_taxes/uc_taxes.module index d5b998a..9e7abc1 100644 --- a/uc_taxes/uc_taxes.module +++ b/uc_taxes/uc_taxes.module @@ -413,8 +413,10 @@ function uc_taxes_filter_rates($order) { // For orders no longer in checkout, only the saved tax rates can apply. elseif (isset($order->order_status) && uc_order_status_data($order->order_status, 'state') != 'in_checkout') { if (isset($order->line_items)) { + $order_tax_count = 0; foreach ($order->line_items as $item) { if ($item['type'] == 'tax') { + $order_tax_count += 1; if (!empty($item['data']['tax'])) { // Use the rate stored in the line-item. $taxes[] = clone $item['data']['tax']; @@ -430,6 +432,19 @@ function uc_taxes_filter_rates($order) { } } } + // count the actual no of taxes + // that can be applied to an order + $actual_tax_count = uc_taxes_get_tax_count(); + + // Check if all the taxes are applied to current order + // if not apply all the taxes that are applicable to current order + if ($order_tax_count < $actual_tax_count) { + foreach (uc_taxes_rate_load() as $rate) { + if (rules_invoke_component('uc_taxes_' . $rate->id, $order)) { + $taxes[] = clone $rate; + } + } + } } } // For orders still in checkout, any tax whose conditions are satisfied can @@ -682,3 +697,23 @@ function uc_taxes_get_included_tax($product, $order = NULL) { return array($amount, $suffixes); } + +/** +* Counts the number of taxes that can be applied to an order +* +* @return +* The number of taxes that can be applied to an order +*/ +function uc_taxes_get_tax_count() { + $tax_count = 0; + + // Get all the rate data from the database. + $result = db_query("SELECT * FROM {uc_taxes} ORDER BY weight"); + + // Loop through each returned row. + foreach ($result as $rate) { + $tax_count++; + } + + return $tax_count; +}