public function InvoiceItem::getAdjustedUnitPrice in Commerce Invoice 8.2
Gets the adjusted invoice item unit price.
Calculated by dividing the adjusted total price by quantity.
Useful for refunds and other purposes where there's a need to know how much a single unit contributed to the order total.
Parameters
string[] $adjustment_types: The adjustment types to include in the adjusted price. Examples: fee, promotion, tax. Defaults to all adjustment types.
Return value
\Drupal\commerce_price\Price|null The adjusted invoice item unit price, or NULL.
Overrides InvoiceItemInterface::getAdjustedUnitPrice
File
- src/
Entity/ InvoiceItem.php, line 217
Class
- InvoiceItem
- Defines the invoice item entity class.
Namespace
Drupal\commerce_invoice\EntityCode
public function getAdjustedUnitPrice(array $adjustment_types = []) {
$unit_price = $this
->getUnitPrice();
if (!$unit_price) {
return NULL;
}
$adjusted_total_price = $this
->getAdjustedTotalPrice($adjustment_types);
$adjusted_unit_price = $adjusted_total_price
->divide($this
->getQuantity());
$rounder = \Drupal::service('commerce_price.rounder');
$adjusted_unit_price = $rounder
->round($adjusted_unit_price);
return $adjusted_unit_price;
}