From bc6304575ccb7fb7c9846fe2315b728492d0aa4a Mon Sep 17 00:00:00 2001 From: tavi toporjinschi Date: Mon, 6 Mar 2017 11:30:59 +0000 Subject: [PATCH 1/5] Issue #2857378 by bojanz, vasike, mglaman: Hide order activity when empty --- modules/log/commerce_log.post_update.php | 32 +++++++++ .../install/views.view.commerce_activity.yml | 13 +--- .../src/Functional/OrderAdminActivityTest.php | 69 +++++++++++++++++++ .../templates/commerce-order--admin.html.twig | 2 +- 4 files changed, 103 insertions(+), 13 deletions(-) create mode 100644 modules/log/tests/src/Functional/OrderAdminActivityTest.php diff --git a/modules/log/commerce_log.post_update.php b/modules/log/commerce_log.post_update.php index 0566427248..da5d0c90fd 100644 --- a/modules/log/commerce_log.post_update.php +++ b/modules/log/commerce_log.post_update.php @@ -35,3 +35,35 @@ function commerce_log_post_update_1() { return $message; } + +/** + * Revert the Activity view to empty 'No results behavior'. + */ +function commerce_log_post_update_2() { + /** @var \Drupal\commerce\Config\ConfigUpdaterInterface $config_updater */ + $config_updater = \Drupal::service('commerce.config_updater'); + + $views = [ + 'views.view.commerce_activity', + ]; + $result = $config_updater->revert($views, FALSE); + + $success_results = $result->getSucceeded(); + $failure_results = $result->getFailed(); + $message = ''; + 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/log/config/install/views.view.commerce_activity.yml b/modules/log/config/install/views.view.commerce_activity.yml index 5753ebb3c9..98b4aa26f4 100644 --- a/modules/log/config/install/views.view.commerce_activity.yml +++ b/modules/log/config/install/views.view.commerce_activity.yml @@ -307,18 +307,7 @@ display: title: 'Order logs' header: { } footer: { } - empty: - area_text_custom: - id: area_text_custom - table: views - field: area_text_custom - relationship: none - group_type: group - admin_label: '' - empty: true - tokenize: false - content: 'No log entries.' - plugin_id: text_custom + empty: { } relationships: { } arguments: source_entity_id: diff --git a/modules/log/tests/src/Functional/OrderAdminActivityTest.php b/modules/log/tests/src/Functional/OrderAdminActivityTest.php new file mode 100644 index 0000000000..236749c19c --- /dev/null +++ b/modules/log/tests/src/Functional/OrderAdminActivityTest.php @@ -0,0 +1,69 @@ +order = $this->createEntity('commerce_order', [ + 'type' => 'default', + 'mail' => $this->loggedInUser->getEmail(), + 'uid' => $this->loggedInUser->id(), + 'store_id' => $this->store, + ]); + } + + /** + * Tests order activity on Order admin view. + */ + public function testOrderAdminActivity() { + $this->drupalGet($this->order->toUrl()); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextNotContains(t('Order activity')); + $transition = $this->order->getState()->getTransitions(); + $this->order->getState()->applyTransition($transition['place']); + $this->order->save(); + $this->drupalGet($this->order->toUrl()); + $this->assertSession()->pageTextContains(t('Order activity')); + $this->assertSession()->pageTextContains(t('The order was placed.')); + } +} diff --git a/modules/order/templates/commerce-order--admin.html.twig b/modules/order/templates/commerce-order--admin.html.twig index f1b1c4a623..66e796f788 100644 --- a/modules/order/templates/commerce-order--admin.html.twig +++ b/modules/order/templates/commerce-order--admin.html.twig @@ -26,7 +26,7 @@ {{ order.order_items }} {{ order.total_price }} - {% if order.activity %} + {% if order.activity|render|striptags|trim is not empty %}

{% trans %}Order activity{% endtrans %}

