Skip to content

Commit 643bb39

Browse files
simgui8mglaman
authored andcommitted
Issue #2859834 by flocondetoile, simgui8, andypost, Lukas von Blarer, heddn, mglaman, Sumi, bojanz, finne: Allow checkout progress to link to previous steps
1 parent 177d3f7 commit 643bb39

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

modules/checkout/config/install/commerce_checkout.commerce_checkout_flow.default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ label: Default
66
plugin: multistep_default
77
configuration:
88
display_checkout_progress: true
9+
display_checkout_progress_breadcrumb_links: false
910
panes:
1011
login:
1112
allow_guest_checkout: true

modules/checkout/config/schema/commerce_checkout.schema.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ commerce_checkout_flow_with_panes_configuration:
3838
display_checkout_progress:
3939
type: boolean
4040
label: 'Display checkout progress'
41+
display_checkout_progress_breadcrumb_links:
42+
type: boolean
43+
label: 'Display checkout progress breadcrumb links'
4144
order_summary_view:
4245
type: string
4346
label: 'Order summary view'

modules/checkout/src/Plugin/Block/CheckoutProgressBlock.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Drupal\commerce_checkout\CheckoutOrderManagerInterface;
66
use Drupal\Core\Block\BlockBase;
7+
use Drupal\Core\Link;
78
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
89
use Drupal\Core\Routing\RouteMatchInterface;
910
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -109,9 +110,24 @@ public function build() {
109110
continue;
110111
}
111112

113+
// Create breadcrumb style links for active checkout steps.
114+
if (
115+
$current_step_id !== 'complete' &&
116+
$configuration['display_checkout_progress_breadcrumb_links'] &&
117+
$index <= $current_step_index
118+
) {
119+
$label = Link::createFromRoute($step_definition['label'], 'commerce_checkout.form', [
120+
'commerce_order' => $order->id(),
121+
'step' => $step_id,
122+
])->toString();
123+
}
124+
else {
125+
$label = $step_definition['label'];
126+
}
127+
112128
$steps[] = [
113129
'id' => $step_id,
114-
'label' => $step_definition['label'],
130+
'label' => $label,
115131
'position' => $position,
116132
];
117133
}

modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowBase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ public function setConfiguration(array $configuration) {
235235
public function defaultConfiguration() {
236236
return [
237237
'display_checkout_progress' => TRUE,
238+
'display_checkout_progress_breadcrumb_links' => FALSE,
238239
];
239240
}
240241

@@ -248,6 +249,12 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
248249
'#description' => $this->t('Used by the checkout progress block to determine visibility.'),
249250
'#default_value' => $this->configuration['display_checkout_progress'],
250251
];
252+
$form['display_checkout_progress_breadcrumb_links'] = [
253+
'#type' => 'checkbox',
254+
'#title' => $this->t('Display checkout progress breadcrumb as links'),
255+
'#description' => $this->t('Let the checkout progress block render the breadcrumb as links.'),
256+
'#default_value' => $this->configuration['display_checkout_progress_breadcrumb_links'],
257+
];
251258

252259
return $form;
253260
}
@@ -265,6 +272,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
265272
$values = $form_state->getValue($form['#parents']);
266273
$this->configuration = [];
267274
$this->configuration['display_checkout_progress'] = $values['display_checkout_progress'];
275+
$this->configuration['display_checkout_progress_breadcrumb_links'] = $values['display_checkout_progress_breadcrumb_links'];
268276
}
269277
}
270278

modules/checkout/templates/commerce-checkout-progress.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
#}
1515
<ol class="checkout-progress clearfix">
1616
{% for step in steps %}
17-
<li class="checkout-progress--step checkout-progress--step__{{ step.position }}">{{ step.label }}</li>
17+
<li class="checkout-progress--step checkout-progress--step__{{ step.position }}">{{ step.label }}</li>
1818
{% endfor %}
1919
</ol>

modules/checkout/tests/src/Functional/CheckoutOrderTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public function testCacheMetadata() {
145145
* Tests anonymous and authenticated checkout.
146146
*/
147147
public function testCheckout() {
148+
$config = \Drupal::configFactory()->getEditable('commerce_checkout.commerce_checkout_flow.default');
149+
$config->set('configuration.display_checkout_progress_breadcrumb_links', TRUE);
150+
$config->save();
151+
148152
$this->drupalLogout();
149153
$this->drupalGet($this->product->toUrl());
150154
$this->submitForm([], 'Add to cart');
@@ -154,7 +158,15 @@ public function testCheckout() {
154158
$this->submitForm([], 'Checkout');
155159
$this->assertSession()->pageTextNotContains('Order Summary');
156160

161+
// Check breadcrumbs are links.
162+
$this->assertSession()->elementsCount('css', '.block-commerce-checkout-progress li.checkout-progress--step > a', 0);
163+
$this->submitForm([], 'Continue as Guest');
164+
// Check breadcrumb link functionality.
165+
$this->assertSession()->elementsCount('css', '.block-commerce-checkout-progress li.checkout-progress--step > a', 1);
166+
$this->getSession()->getPage()->findLink('Login')->click();
167+
$this->assertSession()->pageTextNotContains('Order Summary');
157168
$this->assertCheckoutProgressStep('Login');
169+
158170
$this->submitForm([], 'Continue as Guest');
159171
$this->assertCheckoutProgressStep('Order information');
160172
$this->submitForm([
@@ -169,6 +181,7 @@ public function testCheckout() {
169181
'billing_information[profile][address][0][address][administrative_area]' => 'CA',
170182
], 'Continue to review');
171183
$this->assertCheckoutProgressStep('Review');
184+
$this->assertSession()->elementsCount('css', '.block-commerce-checkout-progress li.checkout-progress--step > a', 2);
172185
$this->assertSession()->pageTextContains('Contact information');
173186
$this->assertSession()->pageTextContains('Billing information');
174187
$this->assertSession()->pageTextContains('Order Summary');
@@ -218,6 +231,15 @@ public function testCheckout() {
218231
$this->submitForm([], 'Continue to review');
219232
$this->assertSession()->pageTextContains('Billing information');
220233
$this->assertSession()->pageTextContains('Order Summary');
234+
$this->assertSession()->elementsCount('css', '.block-commerce-checkout-progress li.checkout-progress--step > a', 1);
235+
$this->assertCheckoutProgressStep('Review');
236+
237+
// Go back with the breadcrumb.
238+
$this->getSession()->getPage()->findLink('Order information')->click();
239+
$this->assertSession()->pageTextContains('Order Summary');
240+
$this->assertCheckoutProgressStep('Order information');
241+
$this->assertSession()->elementsCount('css', '.block-commerce-checkout-progress li.checkout-progress--step > a', 0);
242+
$this->submitForm([], 'Continue to review');
221243
$this->assertCheckoutProgressStep('Review');
222244

223245
// Go back and forth.
@@ -262,6 +284,8 @@ public function testRegisterOrderCheckout() {
262284
'login[register][password][pass2]' => 'pass',
263285
], 'Create account and continue');
264286
$this->assertSession()->pageTextContains('Billing information');
287+
// Check breadcrumbs are not links. (the default setting)
288+
$this->assertSession()->elementNotExists('css', '.block-commerce-checkout-progress li.checkout-progress--step > a');
265289

266290
// Test account validation.
267291
$this->drupalLogout();

0 commit comments

Comments
 (0)