public function Proportional::prorateOrderItem in Commerce Recurring Framework 8
Prorates the given order item.
When needed, the plugin can use separate logic for recurring and initial order items by looking at the order item type:
if (in_array($order_item
->bundle(), commerce_recurring_order_item_types())) {
// This is a recurring order item.
}
else {
// This is an initial order item.
}
Parameters
\Drupal\commerce_order\Entity\OrderItemInterface $order_item: The order item.
\Drupal\commerce_recurring\BillingPeriod $billing_period: The partial billing period.
\Drupal\commerce_recurring\BillingPeriod $full_billing_period: The full billing period.
Return value
\Drupal\commerce_price\Price The prorated price.
Overrides ProraterBase::prorateOrderItem
File
- src/
Plugin/ Commerce/ Prorater/ Proportional.php, line 62
Class
- Proportional
- Provides a proportional prorater.
Namespace
Drupal\commerce_recurring\Plugin\Commerce\ProraterCode
public function prorateOrderItem(OrderItemInterface $order_item, BillingPeriod $billing_period, BillingPeriod $full_billing_period) {
$duration = $billing_period
->getDuration();
$full_duration = $full_billing_period
->getDuration();
$price = $order_item
->getUnitPrice();
$price = $price
->multiply(Calculator::divide($duration, $full_duration));
$price = $this->rounder
->round($price);
return $price;
}