private function InvoiceGenerator::getAdjustmentsFromEntity in Commerce Invoice 8.2
Return an array of adjustments from a given adjustable entity.
Parameters
\Drupal\commerce_order\EntityAdjustableInterface $entity: An adjustable entity object.
\Drupal\commerce_order\EntityAdjustableInterface[] $existing_items: (optional) An array of existing items that might contain adjustments which need to be subtracted from adjustable entity above. Defaults to an empty array.
Return value
\Drupal\commerce_order\Adjustment[] An array of adjustments.
2 calls to InvoiceGenerator::getAdjustmentsFromEntity()
- InvoiceGenerator::doGenerate in src/
InvoiceGenerator.php - InvoiceGenerator::getInvoiceItemsFromOrder in src/
InvoiceGenerator.php - Return an array of invoice items from a given order.
File
- src/
InvoiceGenerator.php, line 165
Class
Namespace
Drupal\commerce_invoiceCode
private function getAdjustmentsFromEntity(EntityAdjustableInterface $entity, array $existing_items = []) {
$adjustments = [];
foreach ($entity
->getAdjustments() as $adjustment) {
// Look through all the existing invoices for this order and subtract the
// amount of their adjustments.
foreach ($existing_items as $existing_item) {
foreach ($existing_item
->getAdjustments() as $previous_adjustment) {
if ($adjustment
->getType() === $previous_adjustment
->getType() && $adjustment
->getSourceId() === $previous_adjustment
->getSourceId()) {
$adjustment = $adjustment
->subtract($previous_adjustment);
}
}
}
if (!$adjustment
->getAmount()
->isZero()) {
$adjustments[] = $adjustment;
}
}
return $adjustments;
}