Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2857378 by bojanz, vasike, mglaman: Hide order activity when empty #666

Open
wants to merge 16 commits into
base: 8.x-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion modules/log/commerce_log.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,41 @@ function commerce_log_post_update_2() {

$success_results = $result->getSucceeded();
$failure_results = $result->getFailed();
$message = '';
if ($success_results) {
$message = t('Succeeded:') . '<br>';
$message .= t('Succeeded:') . '<br>';
foreach ($success_results as $success_message) {
$message .= $success_message . '<br>';
}
$message .= '<br>';
}
if ($failure_results) {
$message .= t('Failed:') . '<br>';
foreach ($failure_results as $failure_message) {
$message .= $failure_message . '<br>';
}
}

return $message;
}

/**
* Revert the Activity view to empty 'No results behavior'.
*/
function commerce_log_post_update_3() {
/** @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:') . '<br>';
foreach ($success_results as $success_message) {
$message .= $success_message . '<br>';
}
Expand Down
13 changes: 1 addition & 12 deletions modules/log/config/install/views.view.commerce_activity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,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:
Expand Down
70 changes: 70 additions & 0 deletions modules/log/tests/src/Functional/OrderAdminActivityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Drupal\Tests\commerce_log\Functional;

use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;

/**
* Tests the order activity on order admin view.
*
* @group commerce
*/
class OrderAdminActivityTest extends CommerceBrowserTestBase {

/**
* The order to test against.
*
* @var \Drupal\commerce_order\Entity\OrderInterface
*/
protected $order;

/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'commerce_order',
'commerce_log',
];

/**
* {@inheritdoc}
*/
protected function getAdministratorPermissions() {
return array_merge([
'administer commerce_order',
], parent::getAdministratorPermissions());
}

/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();

/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$this->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['cancel']);
$this->order->save();
$this->drupalGet($this->order->toUrl());
$this->assertSession()->pageTextContains(t('Order activity'));
$this->assertSession()->pageTextContains(t('The order was canceled.'));
}

}
2 changes: 1 addition & 1 deletion modules/order/commerce_order.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function commerce_order_post_update_7() {
$views = [
'views.view.commerce_order_item_table',
];
$result = $config_updater->revert($views);
$result = $config_updater->revert($views, FALSE);

$success_results = $result->getSucceeded();
$failure_results = $result->getFailed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ 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}
*/
Expand Down
2 changes: 1 addition & 1 deletion modules/order/templates/commerce-order--admin.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{{ order.order_items }}
{{ order.total_price }}

{% if order.activity %}
{% if order.activity|render|striptags|trim is not empty %}
<h2>{% trans %}Order activity{% endtrans %}</h2>
{{ order.activity }}
{% endif %}
Expand Down
1 change: 0 additions & 1 deletion modules/order/tests/src/Functional/OrderAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ public function testAdminOrderView() {
]);
$order->setItems([$order_item]);
$order->save();

$this->drupalGet($order->toUrl()->toString());
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextNotContains('There are no order items yet.');
Expand Down