class Proportional in Commerce Recurring Framework 8
Provides a proportional prorater.
Plugin annotation
@CommerceProrater(
id = "proportional",
label = @Translation("Proportional"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\commerce_recurring\Plugin\Commerce\Prorater\ProraterBase implements ProraterInterface
- class \Drupal\commerce_recurring\Plugin\Commerce\Prorater\Proportional implements ContainerFactoryPluginInterface
- class \Drupal\commerce_recurring\Plugin\Commerce\Prorater\ProraterBase implements ProraterInterface
Expanded class hierarchy of Proportional
1 file declares its use of Proportional
- BillingScheduleTest.php in tests/
src/ Kernel/ Entity/ BillingScheduleTest.php
File
- src/
Plugin/ Commerce/ Prorater/ Proportional.php, line 20
Namespace
Drupal\commerce_recurring\Plugin\Commerce\ProraterView source
class Proportional extends ProraterBase implements ContainerFactoryPluginInterface {
/**
* The price rounder service.
*
* @var \Drupal\commerce_price\RounderInterface
*/
protected $rounder;
/**
* Constructs a new Proportional object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\commerce_price\RounderInterface $rounder
* The rounder.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RounderInterface $rounder) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->rounder = $rounder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('commerce_price.rounder'));
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
Proportional:: |
protected | property | The price rounder service. | |
Proportional:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
Proportional:: |
public | function |
Prorates the given order item. Overrides ProraterBase:: |
|
Proportional:: |
public | function |
Constructs a new Proportional object. Overrides ProraterBase:: |
|
ProraterBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
ProraterBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ProraterBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
ProraterBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ProraterBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ProraterBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
ProraterBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |