Skip to content

Commit

Permalink
Merge pull request #16 in DEV-MO/shopware5-module from fix/SHPWR-334-…
Browse files Browse the repository at this point in the history
…tax-on-shipping-item-in-xml-sometimes-zero to release/5.2.3

* commit '6e93313a50ae2d46d771f3db87b0d5728a4e4f77':
  fix/SHPWR-334-tax-on-shipping-item-in-xml-sometimes-zero)
  fix/SHPWR-334-tax-on-shipping-item-in-xml-sometimes-zero
  fix/SHPWR-334-tax-on-shipping-item-in-xml-sometimes-zero standardize shipping to pattern for other items
  fix/SHPWR-334-tax-on-shipping-item WIP
  • Loading branch information
rpWhittington committed Aug 27, 2018
2 parents c6c6941 + 6e93313 commit 11c48da
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
13 changes: 10 additions & 3 deletions Bootstrapping/Events/BackendOrderControllerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace RpayRatePay\Bootstrapping\Events;

use RatePAY\Service\Math;
use RatePAY\Service\Util;
use RpayRatePay\Component\Mapper\PaymentRequestData;
use RpayRatePay\Component\Service\PaymentProcessor;
Expand Down Expand Up @@ -121,9 +122,15 @@ private function orderStructToPaymentRequestData(\SwagBackendOrder\Components\Or
$items[] = $this->positionStructToArray($positionStruct);
}

$shippingCost = $orderStruct->getShippingCosts();
$shippingTax = Math::taxFromPrices(
$orderStruct->getShippingCostsNet(),
$orderStruct->getShippingCosts()
);

//looks like vat is always a whole number, so I'll round
$shippingTax = round($shippingTax);

$shippingTax = $orderStruct->getShippingCostsNet() - $orderStruct->getSHippingCostsNet();
$shippingToSend = $orderStruct->getNetOrder() ? $orderStruct->getShippingCostsNet() : $orderStruct->getShippingCosts();

$dfpToken = '';

Expand All @@ -133,7 +140,7 @@ private function orderStructToPaymentRequestData(\SwagBackendOrder\Components\Or

$amount = $orderStruct->getTotal();

return new PaymentRequestData($method, $customer, $billing, $shipping, $items, $shippingCost, $shippingTax, $dfpToken, $lang, $amount);
return new PaymentRequestData($method, $customer, $billing, $shipping, $items, $shippingToSend, $shippingTax, $dfpToken, $lang, $amount);
}

private function positionStructToArray(\SwagBackendOrder\Components\Order\Struct\PositionStruct $item)
Expand Down
11 changes: 11 additions & 0 deletions Component/Library/src/Service/Math.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@ public static function netToGross($netPrice, $taxPercentage, $round = false)

return $rounded;
}

/**
* @param float|int $netPrice
* @param float|int $grossPrice
* @return float|int
*/
public static function taxFromPrices($netPrice, $grossPrice)
{
$tax = ($grossPrice - $netPrice) / $netPrice;
return $tax * 100;
}
}
20 changes: 8 additions & 12 deletions Component/Mapper/ModelFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use RatePAY\Service\Math;
use RpayRatePay\Component\Mapper\PaymentRequestData;
use RpayRatePay\Component\Mapper\BankData;
use RatePAY\Service\Util;
Expand Down Expand Up @@ -818,9 +819,15 @@ public function getSecurityCode($countryCode = false)
*/
private function getShippingItemData(PaymentRequestData $shippingData, $useFallbackShipping = false)
{
$priceGross = $this->netItemPrices ?
Math::netToGross($shippingData->getShippingCost(), $shippingData->getShippingTax()) :
$shippingData->getShippingCost();

$priceGross = round($priceGross, 2);

$item = [
'Description' => 'Shipping costs',
'UnitPriceGross' => $shippingData->getShippingCost(),
'UnitPriceGross' => $priceGross,
'TaxRate' => $shippingData->getShippingTax(),
];

Expand All @@ -830,17 +837,6 @@ private function getShippingItemData(PaymentRequestData $shippingData, $useFallb
$item['Description'] = 'shipping';
}

$system = Shopware()->System();
$userGroup = Shopware()->Db()->fetchRow('
SELECT * FROM s_core_customergroups WHERE groupkey = ?
', [$system->sUSERGROUP]);

if ($userGroup['tax'] == 0) {
$cost = $item['UnitPriceGross'];
$tax = $item['TaxRate'];
$item['UnitPriceGross'] = number_format($cost / 100 * $tax + $cost , 2);
}

return $item;
}

Expand Down
2 changes: 1 addition & 1 deletion Component/Mapper/PaymentRequestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getAmount()
}

/**
* @return strign
* @return string
*/
public function getMethod()
{
Expand Down

0 comments on commit 11c48da

Please sign in to comment.