Skip to content

Commit

Permalink
Merge pull request #344 from OXID-eSales/SeperateShippingCost
Browse files Browse the repository at this point in the history
move shippingcosts from items to breakdown
  • Loading branch information
mariolorenz authored Sep 19, 2024
2 parents 1539ca0 + 7171f26 commit 555df44
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 52 deletions.
32 changes: 5 additions & 27 deletions src/Core/OrderRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use OxidEsales\Eshop\Application\Model\State;
use OxidEsales\Eshop\Core\Registry;
use OxidSolutionCatalysts\PayPal\Service\ModuleSettings;
use OxidSolutionCatalysts\PayPal\Core\PayPalRequestAmountFactory;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\AddressPortable;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\AddressPortable3;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\AmountWithBreakdown;
Expand Down Expand Up @@ -76,7 +75,6 @@ class OrderRequestFactory
* @param null|string $invoiceId custom invoice number
* @param null|string $returnUrl Return Url
* @param null|string $cancelUrl Cancel Url
* @param bool $articlesWithTax Articles in Request with Tax information?
* @param bool $setProvidedAddress Address changeable in PayPal?
*
* @return OrderRequest
Expand Down Expand Up @@ -204,8 +202,6 @@ protected function getGooglePayPaymentSource($basket, $requestName)
{
$user = $basket->getBasketUser();

$userName = $user->getFieldData('oxfname') . ' ' . $user->getFieldData('oxlname');

// get Billing CountryCode
$country = oxNew(Country::class);
$country->load($user->getFieldData('oxcountryid'));
Expand All @@ -225,11 +221,14 @@ protected function getGooglePayPaymentSource($basket, $requestName)
$paymentSource->$requestName->attributes->verification->method = 'SCA_ALWAYS';
return $paymentSource;
}

/**
* Sets application context
*
* @param string $userAction
*
* @param string|null $userAction
* @param string|null $returnUrl
* @param string|null $cancelUrl
* @param bool|null $setProvidedAddress
* @return OrderApplicationContext
*/
protected function getApplicationContext(
Expand Down Expand Up @@ -309,8 +308,6 @@ public function getItems(): array
$itemCategory = $this->getItemCategoryByBasketContent();
$currency = $basket->getBasketCurrency();
$language = Registry::getLang();
$config = Registry::getConfig();
$netMode = $basket->isCalculationModeNetto();
$items = [];

/** @var BasketItem $basketItem */
Expand Down Expand Up @@ -394,25 +391,6 @@ public function getItems(): array
$items[] = $item;
}

//Shipping cost
$delivery = $basket->getPayPalCheckoutDeliveryCosts();
if ($delivery) {
$item = new Item();
$item->name = $language->translateString('SHIPPING_COST');

$item->unit_amount = PriceToMoney::convert(
$delivery,
$currency
);
// tax - we use 0% and calculate with brutto to avoid rounding errors
$item->tax = PriceToMoney::convert(0.0, $currency);
$item->tax_rate = '0';
$item->category = $itemCategory;

$item->quantity = '1';
$items[] = $item;
}

// possible price surcharge
$discount = $basket->getPayPalCheckoutDiscount();

Expand Down
15 changes: 0 additions & 15 deletions src/Core/PatchRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,6 @@ protected function getPurchaseUnitsPatch(
$patchValues[] = $item;
}

//Shipping cost
$delivery = $basket->getPayPalCheckoutDeliveryCosts();
if ($delivery) {
$item = new Item();
$item->name = $language->translateString('SHIPPING_COST');

$item->unit_amount = PriceToMoney::convert(
$delivery,
$currency
);

$item->quantity = '1';
$patchValues[] = $item;
}

// possible price surcharge
$discount = $basket->getPayPalCheckoutDiscount();

Expand Down
17 changes: 14 additions & 3 deletions src/Core/PayPalRequestAmountFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace OxidSolutionCatalysts\PayPal\Core;

use OxidEsales\Eshop\Application\Model\Basket;
use OxidEsales\Eshop\Core\Registry;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\AmountBreakdown;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\AmountWithBreakdown;
use OxidSolutionCatalysts\PayPal\Core\Utils\PriceToMoney;
Expand All @@ -35,6 +34,7 @@ public function getAmount(Basket $basket): AmountWithBreakdown

$brutBasketTotal = $basket->getPrice()->getBruttoPrice();
$brutDiscountValue = $itemTotal + $itemTotalAdditionalCosts - $brutBasketTotal;
$shipping = $basket->getPayPalCheckoutDeliveryCosts();

// possible price surcharge
if ($netMode && $brutDiscountValue < 0) {
Expand All @@ -47,16 +47,18 @@ public function getAmount(Basket $basket): AmountWithBreakdown
}

if ($netMode) {
$total = $brutBasketTotal;
$total = $brutBasketTotal - $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->value;
$amount->value = $total_with_shipping->value;
$amount->currency_code = $total->currency_code;

//Cost breakdown
Expand All @@ -70,6 +72,15 @@ public function getAmount(Basket $basket): AmountWithBreakdown
//Item tax sum - we use 0% and calculate with brutto to avoid rounding errors
$breakdown->tax_total = PriceToMoney::convert(0, $currency);

//Shipping cost
$delivery = $basket->getPayPalCheckoutDeliveryCosts();
if ($delivery) {
$breakdown->shipping = PriceToMoney::convert(
$delivery,
$currency
);
}

return $amount;
}
}
7 changes: 0 additions & 7 deletions src/Model/Basket.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,14 @@ public function addShippingPriceForExpress(float $defaultShippingPriceExpress):
* - Wrapping-Costs
* - Gift-Cards
* - Payment-Costs
* - Delivery-Costs
*/
public function getAdditionalPayPalCheckoutItemCosts(): float
{
$result = 0;
$result += $this->getPayPalCheckoutWrapping();
$result += $this->getPayPalCheckoutGiftCard();
$result += $this->getPayPalCheckoutPayment();
$result += $this->getPayPalCheckoutDeliveryCosts();

return $result;
}

private function getFloatFromPrice(Price $price): float
{
return $this->isCalculationModeNetto() ? $price->getNettoPrice(): $price->getBruttoPrice();
}
}

0 comments on commit 555df44

Please sign in to comment.