public function OrderItem::getAdjustedUnitPrice in Commerce Core 8.2
Gets the adjusted order 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 order item unit price, or NULL.
Overrides OrderItemInterface::getAdjustedUnitPrice
1 call to OrderItem::getAdjustedUnitPrice()
- OrderItem::getAdjustedTotalPrice in modules/
order/ src/ Entity/ OrderItem.php - Gets the adjusted order item total price.
File
- modules/
order/ src/ Entity/ OrderItem.php, line 236
Class
- OrderItem
- Defines the order item entity class.
Namespace
Drupal\commerce_order\EntityCode
public function getAdjustedUnitPrice(array $adjustment_types = []) {
$unit_price = $this
->getUnitPrice();
if (!$unit_price) {
return NULL;
}
if ($this
->usesLegacyAdjustments()) {
$adjusted_unit_price = $this
->applyAdjustments($unit_price, $adjustment_types);
}
else {
$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;
}