diff --git a/modules/receipt/src/Controller/PrintController.php b/modules/receipt/src/Controller/PrintController.php
index c1000ad..2e08eda 100644
--- a/modules/receipt/src/Controller/PrintController.php
+++ b/modules/receipt/src/Controller/PrintController.php
@@ -10,7 +10,9 @@ use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\HtmlCommand;
use Drupal\Core\Ajax\SettingsCommand;
use Drupal\Core\Controller\ControllerBase;
+use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Url;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class PrintController.
@@ -18,6 +20,32 @@ use Drupal\Core\Url;
class PrintController extends ControllerBase {
/**
+ * The date formatter.
+ *
+ * @var \Drupal\Core\Datetime\DateFormatterInterface
+ */
+ protected $dateFormatter;
+
+ /**
+ * Creates a new PrintController object.
+ *
+ * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
+ * The date formatter.
+ */
+ public function __construct(DateFormatterInterface $date_formatter) {
+ $this->dateFormatter = $date_formatter;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('date.formatter')
+ );
+ }
+
+ /**
* A controller callback.
*/
public function ajaxReceipt(OrderInterface $commerce_order, $print_or_email) {
@@ -62,44 +90,52 @@ class PrintController extends ControllerBase {
* A controller callback.
*/
public function showReceipt(OrderInterface $commerce_order) {
-
$number_formatter_factory = \Drupal::service('commerce_price.number_formatter_factory');
$number_formatter = $number_formatter_factory->createInstance();
+ $is_gift = $commerce_order->getData('gift_order');
+ $totals = [];
+ $gift_order = '';
$sub_total_price = $commerce_order->getSubtotalPrice();
$currency = Currency::load($sub_total_price->getCurrencyCode());
- $formatted_amount = $number_formatter->formatCurrency($sub_total_price->getNumber(), $currency);
// In the future add a setting to display group or individual for same skus.
$items = $commerce_order->getItems();
foreach ($items as $item) {
$totals[] = [
$item->getTitle() . ' (' . $item->getQuantity() . ')',
- $number_formatter->formatCurrency($item->getAdjustedTotalPrice()->getNumber(), $currency),
+ !$is_gift ? $number_formatter->formatCurrency($item->getAdjustedTotalPrice()->getNumber(), $currency) : '',
];
}
- $totals[] = ['Subtotal', $formatted_amount];
+ if (!$is_gift) {
+ $formatted_amount = $number_formatter->formatCurrency($sub_total_price->getNumber(), $currency);
+ $totals[] = ['Subtotal', $formatted_amount];
+ }
// Commerce appears to have a bug where if no adjustments exist, it will
// return a 0 => null array, which will still trigger a foreach loop.
- foreach ($commerce_order->collectAdjustments() as $key => $adjustment) {
- if (!empty($adjustment)) {
- $amount = $adjustment->getAmount();
- $currency = Currency::load($amount->getCurrencyCode());
- $formatted_amount = $number_formatter->formatCurrency($amount->getNumber(), $currency);
-
- $totals[] = [
- $adjustment->getLabel(),
- $formatted_amount,
- ];
+ if (!$is_gift) {
+ foreach ($commerce_order->collectAdjustments() as $key => $adjustment) {
+ if (!empty($adjustment)) {
+ $amount = $adjustment->getAmount();
+ $currency = Currency::load($amount->getCurrencyCode());
+ $formatted_amount = $number_formatter->formatCurrency($amount->getNumber(), $currency);
+
+ $totals[] = [
+ $adjustment->getLabel(),
+ $formatted_amount,
+ ];
+ }
}
}
// Collecting the total price on the cart.
- $total_price = $commerce_order->getTotalPrice();
- $formatted_amount = $number_formatter->formatCurrency($total_price->getNumber(), $currency);
- $totals[] = ['Total', $formatted_amount];
+ if (!$is_gift) {
+ $total_price = $commerce_order->getTotalPrice();
+ $formatted_amount = $number_formatter->formatCurrency($total_price->getNumber(), $currency);
+ $totals[] = ['Total', $formatted_amount];
+ }
$payment_storage = \Drupal::entityTypeManager()->getStorage('commerce_payment');
$payments = $payment_storage->loadMultipleByOrder($commerce_order);
@@ -111,19 +147,22 @@ class PrintController extends ControllerBase {
'class' => ['use-ajax', 'button'],
],
]);
-
+ $order_date = $this->dateFormatter->format($commerce_order->getCompletedTime());
$config = \Drupal::config('commerce_pos_receipt.settings');
+ if ($is_gift) {
+ $gift_order = '' . $this->t('GIFT ORDER') . '';
+ }
$build = ['#theme' => 'commerce_pos_receipt'];
$build['#receipt'] = [
'header' => [
- '#markup' => check_markup($config->get('header'), $config->get('header_format')),
+ '#markup' => check_markup($config->get('header'), $config->get('header_format')) . "
$order_date
Order# {$commerce_order->id()}
$gift_order