You are here

class Proportional in Commerce Recurring Framework 8

Provides a proportional prorater.

Plugin annotation


@CommerceProrater(
  id = "proportional",
  label = @Translation("Proportional"),
)

Hierarchy

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\Prorater
View 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

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
Proportional::$rounder protected property The price rounder service.
Proportional::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
Proportional::prorateOrderItem public function Prorates the given order item. Overrides ProraterBase::prorateOrderItem
Proportional::__construct public function Constructs a new Proportional object. Overrides ProraterBase::__construct
ProraterBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
ProraterBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
ProraterBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration
ProraterBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ProraterBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ProraterBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
ProraterBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm