OrderTotalSummary.php in Commerce Core 8.2
File
modules/order/src/OrderTotalSummary.php
View source
<?php
namespace Drupal\commerce_order;
use Drupal\commerce_order\Entity\OrderInterface;
class OrderTotalSummary implements OrderTotalSummaryInterface {
protected $adjustmentTransformer;
public function __construct(AdjustmentTransformerInterface $adjustment_transformer) {
$this->adjustmentTransformer = $adjustment_transformer;
}
public function buildTotals(OrderInterface $order) {
$adjustments = $order
->collectAdjustments();
$adjustments = $this->adjustmentTransformer
->processAdjustments($adjustments);
$adjustments = array_filter($adjustments, function (Adjustment $adjustment) {
return $adjustment
->getType() == 'tax' || !$adjustment
->isIncluded();
});
$adjustments = array_map(function (Adjustment $adjustment) {
return $adjustment
->toArray();
}, $adjustments);
foreach ($adjustments as $index => $adjustment) {
$adjustments[$index]['total'] = $adjustments[$index]['amount'];
}
return [
'subtotal' => $order
->getSubtotalPrice(),
'adjustments' => $adjustments,
'total' => $order
->getTotalPrice(),
];
}
}