class OrderRenderer in Commerce Core 8.2
Provides a custom entity_print renderer for orders.
Uses the commerce_order_receipt template for the document contents.
Hierarchy
- class \Drupal\commerce_order\EntityPrint\OrderRenderer extends \Drupal\entity_print\Renderer\ContentEntityRenderer uses StringTranslationTrait
Expanded class hierarchy of OrderRenderer
1 file declares its use of OrderRenderer
- EntityPrintOrderRendererTest.php in modules/
order/ tests/ src/ Kernel/ EntityPrintOrderRendererTest.php
File
- modules/
order/ src/ EntityPrint/ OrderRenderer.php, line 22
Namespace
Drupal\commerce_order\EntityPrintView source
class OrderRenderer extends ContentEntityRenderer {
use StringTranslationTrait;
/**
* The order total summary.
*
* @var \Drupal\commerce_order\OrderTotalSummaryInterface
*/
protected $orderTotalSummary;
/**
* Constructs a new OrderEntityRenderer object.
*
* @param \Drupal\Core\Render\RendererInterface $renderer
* The core render service.
* @param \Drupal\entity_print\Asset\AssetRendererInterface $asset_renderer
* The entity print asset renderer.
* @param \Drupal\entity_print\FilenameGeneratorInterface $filename_generator
* A filename generator.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\commerce_order\OrderTotalSummaryInterface $order_total_summary
* The order total summary service.
*/
public function __construct(CoreRendererInterface $renderer, AssetRendererInterface $asset_renderer, FilenameGeneratorInterface $filename_generator, EventDispatcherInterface $event_dispatcher, EntityTypeManagerInterface $entity_type_manager, OrderTotalSummaryInterface $order_total_summary) {
parent::__construct($renderer, $asset_renderer, $filename_generator, $event_dispatcher, $entity_type_manager);
$this->orderTotalSummary = $order_total_summary;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($container
->get('renderer'), $container
->get('entity_print.asset_renderer'), $container
->get('entity_print.filename_generator'), $container
->get('event_dispatcher'), $container
->get('entity_type.manager'), $container
->get('commerce_order.order_total_summary'));
}
/**
* {@inheritdoc}
*/
public function render(array $orders) {
$profile_view_builder = $this->entityTypeManager
->getViewBuilder('profile');
$build = [];
foreach ($orders as $order) {
assert($order instanceof OrderInterface);
$order_build = [
'#theme' => 'commerce_order_receipt__entity_print',
'#order_entity' => $order,
'#totals' => $this->orderTotalSummary
->buildTotals($order),
];
if ($billing_profile = $order
->getBillingProfile()) {
$order_build['#billing_information'] = $profile_view_builder
->view($billing_profile);
}
$build[] = $order_build;
}
return $build;
}
/**
* {@inheritdoc}
*/
public function getFilename(array $entities) {
$entities_label = $this->filenameGenerator
->generateFilename($entities, static function (OrderInterface $order) {
return $order
->id();
});
return $this
->t('Order @id @receipt', [
'@id' => $entities_label,
'@receipt' => $this
->formatPlural(count($entities), 'receipt', 'receipts'),
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OrderRenderer:: |
protected | property | The order total summary. | |
OrderRenderer:: |
public static | function | ||
OrderRenderer:: |
public | function | ||
OrderRenderer:: |
public | function | ||
OrderRenderer:: |
public | function | Constructs a new OrderEntityRenderer object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |