class PriceCalculatorPass in Commerce Core 8.2
Adds order processors to the PriceCalculator, grouped by adjustment type.
Hierarchy
- class \Drupal\commerce_order\DependencyInjection\Compiler\PriceCalculatorPass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface
Expanded class hierarchy of PriceCalculatorPass
1 file declares its use of PriceCalculatorPass
- CommerceOrderServiceProvider.php in modules/
order/ src/ CommerceOrderServiceProvider.php
File
- modules/
order/ src/ DependencyInjection/ Compiler/ PriceCalculatorPass.php, line 14
Namespace
Drupal\commerce_order\DependencyInjection\CompilerView source
class PriceCalculatorPass implements CompilerPassInterface {
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container) {
$definition = $container
->getDefinition('commerce_order.price_calculator');
$processor_interface = OrderProcessorInterface::class;
$processors = [];
foreach ($container
->findTaggedServiceIds('commerce_order.order_processor') as $id => $attributes) {
$processor = $container
->getDefinition($id);
if (!is_subclass_of($processor
->getClass(), $processor_interface)) {
throw new LogicException("Service '{$id}' does not implement {$processor_interface}.");
}
$attribute = $attributes[0];
if (empty($attribute['adjustment_type'])) {
continue;
}
$processors[$id] = [
'priority' => isset($attribute['priority']) ? $attribute['priority'] : 0,
'adjustment_type' => $attribute['adjustment_type'],
];
}
// Sort the processors by priority.
uasort($processors, function ($processor1, $processor2) {
if ($processor1['priority'] == $processor2['priority']) {
return 0;
}
return $processor1['priority'] > $processor2['priority'] ? -1 : 1;
});
// Add the processors to PriceCalculator.
foreach ($processors as $id => $processor) {
$arguments = [
new Reference($id),
$processor['adjustment_type'],
];
$definition
->addMethodCall('addProcessor', $arguments);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PriceCalculatorPass:: |
public | function | You can modify the container here before it is dumped to PHP code. |