Skip to content

Commit

Permalink
Fixed discounts handling in amount breakdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Sosnowski committed Dec 2, 2024
1 parent 99d2cdd commit 831715f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 38 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [0007675](https://bugs.oxid-esales.com/view.php?id=7675): fix the possibility to finish order without redirect and login to Paypal
- [0007676](https://bugs.oxid-esales.com/view.php?id=7676): If we have a corrupted generated_services.yaml and try to deactivate the module via the admin, we will display a more understandable error message about what happened.
- introduce ActionHash to make the PayPal-Request-ID more unique
- [0007695](https://bugs.oxid-esales.com/view.php?id=7695): Fix: if DeliverySet is set in Frontend, then do not add any PseudoDeliveryCosts for PPExpress

### NEW
- PayPal-Request-Id based on serialized body, no extra PayPal-Request-Id necessary anymore
Expand Down
48 changes: 17 additions & 31 deletions src/Core/PatchRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,50 +67,36 @@ public function getRequest(

protected function getShippingAddressPatch(): void
{
$addressObj = false;
$address = new AddressPortable();
$session = Registry::getSession();
$deliveryId = Registry::getSession()->getVariable("deladrid");
$deliveryAddress = oxNew(Address::class);

$deliveryId = $session->getVariable("deladrid");
if ($deliveryId && $deliveryAddress->load($deliveryId)) {
$patch = new Patch();
$patch->op = Patch::OP_REPLACE;
$patch->path = "/purchase_units/@reference_id=='"
. Constants::PAYPAL_ORDER_REFERENCE_ID
. "'/shipping/address";

if ($deliveryId) {
$deliveryAddress = oxNew(Address::class);
if ($deliveryAddress->load($deliveryId)) {
$addressObj = $deliveryAddress;
}
}
else {
$user = $this->basket->getUser();
if ($user) {
$addressObj = $user;
}
}
$address = new AddressPortable();

if ($addressObj) {
$state = oxNew(State::class);
$country = oxNew(Country::class);
$state->load($deliveryAddress->getFieldData('oxstateid'));

$state->load($addressObj->getFieldData('oxstateid'));
$country->load($addressObj->getFieldData('oxcountryid'));
$country = oxNew(Country::class);
$country->load($deliveryAddress->getFieldData('oxcountryid'));

$addressLine =
$addressObj->getFieldData('oxstreet') . " " . $addressObj->getFieldData('oxstreetnr');
$deliveryAddress->getFieldData('oxstreet') . " " . $deliveryAddress->getFieldData('oxstreetnr');
$address->address_line_1 = $addressLine;

$addinfoLine = $addressObj->getFieldData('oxcompany') . " " .
$addressObj->getFieldData('oxaddinfo');
$addinfoLine = $deliveryAddress->getFieldData('oxcompany') . " " .
$deliveryAddress->getFieldData('oxaddinfo');
$address->address_line_2 = $addinfoLine;

$address->admin_area_1 = $state->getFieldData('oxtitle');
$address->admin_area_2 = $addressObj->getFieldData('oxcity');
$address->admin_area_2 = $deliveryAddress->getFieldData('oxcity');
$address->country_code = $country->oxcountry__oxisoalpha2->value;
$address->postal_code = $addressObj->getFieldData('oxzip');

$patch = new Patch();
$patch->op = Patch::OP_REPLACE;
$patch->path = "/purchase_units/@reference_id=='"
. Constants::PAYPAL_ORDER_REFERENCE_ID
. "'/shipping/address";
$address->postal_code = $deliveryAddress->getFieldData('oxzip');

$patch->value = $address;

Expand Down
9 changes: 4 additions & 5 deletions src/Core/PayPalRequestAmountFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,16 @@ public function getAmount(Basket $basket): AmountWithBreakdown
}

if ($netMode) {
$total = $brutBasketTotal - $shipping;
$total = $itemTotal - $shipping;
} else {
$total = $itemTotal - $discount + $itemTotalAdditionalCosts;
}
$total_with_shipping = $total + $shipping;

$total = PriceToMoney::convert($total, $currency);
$total_with_shipping = PriceToMoney::convert($total_with_shipping, $currency);

//Total amount
$amount = new AmountWithBreakdown();
$amount->value = $total_with_shipping->value;
$amount->value = $brutBasketTotal;
$amount->currency_code = $total->currency_code;

//Cost breakdown
Expand All @@ -68,7 +66,8 @@ public function getAmount(Basket $basket): AmountWithBreakdown
$breakdown->discount = PriceToMoney::convert($netMode ? $brutDiscountValue : $discount, $currency);
}

$breakdown->item_total = PriceToMoney::convert($total->value, $currency);
$breakDownItemTotal = $netMode ? $total->value : $itemTotal;
$breakdown->item_total = PriceToMoney::convert($breakDownItemTotal, $currency);
//Item tax sum - we use 0% and calculate with brutto to avoid rounding errors
$breakdown->tax_total = PriceToMoney::convert(0, $currency);

Expand Down
1 change: 0 additions & 1 deletion src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ public function setPayPalTracking(string $trackingCarrier, string $trackingCode)
'oxtrackcode' => $trackingCode
]
);
$this->save();
$payPalOrder = $this->getPayPalRepository();
$payPalOrder->setTrackingCode($trackingCode);
$payPalOrder->setTrackingCarrier($trackingCarrier);
Expand Down

0 comments on commit 831715f

Please sign in to comment.