Add a single product to the cart (value $155.00). This product is within a category that is restricted for the coupon named "TESTME". Store uses a 6% sales tax, which adds $9.30 to the order's total. Go to checkout. On the checkout_payment page, apply the TESTME coupon. This results in a warning message "You must spend at least $0.00 to redeem this coupon.".
It turns out that the ot_coupon's get_order_total function introduces a slight rounding error when calculating the overall order total, resulting in a total of -1.7763568394003E-15 when the product value plus tax is removed. I made the following update to that function to receive the proper message: "This coupon code is not valid for any product currently in your cart. TESTME".
Code:function get_order_total($couponCode) { global $order; $orderTaxGroups = $order->info['tax_groups']; $orderTotalTax = $order->info['tax']; $orderTotal = $order->info['total']; $products = $_SESSION['cart']->get_products(); for ($i=0; $i<sizeof($products); $i++) { if (!is_product_valid($products[$i]['id'], $couponCode)) { $products_tax = zen_get_tax_rate($products[$i]['tax_class_id']); $productsTaxAmount = (zen_calculate_tax($products[$i]['final_price'], $products_tax)) * $products[$i]['quantity']; $orderTotal -= $products[$i]['final_price'] * $products[$i]['quantity']; if ($this->include_tax == 'true') { $orderTotal -= $productsTaxAmount; } if (DISPLAY_PRICE_WITH_TAX == 'true') { $orderTotal -= $productsTaxAmount; } $orderTaxGroups[zen_get_tax_description($products[$i]['tax_class_id'])] -= $productsTaxAmount; $orderTotalTax -= (zen_calculate_tax($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']))) * $products[$i]['quantity']; } } if ($this->include_shipping != 'true') { $orderTotal -= $order->info['shipping_cost']; if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') { $orderTaxGroups[$_SESSION['shipping_tax_description']] -= $order->info['shipping_tax']; $orderTotalTax -= $order->info['shipping_tax']; } } if (DISPLAY_PRICE_WITH_TAX != 'true') { $orderTotal -= $order->info['tax']; } //-bof-20140724-lat9-Fix for negative-going orderTotal value, due to teeny rounding errors during the tax calculations if ($orderTotal < 0) { $orderTotal = 0; } //-eof-20140724-lat9 return array('orderTotal'=>$orderTotal, 'orderTaxGroups'=>$orderTaxGroups, 'orderTax'=>$orderTotalTax, 'shipping'=>$order->info['shipping_cost'], 'shippingTax'=>$order->info['shipping_tax']); }


Reply With Quote

