diff --git a/modules/order/commerce_order.links.task.yml b/modules/order/commerce_order.links.task.yml index 8ea6291fac..5e20e15b4d 100644 --- a/modules/order/commerce_order.links.task.yml +++ b/modules/order/commerce_order.links.task.yml @@ -3,9 +3,14 @@ entity.commerce_order.collection: base_route: entity.commerce_order.collection title: 'Orders' +entity.commerce_order.canonical: + route_name: 'entity.commerce_order.canonical' + base_route: 'entity.commerce_order.canonical' + title: 'View' + entity.commerce_order.edit_form: route_name: 'entity.commerce_order.edit_form' - base_route: 'entity.commerce_order.edit_form' + base_route: 'entity.commerce_order.canonical' title: 'Edit' entity.commerce_order_type.edit_form: @@ -17,9 +22,3 @@ entity.commerce_order_item_type.edit_form: route_name: entity.commerce_order_item_type.edit_form base_route: entity.commerce_order_item_type.edit_form title: 'Edit' - -entity.commerce_order.canonical: - route_name: 'entity.commerce_order.canonical' - base_route: 'entity.commerce_order.edit_form' - title: 'View' - diff --git a/modules/order/commerce_order.module b/modules/order/commerce_order.module index e1b59ff203..dc2d2a7c67 100644 --- a/modules/order/commerce_order.module +++ b/modules/order/commerce_order.module @@ -19,6 +19,10 @@ function commerce_order_theme($existing, $type, $theme, $path) { 'commerce_order' => [ 'render element' => 'elements', ], + 'commerce_order__admin' => [ + 'base hook' => 'commerce_order', + 'render element' => 'elements', + ], 'commerce_order__user' => [ 'base hook' => 'commerce_order', 'render element' => 'elements', @@ -80,6 +84,11 @@ function template_preprocess_commerce_order(&$variables) { foreach (Element::children($variables['elements']) as $key) { $variables['order'][$key] = $variables['elements'][$key]; } + + if ($order->getBillingProfile()) { + $profile_view_bulder = \Drupal::entityTypeManager()->getViewBuilder('profile'); + $variables['order']['billing_information'] = $profile_view_bulder->view($order->getBillingProfile()); + } } /** diff --git a/modules/order/commerce_order.post_update.php b/modules/order/commerce_order.post_update.php index 907ba9b107..4560d85d56 100644 --- a/modules/order/commerce_order.post_update.php +++ b/modules/order/commerce_order.post_update.php @@ -53,3 +53,36 @@ function commerce_order_post_update_2() { } } } + +/** + * Revert the Order and Profile entity view displays. + */ +function commerce_order_post_update_3() { + /** @var \Drupal\commerce\Config\ConfigUpdaterInterface $config_updater */ + $config_updater = \Drupal::service('commerce.config_updater'); + + $views = [ + 'core.entity_view_display.commerce_order.default.default', + 'core.entity_view_display.commerce_order.default.user', + 'core.entity_view_display.profile.customer.default', + ]; + $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/core.entity_view_display.commerce_order.default.default.yml b/modules/order/config/install/core.entity_view_display.commerce_order.default.default.yml index df574cd35b..91d4a7377b 100644 --- a/modules/order/config/install/core.entity_view_display.commerce_order.default.default.yml +++ b/modules/order/config/install/core.entity_view_display.commerce_order.default.default.yml @@ -5,21 +5,67 @@ dependencies: - commerce_order.commerce_order_type.default - field.field.commerce_order.default.order_items module: + - commerce_order - commerce_price + - state_machine - user id: commerce_order.default.default targetEntityType: commerce_order bundle: default mode: default content: + changed: + type: timestamp + weight: 4 + label: inline + settings: + date_format: short + custom_date_format: '' + timezone: '' + third_party_settings: { } + completed: + label: inline + type: timestamp + weight: 2 + settings: + date_format: short + custom_date_format: '' + timezone: '' + third_party_settings: { } + ip_address: + label: inline + type: string + weight: 7 + settings: + link_to_entity: false + third_party_settings: { } + mail: + label: inline + type: basic_string + weight: 6 + settings: { } + third_party_settings: { } order_items: - type: entity_reference_entity_view + type: commerce_order_item_table weight: 0 + settings: { } + third_party_settings: { } + label: hidden + placed: + label: inline + type: timestamp + weight: 3 settings: - view_mode: default - link: false + date_format: short + custom_date_format: '' + timezone: '' third_party_settings: { } + state: label: hidden + type: state_transition_form + weight: 8 + settings: { } + third_party_settings: { } total_price: type: commerce_price_default weight: 1 @@ -27,7 +73,14 @@ content: strip_trailing_zeroes: false display_currency_code: false third_party_settings: { } - label: above + label: inline + uid: + label: inline + type: author + weight: 5 + settings: { } + third_party_settings: { } hidden: billing_profile: true + order_number: true store_id: true diff --git a/modules/order/config/install/core.entity_view_display.commerce_order.default.user.yml b/modules/order/config/install/core.entity_view_display.commerce_order.default.user.yml index abc376562e..3ddc42f35c 100644 --- a/modules/order/config/install/core.entity_view_display.commerce_order.default.user.yml +++ b/modules/order/config/install/core.entity_view_display.commerce_order.default.user.yml @@ -7,31 +7,43 @@ dependencies: - field.field.commerce_order.default.order_items module: - commerce_order + - commerce_price + - entity_reference_revisions + - options id: commerce_order.default.user targetEntityType: commerce_order bundle: default mode: user content: billing_profile: - type: entity_reference_entity_view - weight: 3 + type: entity_reference_revisions_entity_view + weight: 0 label: above settings: view_mode: default - link: false + link: '' third_party_settings: { } - order_items: - type: commerce_order_item_table - weight: 4 - settings: { } + completed: + label: inline + type: timestamp + weight: 2 + settings: + date_format: short + custom_date_format: '' + timezone: '' third_party_settings: { } - label: hidden mail: label: inline type: basic_string - weight: 2 + weight: 1 settings: { } third_party_settings: { } + order_items: + type: commerce_order_item_table + weight: 5 + settings: { } + third_party_settings: { } + label: hidden order_number: type: string weight: 0 @@ -42,21 +54,28 @@ content: placed: label: inline type: timestamp - weight: 1 + weight: 3 settings: - date_format: medium + date_format: short custom_date_format: '' timezone: '' third_party_settings: { } - store_id: - type: entity_reference_label - weight: 0 + state: + type: list_default + weight: 4 label: inline + settings: { } + third_party_settings: { } + total_price: + type: commerce_price_default + weight: 6 + label: above settings: - link: false + strip_trailing_zeroes: false + display_currency_code: false third_party_settings: { } hidden: + changed: true ip_address: true - total_price: true - state: true + store_id: true uid: true diff --git a/modules/order/config/install/core.entity_view_display.profile.customer.default.yml b/modules/order/config/install/core.entity_view_display.profile.customer.default.yml index 466ee28a61..3790041af3 100644 --- a/modules/order/config/install/core.entity_view_display.profile.customer.default.yml +++ b/modules/order/config/install/core.entity_view_display.profile.customer.default.yml @@ -17,7 +17,7 @@ content: address: type: address_default weight: 0 - label: above + label: hidden settings: { } third_party_settings: { } hidden: { } diff --git a/modules/order/src/Entity/Order.php b/modules/order/src/Entity/Order.php index cc2ce94368..9d8fbe69c0 100644 --- a/modules/order/src/Entity/Order.php +++ b/modules/order/src/Entity/Order.php @@ -40,7 +40,7 @@ * "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm" * }, * "route_provider" = { - * "default" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider", + * "default" = "Drupal\commerce_order\OrderRouteProvider", * "delete-multiple" = "Drupal\entity\Routing\DeleteMultipleRouteProvider", * }, * }, @@ -545,8 +545,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDisplayConfigurable('view', TRUE); $fields['uid'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Owner')) - ->setDescription(t('The order owner.')) + ->setLabel(t('Customer')) + ->setDescription(t('The customer.')) ->setSetting('target_type', 'user') ->setSetting('handler', 'default') ->setDefaultValueCallback('Drupal\commerce_order\Entity\Order::getCurrentUserId') @@ -646,7 +646,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) - ->setDescription(t('The time when the order was last edited.')); + ->setDescription(t('The time when the order was last edited.')) + ->setDisplayConfigurable('view', TRUE); $fields['placed'] = BaseFieldDefinition::create('timestamp') ->setLabel(t('Placed')) diff --git a/modules/order/src/OrderRouteProvider.php b/modules/order/src/OrderRouteProvider.php new file mode 100644 index 0000000000..2566b932c9 --- /dev/null +++ b/modules/order/src/OrderRouteProvider.php @@ -0,0 +1,23 @@ +setDefault('_entity_view', 'commerce_order.admin'); + + return $route; + } +} diff --git a/modules/order/templates/commerce-order--admin.html.twig b/modules/order/templates/commerce-order--admin.html.twig new file mode 100644 index 0000000000..8bbd437da0 --- /dev/null +++ b/modules/order/templates/commerce-order--admin.html.twig @@ -0,0 +1,85 @@ +{# +/** + * @file + * Order template used on the admin order page. + * + * Available variables: + * - attributes: HTML attributes for the wrapper. + * - order: The rendered order fields. + * Use 'order' to print them all, or print a subset such as + * 'order.order_number'. Use the following code to exclude the + * printing of a given field: + * @code + * {{ order|without('order_number') }} + * @endcode + * - order_entity: The order entity. + * + * @ingroup themeable + */ +#} + +{{ attach_library('commerce_order/form') }} +{% set order_state = order_entity.getState.getLabel %} + +
+
+ {{ order.order_items }} + {{ order.total_price }} +
+
+
+
+

+ {{ order_state }} +

+ {% for key in ['completed', 'placed', 'changed'] %} + {% if order[key] %} +
+ {{ order[key] }} +
+ {% endif %} + {% endfor %} +
+
+ + {{ 'Customer Information'|t }} + +
+ {% for key in ['uid', 'mail', 'ip_address'] %} + {% if order[key] %} +
+ {{ order[key] }} +
+ {% endif %} + {% endfor %} +
+
+ {% if order.billing_information %} +
+ + {{ 'Billing information'|t }} + +
+ {{ order.billing_information }} +
+
+ {% endif %} + {% if order.shipping_information %} +
+ + {{ 'Shipping information'|t }} + +
+ {{ order.shipping_information }} +
+
+ {% endif %} + {# If the order has possible transitions, render the field for transition buttons. #} + {% if order_entity.getState.getTransitions is not empty %} +
+ {{ order.state }} +
+ {% endif %} +
+
+
diff --git a/modules/order/templates/commerce-order--user.html.twig b/modules/order/templates/commerce-order--user.html.twig index f24cf7af9a..d669c55e2c 100644 --- a/modules/order/templates/commerce-order--user.html.twig +++ b/modules/order/templates/commerce-order--user.html.twig @@ -18,5 +18,26 @@ */ #} - {{ order }} +
+ {{ order.mail }} + {% if order.shipping_information %} +
+
{{ 'Shipping information'|t }}
+ {{ order.shipping_information }} +
+ {% endif %} + {% if order.billing_information %} +
+
{{ 'Billing information'|t }}
+ {{ order.billing_information }} +
+ {% endif %} +
+
+ {{ order.completed }} + {{ order.placed }} + {{ order.state }} + {{ order.order_items }} + {{ order.total_price }} +
diff --git a/modules/order/tests/src/Functional/OrderAdminTest.php b/modules/order/tests/src/Functional/OrderAdminTest.php index e8a80720d9..a5a1112161 100644 --- a/modules/order/tests/src/Functional/OrderAdminTest.php +++ b/modules/order/tests/src/Functional/OrderAdminTest.php @@ -158,52 +158,30 @@ public function testAdminOrderView() { 'type' => 'default', 'mail' => $this->loggedInUser->getEmail(), 'order_items' => [$order_item], + 'status' => 'draft', ]); // First test that the current admin user can see the order. $this->drupalGet($order->toUrl()->toString()); $this->assertSession()->statusCodeEquals(200); - - // Order displays email address. $this->assertSession()->pageTextContains($this->loggedInUser->getEmail()); - // Logout and check that anonymous users cannot see the order admin screen - // and receive a 403 error code. - $this->drupalLogout(); - - $this->drupalGet($order->toUrl()->toString()); - $this->assertSession()->statusCodeEquals(403); - } - - /** - * Tests that the order workflow transition buttons appear on the order page. - */ - public function testOrderWorkflowTransitionButtons() { - $order_item = $this->createEntity('commerce_order_item', [ - 'type' => 'default', - 'unit_price' => [ - 'number' => '999', - 'currency_code' => 'USD', - ], - ]); - $order = $this->createEntity('commerce_order', [ - 'type' => 'default', - 'mail' => $this->loggedInUser->getEmail(), - 'order_items' => [$order_item], - 'state' => 'draft', - ]); - - $this->drupalGet('admin/commerce/orders/' . $order->id()); - + // Confirm that the transition buttons are visible and functional. $workflow = $order->getState()->getWorkflow(); $transitions = $workflow->getAllowedTransitions($order->getState()->value, $order); foreach ($transitions as $transition) { $this->assertSession()->buttonExists($transition->getLabel()); } - $this->click('input.js-form-submit#edit-place'); $this->assertSession()->buttonNotExists('Place order'); $this->assertSession()->buttonNotExists('Cancel order'); + + // Logout and check that anonymous users cannot see the order admin screen + // and receive a 403 error code. + $this->drupalLogout(); + + $this->drupalGet($order->toUrl()->toString()); + $this->assertSession()->statusCodeEquals(403); } } diff --git a/modules/payment/commerce_payment.module b/modules/payment/commerce_payment.module index eec298b8a9..6992979b40 100755 --- a/modules/payment/commerce_payment.module +++ b/modules/payment/commerce_payment.module @@ -97,3 +97,16 @@ function template_preprocess_commerce_payment_method(array &$variables) { $variables['payment_method'][$key] = $variables['elements'][$key]; } } + +/** + * Implements hook_preprocess_commerce_order(). + */ +function commerce_payment_preprocess_commerce_order(&$variables) { + /** @var Drupal\commerce_order\Entity\OrderInterface $order */ + $order = $variables['elements']['#commerce_order']; + if (!$order->get('payment_method')->isEmpty()) { + $variables['order']['billing_information']['payment'] = [ + '#markup' => $order->get('payment_method')->first()->entity->label(), + ]; + } +}