protected function CheckoutSdk::getAdjustmentsTotal in Commerce PayPal 8
Get the total for the given adjustments.
Parameters
\Drupal\commerce_order\Adjustment[] $adjustments: The adjustments.
string[] $adjustment_types: The adjustment types to include in the calculation. Examples: fee, promotion, tax. Defaults to all adjustment types.
Return value
\Drupal\commerce_price\Price|null The adjustments total, or NULL if no matching adjustments were found.
1 call to CheckoutSdk::getAdjustmentsTotal()
- CheckoutSdk::prepareOrderRequest in src/
CheckoutSdk.php - Prepare the order request parameters.
File
- src/
CheckoutSdk.php, line 398
Class
- CheckoutSdk
- Provides a replacement of the PayPal SDK.
Namespace
Drupal\commerce_paypalCode
protected function getAdjustmentsTotal(array $adjustments, array $adjustment_types = []) {
$adjustments_total = NULL;
$matching_adjustments = [];
foreach ($adjustments as $adjustment) {
if ($adjustment_types && !in_array($adjustment
->getType(), $adjustment_types)) {
continue;
}
if ($adjustment
->isIncluded()) {
continue;
}
$matching_adjustments[] = $adjustment;
}
if ($matching_adjustments) {
$matching_adjustments = $this->adjustmentTransformer
->processAdjustments($matching_adjustments);
foreach ($matching_adjustments as $adjustment) {
$adjustments_total = $adjustments_total ? $adjustments_total
->add($adjustment
->getAmount()) : $adjustment
->getAmount();
}
}
return $adjustments_total;
}