情報
以前の丸め操作のデルタに基づくMagentoの丸め価格。
app / code / core / Mage / Tax / Model / Sales / Total / Quote / Tax.php:1392
app / code / core / Mage / Tax / Model / Sales / Total / Quote / Subtotal.php:719
protected function _deltaRound($price, $rate, $direction, $type = 'regular')
{
if ($price) {
$rate = (string)$rate;
$type = $type . $direction;
// initialize the delta to a small number to avoid non-deterministic behavior with rounding of 0.5
$delta = isset($this->_roundingDeltas[$type][$rate]) ? $this->_roundingDeltas[$type][$rate] : 0.000001;
$price += $delta;
$this->_roundingDeltas[$type][$rate] = $price - $this->_calculator->round($price);
$price = $this->_calculator->round($price);
}
return $price;
}
これにより、高デルタ計算エラー($this->_calculator->round($price)
)が原因でエラーが発生する場合があります。たとえば、このため、一部の価格は±1セントの範囲で変動する可能性があります。
解決
これを回避するには、デルタ計算の精度を向上させる必要があります。
変化する
$this->_roundingDeltas[$type][$rate] = $price - $this->_calculator->round($price);
に
$this->_roundingDeltas[$type][$rate] = $price - round($price, 4);
両方のファイルに変更を加える必要があります。
app / code / core / Mage / Tax / Model / Sales / Total / Quote / Tax.php:1392
app / code / core / Mage / Tax / Model / Sales / Total / Quote / Subtotal.php:719
コアファイルを変更したりハッキングしたりしないでください。書き直してください!
ソリューションはMagento1.9.xのさまざまなバージョンでテストされましたが、これは以前のバージョンでも機能する可能性があります。
PS
以下に示すように、関数の変更roundPrice
は丸め誤差の問題を解決できますが、他の問題を引き起こす可能性があります(たとえば、一部のプラットフォームでは小数点以下2桁までの丸めが必要です)。
app / code / core / Mage / Core / Model / Store.php:995
public function roundPrice($price)
{
return round($price, 4);
}