class OrderTotalSummary in Commerce Core 8.2
Same name in this branch
- 8.2 modules/order/src/OrderTotalSummary.php \Drupal\commerce_order\OrderTotalSummary
- 8.2 modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php \Drupal\commerce_order\Plugin\Field\FieldFormatter\OrderTotalSummary
Hierarchy
- class \Drupal\commerce_order\OrderTotalSummary implements OrderTotalSummaryInterface
Expanded class hierarchy of OrderTotalSummary
1 string reference to 'OrderTotalSummary'
- commerce_order.services.yml in modules/
order/ commerce_order.services.yml - modules/order/commerce_order.services.yml
1 service uses OrderTotalSummary
File
- modules/
order/ src/ OrderTotalSummary.php, line 7
Namespace
Drupal\commerce_orderView source
class OrderTotalSummary implements OrderTotalSummaryInterface {
/**
* The adjustment transformer.
*
* @var \Drupal\commerce_order\AdjustmentTransformerInterface
*/
protected $adjustmentTransformer;
/**
* Constructs a new OrderTotalSummary object.
*
* @param \Drupal\commerce_order\AdjustmentTransformerInterface $adjustment_transformer
* The adjustment transformer.
*/
public function __construct(AdjustmentTransformerInterface $adjustment_transformer) {
$this->adjustmentTransformer = $adjustment_transformer;
}
/**
* {@inheritdoc}
*/
public function buildTotals(OrderInterface $order) {
$adjustments = $order
->collectAdjustments();
$adjustments = $this->adjustmentTransformer
->processAdjustments($adjustments);
// Included adjustments are not displayed to the customer, they
// exist to allow the developer to know what the price is made of.
// The one exception is taxes, which need to be shown for legal reasons.
$adjustments = array_filter($adjustments, function (Adjustment $adjustment) {
return $adjustment
->getType() == 'tax' || !$adjustment
->isIncluded();
});
// Convert the adjustments to arrays.
$adjustments = array_map(function (Adjustment $adjustment) {
return $adjustment
->toArray();
}, $adjustments);
// Provide the "total" key for backwards compatibility reasons.
foreach ($adjustments as $index => $adjustment) {
$adjustments[$index]['total'] = $adjustments[$index]['amount'];
}
return [
'subtotal' => $order
->getSubtotalPrice(),
'adjustments' => $adjustments,
'total' => $order
->getTotalPrice(),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OrderTotalSummary:: |
protected | property | The adjustment transformer. | |
OrderTotalSummary:: |
public | function |
Builds the totals for the given order. Overrides OrderTotalSummaryInterface:: |
|
OrderTotalSummary:: |
public | function | Constructs a new OrderTotalSummary object. |