diff --git a/modules/order/commerce_order.post_update.php b/modules/order/commerce_order.post_update.php
index 26dd36ceba..48a99222b8 100644
--- a/modules/order/commerce_order.post_update.php
+++ b/modules/order/commerce_order.post_update.php
@@ -170,3 +170,34 @@ function commerce_order_post_update_6() {
}
}
}
+
+/**
+ * Revert the 'commerce_order_item_table' view - empty text added.
+ */
+function commerce_order_post_update_7() {
+ /** @var \Drupal\commerce\Config\ConfigUpdaterInterface $config_updater */
+ $config_updater = \Drupal::service('commerce.config_updater');
+
+ $views = [
+ 'views.view.commerce_order_item_table',
+ ];
+ $result = $config_updater->revert($views, FALSE);
+
+ $success_results = $result->getSucceeded();
+ $failure_results = $result->getFailed();
+ if ($success_results) {
+ $message = t('Succeeded:') . '
';
+ foreach ($success_results as $success_message) {
+ $message .= $success_message . '
';
+ }
+ $message .= '
';
+ }
+ if ($failure_results) {
+ $message .= t('Failed:') . '
';
+ foreach ($failure_results as $failure_message) {
+ $message .= $failure_message . '
';
+ }
+ }
+
+ return $message;
+}
diff --git a/modules/order/config/install/views.view.commerce_order_item_table.yml b/modules/order/config/install/views.view.commerce_order_item_table.yml
index 93955666f8..ed8436d493 100644
--- a/modules/order/config/install/views.view.commerce_order_item_table.yml
+++ b/modules/order/config/install/views.view.commerce_order_item_table.yml
@@ -347,7 +347,16 @@ display:
sorts: { }
header: { }
footer: { }
- empty: { }
+ empty:
+ area:
+ id: area
+ table: views
+ field: area
+ empty: true
+ content:
+ value: 'No items added to this order.'
+ format: plain_text
+ plugin_id: text
relationships: { }
arguments:
order_id:
diff --git a/modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php b/modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php
index bb88c6d977..7c04bd563f 100644
--- a/modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php
+++ b/modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php
@@ -71,10 +71,22 @@ public static function create(ContainerInterface $container, array $configuratio
);
}
+ /**
+ * {@inheritdoc}
+ */
+ public function view(FieldItemListInterface $items, $langcode = NULL) {
+ // Check first if the total price is not empty.
+ if ($items->isEmpty()) {
+ return [];
+ }
+ return parent::view($items, $langcode);
+ }
+
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
+ /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $items->getEntity();
return [
'#theme' => 'commerce_order_total_summary',
diff --git a/modules/order/tests/src/Functional/OrderAdminTest.php b/modules/order/tests/src/Functional/OrderAdminTest.php
index 2565693a1d..9164e8cd22 100644
--- a/modules/order/tests/src/Functional/OrderAdminTest.php
+++ b/modules/order/tests/src/Functional/OrderAdminTest.php
@@ -193,18 +193,12 @@ public function testUnlockOrder() {
* Tests that an admin can view an order's details.
*/
public function testAdminOrderView() {
- $order_item = $this->createEntity('commerce_order_item', [
- 'type' => 'default',
- 'unit_price' => [
- 'number' => '999',
- 'currency_code' => 'USD',
- ],
- ]);
+ // First test for order without items.
+ /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $this->createEntity('commerce_order', [
'type' => 'default',
'store_id' => $this->store->id(),
'mail' => $this->loggedInUser->getEmail(),
- 'order_items' => [$order_item],
'state' => 'draft',
'uid' => $this->loggedInUser,
]);
@@ -214,6 +208,10 @@ public function testAdminOrderView() {
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains($this->loggedInUser->getEmail());
+ // Test there are no items.
+ $this->assertSession()->pageTextContains('No items added to this order.');
+ $this->assertSession()->pageTextNotContains('Total');
+
// Confirm that the transition buttons are visible and functional.
$workflow = $order->getState()->getWorkflow();
$transitions = $workflow->getAllowedTransitions($order->getState()->value, $order);
@@ -224,6 +222,22 @@ public function testAdminOrderView() {
$this->assertSession()->buttonNotExists('Place order');
$this->assertSession()->buttonNotExists('Cancel order');
+ // Test with order items.
+ $order_item = $this->createEntity('commerce_order_item', [
+ 'type' => 'default',
+ 'unit_price' => [
+ 'number' => '999',
+ 'currency_code' => 'USD',
+ ],
+ ]);
+ $order->setItems([$order_item]);
+ $order->save();
+ $this->drupalGet($order->toUrl()->toString());
+ $this->assertSession()->statusCodeEquals(200);
+ $this->assertSession()->pageTextNotContains('No items added to this order.');
+ $this->assertSession()->pageTextContains('$999.00');
+ $this->assertSession()->pageTextContains('Total price');
+
// Logout and check that anonymous users cannot see the order admin screen
// and receive a 403 error code.
$this->drupalLogout();