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

Add separate render function to CheckoutProgressBlock #869

Open
wants to merge 3 commits into
base: 8.x-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion modules/checkout/src/Plugin/Block/CheckoutProgressBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\commerce_checkout\Plugin\Block;

use Drupal\commerce_checkout\CheckoutOrderManagerInterface;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
Expand Down Expand Up @@ -79,6 +80,18 @@ public function build() {
// The block is being rendered outside of the checkout page.
return [];
}

$requested_step_id = $this->routeMatch->getParameter('step');
return $this->render($order, $requested_step_id);
}

/**
* Builds the checkout progress block.
*
* @return array
* A render array.
*/
public function render(OrderInterface $order, string $requested_step_id) {
$checkout_flow = $this->checkoutOrderManager->getCheckoutFlow($order);
$checkout_flow_plugin = $checkout_flow->getPlugin();
$configuration = $checkout_flow_plugin->getConfiguration();
Expand All @@ -89,7 +102,6 @@ public function build() {
// Prepare the steps as expected by the template.
$steps = [];
$visible_steps = $checkout_flow_plugin->getVisibleSteps();
$requested_step_id = $this->routeMatch->getParameter('step');
$current_step_id = $this->checkoutOrderManager->getCheckoutStepId($order, $requested_step_id);
$current_step_index = array_search($current_step_id, array_keys($visible_steps));
$index = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane;

use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\Core\Form\FormStateInterface;

/**
Expand Down Expand Up @@ -70,6 +71,9 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
* {@inheritdoc}
*/
public function isVisible() {
if (!$this->order instanceof OrderInterface) {
return FALSE;
}
// Show the pane only for guest checkout.
return empty($this->order->getCustomerId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\commerce\InlineFormManager;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_payment\Exception\DeclineException;
use Drupal\commerce_payment\Exception\PaymentGatewayException;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\ManualPaymentGatewayInterface;
Expand Down Expand Up @@ -129,6 +130,9 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
* {@inheritdoc}
*/
public function isVisible() {
if (!$this->order instanceof OrderInterface) {
return FALSE;
}
if ($this->order->isPaid() || $this->order->getTotalPrice()->isZero()) {
// No payment is needed if the order is free or has already been paid.
return FALSE;
Expand Down