Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

please verify/review bug in lev_discount


felixs

Recommended Posts

Hello,

 

I install the lev_discount contribution two hours ago. Everything seems to work but the bill wasn't calculated correctly... (using osC M2 and lev_discount v2.3)

 

I couldn't find the email address of the author (Ian Wilson?) so I'm writing here. If this is the wrong forum please feel free to move my post.

 

example:

sub total: 419,95 Euro

price break (4%) should be: 16,80

tax (16%): 64,50 (16% of 419,55 - 16,80)

total: 467,65

 

but actually displayed was:

sub total: 419,95 Euro

price break: 19,49 <= wrong!

tax: 64,50

total: 467,65

 

After looking into the source code I think I know what's going wrong but as a newbie to osc (allthough with a solid computer science background) I don't know if my modifcations can cause unwanted side effects so please be careful.

 

Look in function process() - lev_discount.php

if ($od_amount>0) {
$this->deduction = $od_amount;
$this->output[] = array('title' => $this->title . ':',
 'text' => '<b>' .$currencies->format($od_amount) . '</b>',
 'value' => $od_amount);
$order->info['total'] = $order->info['total'] - $od_amount;

 

that should be around line 40.

 

the last line contains the error (imho) as the module distracts the wrong value. My approach is to recalculate the whole amount which works with my configuration but maybe I'm missing some other discounts/fees. Replace the last line (and only the last one!) with...

$order->info['total'] = $order->info['tax'] + $order->info['subtotal'] + $order->info['shipping_cost'] - $od_amount;

 

and in function calculate_credit (around line 77)

    $od_amount = round($amount*10)/10*$od_pc/100;
   $od_amount = $od_amount + $tod_amount;
   return $od_amount;

 

_delete_ the secound line.

 

 

While looking at the source I noticed another thing:

$od_amount = $this->calculate_credit($this->get_order_total());

 

get_order_total return a wrong value in my configuration (ca. 3 EUR to high) but that doesn't influenced the end value. I'm surprised about the fact that this module calculates the sub total be itself because you can ask the order object about the subtotal.

 

So I replaced the line above with this one:

$od_amount = $this->calculate_credit($order->info['subtotal']);

 

Please tell me if me modifications are correct and if they can cause side-effects. What is the 'osCommerce'-Style of submitting patches for a contribution?

 

Felix Schwarz

Germany

 

-- sorry for my bad english

Link to comment
Share on other sites

  • 1 year later...

Felix, I was having the same problem with the lev_discount contribution and tried your fix.

 

It seems to work for me, I haven't found any problems elsewhere on the site because of it yet.

 

Thank you so much for sharing your solution!!

Patti

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...