Magento & Paypal rounding issue

I have some rounding issues with Paypal and Magento 1.7.0.2. All prices on the website include tax, and the tax is 20% (VAT).

I will go for verification and everything will be correct:

enter image description here

Then I click on the address of the place, and Paypal will be such, which is wrong, because the total amount is now 1p less. This, apparently, is the reason for how the tax is rounded.

enter image description here

In some cases, it works fine, but in others, the tax is rounded off incorrectly. I tried to make changes to the calcTaxAmount () tax calculation method in application / code / kernel / Mage / Tax / Model / Calculation.php

I added this to the calcTaxAmount method, which seemed to fix it, but this led to the prices on the product page being incorrect (1p less).

$amount = $this->roundUp($amount);

, , . - , . .

EDIT: Magento

enter image description here

+5
6

, , .

, .

- In Mage_Tax_Model_Calculation:: calcTaxAmount():

:

if ($priceIncludeTax)...

if ( ! $priceIncludeTax ) ...

, :

if ( ! $priceIncludeTax ) { 
    $amount = $price*(1-1/(1+$taxRate)); 
} else { 
    $amount = $price*$taxRate; 
}

. : http://www.magentocommerce.com/boards/viewthread/247201/P45/

-

+2

"" , . .

, : //​​ ​​/Mage/Paypal//Api/Nvp.php

( -) 606, .

$request['SHIPPINGAMT'] = ($request['AMT'] - ($request['TAXAMT'] + $request['ITEMAMT']));

$response = $this->call(self::SET_EXPRESS_CHECKOUT, $request);
$this->_importFromResponse($this->_setExpressCheckoutResponse, $response);

paypal moule

- , shippingcost,

+2

(, -, magento ), ShopWorks ( , !) , -, ​​, .) $request (/hack):

606 Nvp.php :

$totalValue = $request['TAXAMT'] + $request['ITEMAMT'];
$finalValue = $totalValue - $request['AMT'];

if($request['SHIPPINGAMT'] > 0) {
    $request['SHIPPINGAMT'] = ($request['AMT'] - ($request['TAXAMT'] + $request['ITEMAMT']));
    $totalValue = $request['TAXAMT'] + $request['ITEMAMT'] + $request['SHIPPINGAMT'];
    $finalValue = $totalValue - $request['AMT'];
}

if($request['AMT'] != $totalValue) {
    if($totalValue > $request['AMT']) {
        $request['TAXAMT'] = $request['TAXAMT'] - $finalValue;
    } elseif($totalValue < $request['AMT']) {
        $request['TAXAMT'] = $request['TAXAMT'] + $finalValue;
    } else {
        $request['AMT'] = $request['TAXAMT'] + $request['ITEMAMT'];
    }
}

, call() ( 938 Nvp.php):

$totalValue = $request['TAXAMT'] + $request['ITEMAMT'] + $request['SHIPPINGAMT'];
$finalValue = $totalValue - $request['AMT'];

if($request['AMT'] != $totalValue) {
    if($totalValue > $request['AMT']) {
        if($finalValue > 0) {
            // its preferable that we change the tax amount over the grand total amount
            $request['TAXAMT'] = $request['TAXAMT'] - $finalValue;
        } else {
            $request['AMT'] = $totalValue;
        }
    } elseif($totalValue < $request['AMT']) {
        if($finalValue > 0) {
            // its preferable that we change the tax amount over the grand total amount
            $request['TAXAMT'] = $request['TAXAMT'] + $finalValue;
        } else {
            $request['AMT'] = $totalValue;
        }
    } else {
        $request['AMT'] = $totalValue;
    }
}

. , , , , ( , , , ).

, $request ['AMT'], , $finalValue -0,9999, -, , , - , , !

, nvp.php , app/local/mage. !: -)

+1

Magento ( , Magento 1.8.0) "" Paypal; Mage_Paypal_Model_Cart.

, _validate() 381 , ( getBaseGrandTotal())

( , ); getItems() 146 false.

, " " .

, ( 404):

if (sprintf('%.4F', $sum) == sprintf('%.4F', $referenceAmount)) {
    $this->_areItemsValid = true;
}

to

$diff = abs(sprintf('%.4F', $sum) - sprintf('%.4F', $referenceAmount));

if ($diff < 0.01) {
     $this->_areItemsValid = true;
}

, 0,009999999...

, .

+1

CE1.7.0.2 , , , Adam Hall fix/hack. , , , , .

, , . , , , , , paypal. , ,

if ($request['TAXAMT'] > 0) {
    $request['TAXAMT'] = $request['TAXAMT'] - $finalValue;
} else {
    $request['SHIPPINGAMT'] = $request['SHIPPINGAMT'] - $finalValue;
}

, . (, , , , , .) , , , .

0

"", .. .

Magento 1.9.0.1

just FYI - a test if it works for you.

Dmitry

-1
source

All Articles