Skip to content

Commit 4ba1fad

Browse files
vasikebojanz
authored andcommitted
Issue #2866419 by vasike, bojanz: Order total summary missing in cart
1 parent 7c286c0 commit 4ba1fad

5 files changed

Lines changed: 65 additions & 1 deletion

File tree

modules/cart/commerce_cart.module

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ function commerce_cart_theme($existing, $type, $theme, $path) {
3232
];
3333
}
3434

35+
/**
36+
* Implements hook_preprocess_views_view().
37+
*
38+
* Moves the commerce_cart_form footer output above the submit buttons.
39+
*/
40+
function commerce_cart_preprocess_views_view(&$variables) {
41+
$view = $variables['view'];
42+
if (strpos($view->storage->get('tag'), 'commerce_cart_form') !== FALSE) {
43+
$variables['rows']['footer'] = $variables['footer'];
44+
$variables['footer'] = '';
45+
}
46+
}
47+
3548
/**
3649
* Implements hook_entity_base_field_info().
3750
*/

modules/cart/commerce_cart.post_update.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,35 @@ function commerce_cart_post_update_1() {
3737

3838
return $message;
3939
}
40+
41+
/**
42+
* Revert the cart block and form views.
43+
*/
44+
function commerce_cart_post_update_2() {
45+
/** @var \Drupal\commerce\Config\ConfigUpdaterInterface $config_updater */
46+
$config_updater = \Drupal::service('commerce.config_updater');
47+
48+
$views = [
49+
'views.view.commerce_cart_block',
50+
'views.view.commerce_cart_form',
51+
];
52+
$result = $config_updater->revert($views);
53+
54+
$success_results = $result->getSucceeded();
55+
$failure_results = $result->getFailed();
56+
if ($success_results) {
57+
$message = t('Succeeded:') . '<br>';
58+
foreach ($success_results as $success_message) {
59+
$message .= $success_message . '<br>';
60+
}
61+
$message .= '<br>';
62+
}
63+
if ($failure_results) {
64+
$message .= t('Failed:') . '<br>';
65+
foreach ($failure_results as $failure_message) {
66+
$message .= $failure_message . '<br>';
67+
}
68+
}
69+
70+
return $message;
71+
}

modules/cart/config/install/views.view.commerce_cart_form.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,16 @@ display:
396396
entity_field: order_item_id
397397
plugin_id: standard
398398
header: { }
399-
footer: { }
399+
footer:
400+
commerce_order_total:
401+
id: commerce_order_total
402+
table: views
403+
field: commerce_order_total
404+
relationship: none
405+
group_type: group
406+
admin_label: ''
407+
empty: false
408+
plugin_id: commerce_order_total
400409
empty: { }
401410
relationships:
402411
order_items:

modules/cart/tests/src/Functional/CartTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function testCartPage() {
6565
$this->cartManager->addEntity($this->cart, $this->variation);
6666

6767
$this->drupalGet('cart');
68+
// Confirm the presence of the order total summary.
69+
$this->assertSession()->elementTextContains('css', '.order-total-line', 'Subtotal');
70+
$this->assertSession()->elementTextContains('css', '.order-total-line', 'Total');
71+
$this->assertSession()->pageTextContains('$999.00');
6872
// Confirm the presence and functioning of the Quantity field.
6973
$this->assertSession()->fieldValueEquals('edit-edit-quantity-0', 1);
7074
$this->assertSession()->buttonExists('Update cart');
@@ -73,6 +77,8 @@ public function testCartPage() {
7377
];
7478
$this->submitForm($values, t('Update cart'));
7579
$this->assertSession()->fieldValueEquals('edit-edit-quantity-0', 2);
80+
$this->assertSession()->elementTextContains('css', '.order-total-line', 'Total');
81+
$this->assertSession()->pageTextContains('$1,998.00');
7682

7783
// Confirm the presence and functioning of the Remove button.
7884
$this->assertSession()->buttonExists('Remove');

modules/promotion/tests/src/Functional/CouponRedemptionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public function testCouponRedemption() {
117117
$existing_coupon = $this->promotion->get('coupons')->first()->entity;
118118

119119
$this->assertSession()->pageTextContains('Enter your promotion code to redeem a discount.');
120+
$this->assertSession()->elementTextNotContains('css', '.order-total-line', 'Discount');
120121

121122
// Test entering an invalid coupon.
122123
$this->getSession()->getPage()->fillField('Promotion code', $this->randomString());
@@ -127,11 +128,14 @@ public function testCouponRedemption() {
127128
$this->getSession()->getPage()->pressButton('Apply');
128129

129130
$this->assertSession()->pageTextContains('Coupon applied');
131+
$this->assertSession()->elementTextContains('css', '.order-total-line', 'Discount');
132+
$this->assertSession()->pageTextContains('-$99.90');
130133

131134
$this->assertSession()->fieldNotExists('coupons[code]');
132135
$this->assertSession()->buttonNotExists('Apply');
133136
$this->getSession()->getPage()->pressButton('Remove promotion');
134137

138+
$this->assertSession()->elementTextNotContains('css', '.order-total-line', 'Discount');
135139
$this->assertSession()->fieldExists('coupons[code]');
136140
$this->assertSession()->buttonExists('Apply');
137141
}

0 commit comments

Comments
 (0)