{{ order.activity }} {% endif %} From 19b91231ceee0b951318398cdfdc4292062a7f20 Mon Sep 17 00:00:00 2001 From: tavi toporjinschi Date: Fri, 10 Mar 2017 12:30:40 +0000 Subject: [PATCH 2/5] Fix for travis errors. --- modules/log/tests/src/Functional/OrderAdminActivityTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/log/tests/src/Functional/OrderAdminActivityTest.php b/modules/log/tests/src/Functional/OrderAdminActivityTest.php index 236749c19c..110fa31637 100644 --- a/modules/log/tests/src/Functional/OrderAdminActivityTest.php +++ b/modules/log/tests/src/Functional/OrderAdminActivityTest.php @@ -14,7 +14,7 @@ class OrderAdminActivityTest extends CommerceBrowserTestBase { /** * The order to test against. * - * @var \Drupal\commerce_order\Entity\OrderInterface $order + * @var \Drupal\commerce_order\Entity\OrderInterface */ protected $order; @@ -66,4 +66,5 @@ public function testOrderAdminActivity() { $this->assertSession()->pageTextContains(t('Order activity')); $this->assertSession()->pageTextContains(t('The order was placed.')); } + } From 58a7e742f4474268f9feca118608327e87ed19ff Mon Sep 17 00:00:00 2001 From: tavi toporjinschi Date: Thu, 6 Apr 2017 14:10:50 +0000 Subject: [PATCH 3/5] Issue #2867430 by vasike, bojanz: Order total summary formatter for empty total price --- modules/order/commerce_order.post_update.php | 31 +++++++++++++++++++ .../views.view.commerce_order_item_table.yml | 11 ++++++- .../FieldFormatter/OrderTotalSummary.php | 14 +++++++++ .../tests/src/Functional/OrderAdminTest.php | 30 +++++++++++++----- 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/modules/order/commerce_order.post_update.php b/modules/order/commerce_order.post_update.php index 335c6cf399..1d391f5f66 100644 --- a/modules/order/commerce_order.post_update.php +++ b/modules/order/commerce_order.post_update.php @@ -149,3 +149,34 @@ function commerce_order_post_update_5() { return $message; } + +/** + * Revert the 'commerce_order_item_table' view - empty text added. + */ +function commerce_order_post_update_6() { + /** @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; +} \ No newline at end of file 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..0f7b32922e 100644 --- a/modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php +++ b/modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php @@ -71,10 +71,24 @@ public static function create(ContainerInterface $container, array $configuratio ); } + /** + * {@inheritdoc} + * + * Loads the entities referenced in that field across all the entities being + * viewed. + */ + 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 2d837e67d1..627c31704d 100644 --- a/modules/order/tests/src/Functional/OrderAdminTest.php +++ b/modules/order/tests/src/Functional/OrderAdminTest.php @@ -162,18 +162,12 @@ public function testDeleteOrder() { * 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, ]); @@ -183,6 +177,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); @@ -193,6 +191,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(); From 7aa6a634db95848621435bc6ddffd0fdf45d0426 Mon Sep 17 00:00:00 2001 From: tavi toporjinschi Date: Thu, 6 Apr 2017 16:28:28 +0000 Subject: [PATCH 4/5] Code standards clean-up - travis errors. --- modules/order/commerce_order.post_update.php | 2 +- .../src/Plugin/Field/FieldFormatter/OrderTotalSummary.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/order/commerce_order.post_update.php b/modules/order/commerce_order.post_update.php index 1d391f5f66..03ebb94a4c 100644 --- a/modules/order/commerce_order.post_update.php +++ b/modules/order/commerce_order.post_update.php @@ -179,4 +179,4 @@ function commerce_order_post_update_6() { } return $message; -} \ No newline at end of file +} diff --git a/modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php b/modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php index 0f7b32922e..7c04bd563f 100644 --- a/modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php +++ b/modules/order/src/Plugin/Field/FieldFormatter/OrderTotalSummary.php @@ -73,9 +73,6 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} - * - * Loads the entities referenced in that field across all the entities being - * viewed. */ public function view(FieldItemListInterface $items, $langcode = NULL) { // Check first if the total price is not empty. @@ -84,6 +81,7 @@ public function view(FieldItemListInterface $items, $langcode = NULL) { } return parent::view($items, $langcode); } + /** * {@inheritdoc} */ From e5477b1988ca048ad66f5630e1ee68c0a2abcc8e Mon Sep 17 00:00:00 2001 From: tavi toporjinschi Date: Wed, 4 Oct 2017 13:43:38 +0000 Subject: [PATCH 5/5] Fix OrderAdminActivityTest.php errors. --- modules/log/tests/src/Functional/OrderAdminActivityTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/log/tests/src/Functional/OrderAdminActivityTest.php b/modules/log/tests/src/Functional/OrderAdminActivityTest.php index 110fa31637..b941d49450 100644 --- a/modules/log/tests/src/Functional/OrderAdminActivityTest.php +++ b/modules/log/tests/src/Functional/OrderAdminActivityTest.php @@ -60,11 +60,11 @@ public function testOrderAdminActivity() { $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextNotContains(t('Order activity')); $transition = $this->order->getState()->getTransitions(); - $this->order->getState()->applyTransition($transition['place']); + $this->order->getState()->applyTransition($transition['cancel']); $this->order->save(); $this->drupalGet($this->order->toUrl()); $this->assertSession()->pageTextContains(t('Order activity')); - $this->assertSession()->pageTextContains(t('The order was placed.')); + $this->assertSession()->pageTextContains(t('The order was canceled.')); } }