I recently started a new job where I maintain 5 shopping carts all built off of Zen Cart 1.3.8a. I’ve had brushes with Zen Cart in the past so I knew I was in for a lot of work. The thing about Zen Cart is that there are lots of problems that never seem to get fixed. I imagine that the Zen Cart development team’s elitist attitude has a lot to do with that. If you click on the link titled “Interested in being a Team Member?” on the Zen Cart Team page you are taken to a page that ends with “don’t call us … we will call you.”
That’s my Zen Cart mini-rant for the day. One of the bugs that has been around for ever is a problem with PayPal transactions. When PayPal receives a transaction you send an item total, grand total and if appropriate a shipping and handling totals. All of these totals must add up to the grand total or PayPal rejects the transaction, the invalid argument is incorrect grand total. The pattern is that totals over $1,000 dollars get screwed up, usually coming up as $1.00. There are pages of forum posts where there seems to be no real resolution. There people that claim to have fixed it by fiddling with settings, but nothing that really made sense.
I setup test server and spent the day hacking on the PayPal module until I discovered a small bug in the code on line 537 of includes/modules/payment/paypalwpp.php. The php number_format() function is used. If you pass “1,560.95″ to number_format() you get 1.00 back. The function sees everything after the comma as a string and strips it off. The value $option['AMT'] contains a thousand separator and is seen by PHP as a string where as $order_amount is passed without the thousand separator and seen as a double.
The offending line:
number_format((isset($options['AMT']) ? $options['AMT'] : $order_amount), 2)
I would guess that when people “fix” this by screwing around with settings they are creating a condition where $option['AMT'] isn’t set and the number_format function gets $order_amount instead. The line of code, 537, is part of a larger statement that starts on line 535. I pasted my patch on live 534. It simply strips out the commas:
// LS PATCH - remove commas so number_format doesn't screw up values over 1000
$options['AMT'] = str_replace(',', '', $options['AMT']);
So this fixed it for me. As far as currencies go our cart is pretty simple, only USD and CAD. If you use a currency that uses a different thousands separator you will need to modify the code. If you are unsure of how to do this drop me a line I can help you out. Better yet if you patch it your self send me the code, I’m including this patch in the alpha three release of Dao Cart.