diff --git a/src/Plugin/Commerce/CheckoutPane/ShippingInformation.php b/src/Plugin/Commerce/CheckoutPane/ShippingInformation.php index b573764..f5fba57 100644 --- a/src/Plugin/Commerce/CheckoutPane/ShippingInformation.php +++ b/src/Plugin/Commerce/CheckoutPane/ShippingInformation.php @@ -7,6 +7,8 @@ use Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface; use Drupal\commerce_shipping\OrderShipmentSummaryInterface; use Drupal\commerce_shipping\PackerManagerInterface; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; @@ -28,6 +30,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class ShippingInformation extends CheckoutPaneBase implements ContainerFactoryPluginInterface { + /** + * The shipping options wrapper. + */ + private const SHIPPING_OPTIONS_WRAPPER = 'shipping-information-shipments-wrapper'; + /** * The packer manager. * @@ -195,7 +202,6 @@ class ShippingInformation extends CheckoutPaneBase implements ContainerFactoryPl '#recalculate' => TRUE, '#ajax' => [ 'callback' => [get_class($this), 'ajaxRefresh'], - 'wrapper' => 'shipping-information-shipments-wrapper', ], // The calculation process only needs a valid shipping profile. '#limit_validation_errors' => [ @@ -210,7 +216,7 @@ class ShippingInformation extends CheckoutPaneBase implements ContainerFactoryPl '#value' => [], ]; $pane_form['shipments'] = [ - '#prefix' => '
', + '#prefix' => '
', '#type' => 'container', '#suffix' => '
', ]; @@ -254,7 +260,13 @@ class ShippingInformation extends CheckoutPaneBase implements ContainerFactoryPl $triggering_element = $form_state->getTriggeringElement(); $parents = array_slice($triggering_element['#parents'], 0, -1); $pane_form = NestedArray::getValue($form, $parents); - return $pane_form['shipments']; + + $element = $pane_form['shipments']; + + $renderer = \Drupal::service('renderer'); + $response = new AjaxResponse(); + $response->addCommand(new ReplaceCommand('#' . self::SHIPPING_OPTIONS_WRAPPER, $renderer->render($element))); + return $response; } /**