Skip to content

Commit

Permalink
Merge pull request #19 in DEV-MO/shopware5-module from feature/SHPWR-…
Browse files Browse the repository at this point in the history
…347_fix-rounded-price-discrepancies to release/5.2.4

* commit 'c6ca0d7ba7ae8f2ed1004d824810fcc5acb9b8c7':
  [SHPWR-347] round item prices for b2b shops
  [SHPWR-347] fix rounded price discrepancies
  • Loading branch information
eiriarte-mendez committed Sep 11, 2018
2 parents c7730f2 + c6ca0d7 commit 6852107
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function toArray()
$amount += floatval($unitPrice);
}

$this->admittedFields['Amount']['value'] = $amount;
$this->admittedFields['Amount']['value'] = round($amount, 2);
}

return parent::toArray();
Expand Down
16 changes: 6 additions & 10 deletions Component/Library/src/Service/Math.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace RatePAY\Service;
use RpayRatePay\Component\Service\Logger;


/**
Expand All @@ -13,20 +14,15 @@ class Math
/**
* @param float $netPrice
* @param float|int $taxPercentage
* @param bool $round
* @param bool $roundToTwoDecimals
* @return float
*/
public static function netToGross($netPrice, $taxPercentage, $round = false)
public static function netToGross($netPrice, $taxPercentage, $roundToTwoDecimals = false)
{
$withTax = $netPrice + $netPrice * $taxPercentage / 100;
$withTax = $netPrice + ($netPrice * $taxPercentage / 100);
$precision = $roundToTwoDecimals ? 2 : 3;

if (!$round) {
return $withTax;
}

$rounded = round($withTax, 2);

return $rounded;
return round($withTax, $precision);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Component/Mapper/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ private function getShippingItemData(PaymentRequestData $shippingData, $useFallb
Math::netToGross($shippingData->getShippingCost(), $shippingData->getShippingTax()) :
$shippingData->getShippingCost();

$priceGross = round($priceGross, 2);
$priceGross = round($priceGross, 3);

$item = [
'Description' => 'Shipping costs',
Expand Down
2 changes: 2 additions & 0 deletions Component/Service/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public function setPaymentStatusPaid($order)
/**
* @param $transactionId
* @param \Shopware\Models\Order\Order $order
* @param bool $backend
* @throws \Exception
*/
public function sendPaymentConfirm($transactionId, $order, $backend = false)
{
Expand Down
2 changes: 1 addition & 1 deletion Controller/frontend/RpayRatepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function saveUserDataAction()

/** @var Shopware\Models\Customer\Customer $userModel */
$userModel = $customerModel->findOneBy(['id' => Shopware()->Session()->sUserId]);
$userWrapped = new ShopwareCustomerWrapper($userModel);
$userWrapped = new ShopwareCustomerWrapper($userModel, Shopware()->Models());

if (isset($Parameter['checkoutBillingAddressId']) && !is_null($Parameter['checkoutBillingAddressId'])) { // From Shopware 5.2 current billing address is sent by parameter
$addressModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Address');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ public function createFormattedResult()
$currency = '&euro;';
$decimalSeperator = ',';
$thousandSepeartor = '.';
}
else {
} else {
$currency = '&euro;';
$decimalSeperator = '.';
$thousandSepeartor = ',';
Expand Down

0 comments on commit 6852107

Please sign in to comment.