Skip to content
Snippets Groups Projects

Issue #3462714 by jsacksick, rszrama: Show the same customer information on...

Merged Jonathan Sacksick requested to merge issue/commerce-3462714:3462714-show-the-same into 8.x-2.x
1 file
+ 15
20
Compare changes
  • Side-by-side
  • Inline
@@ -24,33 +24,20 @@ class OrderForm extends ContentEntityForm {
protected $dateFormatter;
/**
* Constructs a new OrderForm object.
* The currency formatter.
*
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter.
* @var \CommerceGuys\Intl\Formatter\CurrencyFormatterInterface
*/
public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, DateFormatterInterface $date_formatter) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->dateFormatter = $date_formatter;
}
protected $currencyFormatter;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.repository'),
$container->get('entity_type.bundle.info'),
$container->get('datetime.time'),
$container->get('date.formatter')
);
$instance = parent::create($container);
$instance->dateFormatter = $container->get('date.formatter');
$instance->currencyFormatter = $container->get('commerce_price.currency_formatter');
return $instance;
}
/**
@@ -105,6 +92,7 @@ class OrderForm extends ContentEntityForm {
// Hide the rendered state if there's a widget for it.
'#access' => empty($form['store_id']),
],
'completed' => NULL,
'date' => NULL,
'changed' => $this->fieldAsReadOnly($this->t('Changed'), $last_saved),
];
@@ -118,6 +106,10 @@ class OrderForm extends ContentEntityForm {
],
'#weight' => 91,
];
if ($completed_time = $order->getCompletedTime()) {
$date = $this->dateFormatter->format($completed_time, 'short');
$form['meta']['completed'] = $this->fieldAsReadOnly($this->t('Completed'), $date);
}
if ($placed_time = $order->getPlacedTime()) {
$date = $this->dateFormatter->format($placed_time, 'short');
@@ -130,6 +122,9 @@ class OrderForm extends ContentEntityForm {
$store_link = $order->getStore()->toLink()->toString();
$form['meta']['store'] = $this->fieldAsReadOnly($this->t('Store'), $store_link);
}
if ($balance = $order->getBalance()) {
$form['meta']['balance'] = $this->fieldAsReadOnly($this->t('Order balance'), $this->currencyFormatter->format($balance->getNumber(), $balance->getCurrencyCode()));
}
// Move uid/mail widgets to the sidebar, or provide read-only alternatives.
$customer = $order->getCustomer();
if (isset($form['uid'])) {
Loading