webdesignpro Posted December 13, 2002 Share Posted December 13, 2002 I'm testing my installation of the Members Discount contribution, and I can't get the calculations to come out right on the checkout_confirmation.php page. I've set the discount to 10%, and Tax to 4%. I've also set the handing charge to $2 per order. When I process an order for my test user in the taxable state, here is an example of the numbers: Product 1 $18.50 Product 2 $21.50 Discount: $4.16 Sub-Total: $40.00 Tax: $1.44 USPS Priority mail 1 x 2.75: $6.75 Total: $44.19 From what I can tell, the $2.00 handling charge is not being added, unless it is automatically included in the shipping price. The shipping price shown here is the exact same price shown on the checkout page where I choose the preferred rate. The sub-total should display as $36.00, but instead it is showing the total BEFORE the discount. I've changed the sorting order around a few times to see it it makes any difference, but it shows up as $40 for this particular order no matter where it is. The members discount of 10% on a $40.00 order should be $4.00, not $4.16. Curiosly, the tax appears to be correcly calculated at 4% of $36, which is what the correct subtotal should be minus the correct $4 discount. Amazingly, the total is CORRECT. If you start with $40, give a $4 discount, tax $36 at 4%, add the tax ($1.44) and shipping ($6.75) to $36.00 and you get $44.19. So... why does the discount show $4.16? Here are my setting for the Member Discount in Modules... Order Total: Include Shipping in calculation: false Include Tax in calculation: false Calculate Tax: true If I change the settings of "Include Tax in calculation" to TRUE, the tax stays at $1.44, but the Discount jumps to $4.32 and the total changes to $44.03. = WRONG SETTINGS If I change the settings to ALL FALSE, the Tax jumps to $1.60 (4% of $40, the pre-discount total), the Discount shows $4.00 (which is finally correct), and the total is $44.35 = WRONG SETTINGS Basically, my original settings are getting the correct Tax and Total calculations, which matters most... but my client is complaining because the Sub-Total and Discount totals don't DISPLAY properly, even though the calculations for the total are actually based on CORRECT numbers for these two fields. For one last test, I changed to an out-of-state address, and without any Tax added, the discount showed-up as $4, which is correct. Apparently the code for the discount calculations is set to DISPLAY the discount based on the correct subtotal+tax, even though it doesn't actually use this formula in the calculation of the Total. Any ideas how to fix this? Tim Wasson? Ian Wilson? Can anyone else help? Quote -- Harold Corbin Link to comment Share on other sites More sharing options...
Ian Posted December 13, 2002 Share Posted December 13, 2002 1. IIRC The discount module does not recalculate the sub-total hence the reason it is not affected although the code to do this is fairly trivial. 2. Again IIRC if recalculate_tax is true the discount is shown with the amount including discounted tax amount. hence 4.00 + 0.16. Two things could be done here, either not show the extra tax discount or make the discount amount conform to DISPLAY_PRICES_WITH_TAX setting, either would solve your problem. I'll see if I can whip up some code. Quote Trust me, I'm an Accountant. Link to comment Share on other sites More sharing options...
webdesignpro Posted December 13, 2002 Author Share Posted December 13, 2002 Thanks Ian. If you could give me code changes (and where they go), I would really appreciate it. I can copy and move PHP code, but I'm not far enough through my 400+ page book to WRITE anything this complicated yet. Quote -- Harold Corbin Link to comment Share on other sites More sharing options...
webdesignpro Posted December 17, 2002 Author Share Posted December 17, 2002 Any ideas why the handling charge isn't included? Quote -- Harold Corbin Link to comment Share on other sites More sharing options...
webdesignpro Posted December 17, 2002 Author Share Posted December 17, 2002 OK, after some experimenting I figured out that the handling charge is included in the shipping price. Now if I can just get the corrected code for the discounts, I will be in good shape. Quote -- Harold Corbin Link to comment Share on other sites More sharing options...
Ian Posted December 17, 2002 Share Posted December 17, 2002 Harold, The code change is fairly simple. you need to look for these line in the calculate_credit function $od_amount = round($amount*10)/10*$od_pc/100; $od_amount = $od_amount + $tod_amount; simply comment out the 2nd line so you have $od_amount = round($amount*10)/10*$od_pc/100; // $od_amount = $od_amount + $tod_amount; If you also want the sub_total to have the discount taken off find this lines in function process $order->info['total'] = $order->info['total'] - $od_amount; and add a line just after it $order->info['subtotal'] -= $od_amount; HTH Quote Trust me, I'm an Accountant. Link to comment Share on other sites More sharing options...
webdesignpro Posted December 17, 2002 Author Share Posted December 17, 2002 It worked perfectly! THANK YOU!!! Quote -- Harold Corbin Link to comment Share on other sites More sharing options...
Ian Posted December 17, 2002 Share Posted December 17, 2002 Now there's a first for me - code working first time :D Quote Trust me, I'm an Accountant. Link to comment Share on other sites More sharing options...
webdesignpro Posted December 17, 2002 Author Share Posted December 17, 2002 Errr... sorry, Ian. I spoke to soon. Now another problem. Now the discount is correct, and the tax is correct, but the total is wrong. It appears now that the total is calculating tax on the subtotal before the discount is subtracted ($.94) ? something that worked fine before you fixed the discount problem ? even though it is displaying the correct tax ($.85). The total should be $25.95. This is how it looks now: Sub-Total: $23.50 10% Resellers Discount: $2.35 4% Tax: $0.85 USPS priority Mail 1 X 1.65: $3.95 Total: $26.04 Any ideas? Quote -- Harold Corbin Link to comment Share on other sites More sharing options...
Ian Posted December 17, 2002 Share Posted December 17, 2002 The problem is the calculation function I originally wrote is a ball of chalk. More recent versions of the credit class completely separate the tax calculation from the deduxtion calculation. For your problem, I thnk the fix is $od_amount = round($amount*10)/10*$od_pc/100; // $od_amount = $od_amount + $tod_amount; change to $od_amount = round($amount*10)/10*$od_pc/100; order->info['total'] -= $tod_amount; // $od_amount = $od_amount + $tod_amount; Quote Trust me, I'm an Accountant. Link to comment Share on other sites More sharing options...
webdesignpro Posted December 28, 2002 Author Share Posted December 28, 2002 Ian, I tried that code, but I get this error when I click "Continue" on the Payment Method Page: Parse error: parse error in /home/mybigtoe/public_html/catalog/includes/modules/order_total/ot_xmembers.php on line 66 Fatal error: Cannot instantiate non-existent class: ot_xmembers in /home/mybigtoe/public_html/catalog/includes/classes/order_total.php on line 29 I think you missed something in the part that says "order->info['total'] -= $tod_amount;" because there is a minus right next to an equals sign. I tried using just the minus and just the equals, but it still generated the error. Now what? Quote -- Harold Corbin Link to comment Share on other sites More sharing options...
Ian Posted December 29, 2002 Share Posted December 29, 2002 Thats because I should have put $order->info['total'] -= $tod_amount; note I missed the opening $ BTW $order->info['total'] -= $tod_amount; is functionally equivalent to $order->info['total'] = $order->info['total']-$tod_amount; Quote Trust me, I'm an Accountant. Link to comment Share on other sites More sharing options...
webdesignpro Posted February 15, 2003 Author Share Posted February 15, 2003 Ian, Now that we're finally testing the authorizenet payment module before the site goes live in a few days, we've discovered that the amount being passed from OSC to Authorizenet is not including the discount. In other words, the amount shown on the confirmation page shows the discounted price, but when I check the order total in my authorizenet settlement file, it charged the customer the full price (no discount). Any ideas? -Harold Quote -- Harold Corbin Link to comment Share on other sites More sharing options...
Ian Posted February 17, 2003 Share Posted February 17, 2003 Which authorize.net module are you using. If it is the contributed module then the problem will almost certainly be on checkout_process.php. You have to ensure that the order_total modules are loaded and instantiated before the added include file for auhorize.net Quote Trust me, I'm an Accountant. Link to comment Share on other sites More sharing options...
jamaicasearch Posted May 25, 2003 Share Posted May 25, 2003 Ian the sulution u gave for fixing the members discount was great ...the problem with "CUSTOMER SPECIFIC DISCOUNT IS THE SAME as member discount error..count u seggest a fix for this too? Quote Link to comment Share on other sites More sharing options...
Redtail Posted June 9, 2003 Share Posted June 9, 2003 Ian If you have any ideas about how to fix this one also I would appreciate it. Thanks in advance Quote Link to comment Share on other sites More sharing options...
shris Posted December 27, 2003 Share Posted December 27, 2003 Hi. I had the same problems as an earlier poster, and the earlier fixes (having to do with TOD_AMOUNT) worked well. The problem I have now is when I have two discount modules installed. I have Qty_Discounts 1.2 and Customer Specific Discounts 1.3. Both modules work correctly when only one is turned on. When both are turned on, everything calculates correctly EXCEPT the display value shown for the tax. For both modules, include shipping and include tax are off and calculate tax is on. Example order: 100 x Test Product = $2500.00 Sub-Total: $2,500.00 Quantity Discount (30%): $750.00 Customer Discount: $490.00 - for this customer the discount is 28% NC TAX 7.0%: $126.00 Table Rate (Best Way): $320.00 Total: $1,668.20 The Total is correct, but the NC TAX display amount is wrong. It should show $88.20. The display tax is apparently calculating based on ignoring the quantity discount, but pretending the customer discount is applied to the entire subtotal. Incidentally, reversing the sort order of the two modules results in the same (correct) total with the same (incorrect) display tax. The other individual line items show and calculate correctly. The relevant portion of the code in 'customer discount' looks like this: function calculate_discount($amount) { global $order, $customer_id; $od_amount=0; $query = tep_db_query("select customer_discount from " . TABLE_CUSTOMERS . " where customers_id = '" . $customer_id . "'"); $query_result = tep_db_fetch_array($query); $od_pc = $query_result['customer_discount']; if ($query_result['customer_discount'] > 0) { // Calculate tax reduction if necessary if ($this->calculate_tax == 'true') { // Calculate main tax reduction $tod_amount = round($order->info['tax']*10)/10*$od_pc/100; $order->info['tax'] = $order->info['tax'] - $tod_amount; // Calculate tax group deductions reset($order->info['tax_groups']); while (list($key, $value) = each($order->info['tax_groups'])) { $god_amount = round($value*10)/10*$od_pc/100; $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; } } $od_amount = (round($amount*10)/10)*$od_pc/100; $order->info['total'] -= $tod_amount; // $od_amount = $od_amount + $tod_amount; } return $od_amount; } And the relevant portion of Qty Discounts looks like this: function process() { global $order, $currencies, $cart, $ot_subtotal; if ($this->calculate_tax == 'true') { $tod_amount = $this->calculate_discount($order->info['tax']); } $od_amount = $this->calculate_discount($this->get_order_total()); if ($od_amount>0) { if (MODULE_QTY_DISCOUNT_RATE_TYPE == 'percentage') $title_ext = ' ('.$this->calculate_rate($cart->count_contents()).'%)'; $this->deduction = $od_amount+$tod_amount; $this->output[] = array('title' => $this->title . $title_ext . ':', 'text' => '<b>' . $currencies->format($od_amount) . '</b>', 'value' => $od_amount); $order->info['total'] = $order->info['total'] - $od_amount - $tod_amount; if ($this->sort_order < $ot_subtotal->sort_order) { $order->info['subtotal'] = $order->info['subtotal'] - $od_amount - $tod_amount; } $order->info['tax'] = $order->info['tax'] - $tod_amount; } } It appears the two discount modules were written at different times in the development of the methodology. I'm having a rough time tracing exactly where the problem is. I'd appreciate any help anyone can provide. Thanks. shris Quote Link to comment Share on other sites More sharing options...
Guest Posted July 9, 2004 Share Posted July 9, 2004 Hi my problem is that I offer free shipping for all orders over $30.00 - but I want this to apply to orders after discount - i.e. invoiced orders over $30.00 ie. as an example if I have a members discount of 15% and an item the purchase costs $35.00 - the would normally get free shipping o.k. on this item but when you apply 15% discount the invoiced total then = $29.75 - basically I want shipping to be charged for this total, but it is not. Is there a way to make it re-calcutate order total after discount and charge for shipping if discounted total = less than my free shipping total after all??? any help would be appreciated. cheers Maria Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.