Xonu_RoundingErrorFix - Version 1.0.1

Version Notes

Fixes rounding error in Magento 1.7.x.x and PayPal.

Download this release

Release Info

Developer Pawel Kazakow
Extension Xonu_RoundingErrorFix
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

app/code/community/Xonu/RoundingErrorFix/Model/Api/Standard.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Xonu_RoundingErrorFix_Model_Api_Standard extends Mage_Paypal_Model_Api_Standard {
4
+ /**
5
+ * Filter amounts in API calls
6
+ * @param float|string $value
7
+ * @return string
8
+ */
9
+ protected function _filterAmount($value)
10
+ {
11
+ // return sprintf('%.2F', $value); // original line would round e. g. 30.605 to 30.60
12
+ return sprintf('%.2F', round($value, 2)); // the modified line would round 30.605 to 30.61
13
+ }
14
+ }
app/code/community/Xonu/RoundingErrorFix/Model/Sales/Order/Payment.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @copyright (c) 2013, Pawel Kazakow <support@xonu.de>
4
+ * @license http://xonu.de/license/ xonu.de EULA
5
+ */
6
+
7
+
8
+ class Xonu_RoundingErrorFix_Model_Sales_Order_Payment extends Mage_Sales_Model_Order_Payment {
9
+
10
+ protected function _formatAmount($amount, $asFloat = false)
11
+ {
12
+ // $amount = Mage::app()->getStore()->roundPrice($amount);
13
+ $amount = round($amount,2);
14
+ return !$asFloat ? (string)$amount : $amount;
15
+ }
16
+
17
+ }
app/code/community/Xonu/RoundingErrorFix/Model/Store.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @copyright (c) 2013, Pawel Kazakow <support@xonu.de>
5
+ * @license http://xonu.de/license/ xonu.de EULA
6
+ */
7
+
8
+ class Xonu_RoundingErrorFix_Model_Store extends Mage_Core_Model_Store {
9
+
10
+ /**
11
+ * Round price
12
+ *
13
+ * @param mixed $price
14
+ * @return double
15
+ */
16
+ public function roundPrice($price)
17
+ {
18
+ // return round($price, 2); // original code
19
+ return round($price, 4);
20
+ }
21
+ }
app/code/community/Xonu/RoundingErrorFix/etc/config.xml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ @copyright (c) 2013, Pawel Kazakow <support@xonu.de>
4
+ @license http://xonu.de/license/ xonu.de EULA
5
+ -->
6
+ <config>
7
+ <modules>
8
+ <Xonu_RoundingErrorFix>
9
+ <version>1.0.1</version>
10
+ </Xonu_RoundingErrorFix>
11
+ </modules>
12
+ <global>
13
+
14
+ <models>
15
+ <core>
16
+ <rewrite>
17
+ <store>Xonu_RoundingErrorFix_Model_Store</store>
18
+ </rewrite>
19
+ </core>
20
+ <paypal>
21
+ <rewrite>
22
+ <api_standard>Xonu_RoundingErrorFix_Model_Api_Standard</api_standard>
23
+ </rewrite>
24
+ </paypal>
25
+ <sales>
26
+ <rewrite>
27
+ <order_payment>Xonu_RoundingErrorFix_Model_Sales_Order_Payment</order_payment>
28
+ </rewrite>
29
+ </sales>
30
+ </models>
31
+
32
+ </global>
33
+ </config>
app/etc/modules/Xonu_RoundingErrorFix.xml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ @copyright (c) 2013, Pawel Kazakow <support@xonu.de>
4
+ @license http://xonu.de/license/ xonu.de EULA
5
+ -->
6
+ <config>
7
+ <modules>
8
+ <Xonu_RoundingErrorFix>
9
+ <active>true</active>
10
+ <codePool>community</codePool>
11
+ <depends>
12
+ <Mage_Paypal/>
13
+ <Mage_Sales/>
14
+ </depends>
15
+ </Xonu_RoundingErrorFix>
16
+ </modules>
17
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Xonu_RoundingErrorFix</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://xonu.de/license">xonu.de EULA</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Fixes rounding error in Magento 1.7.x.x and PayPal.</summary>
10
+ <description>There is a rounding error in Magento 1.7. Example: If a product costs 9.99 incl. tax. 19% and shipping is 5.00 these values add up to 15.00 in the cart. The correct value would be 14.99.</description>
11
+ <notes>Fixes rounding error in Magento 1.7.x.x and PayPal.</notes>
12
+ <authors><author><name>Pawel Kazakow</name><user>xonu</user><email>support@xonu.de</email></author></authors>
13
+ <date>2013-10-08</date>
14
+ <time>19:04:10</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Xonu_RoundingErrorFix.xml" hash="fc60ed34d31316a139635137222c8442"/></dir></target><target name="magecommunity"><dir name="Xonu"><dir name="RoundingErrorFix"><dir name="Model"><dir name="Api"><file name="Standard.php" hash="530661d1c7de367456acab1efe3df0b0"/></dir><dir name="Sales"><dir name="Order"><file name="Payment.php" hash="d5ec636bc978992d177977d52d9d17eb"/></dir></dir><file name="Store.php" hash="8a16dddbefeedc7a8e24b466d4ce5246"/></dir><dir name="etc"><file name="config.xml" hash="beceed94efe87af4d2f2ee6ca2d3de16"/></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>