You are here

public function ProductVariationFieldRenderer::replaceRenderedFields in Commerce Core 8.2

Replaces the rendered variation fields via AJAX.

Called by the add to cart form when the selected variation changes.

Parameters

\Drupal\Core\Ajax\AjaxResponse $response: The AJAX response.

\Drupal\commerce_product\Entity\ProductVariationInterface $variation: The product variation.

string $view_mode: The display mode.

Overrides ProductVariationFieldRendererInterface::replaceRenderedFields

File

modules/product/src/ProductVariationFieldRenderer.php, line 72

Class

ProductVariationFieldRenderer

Namespace

Drupal\commerce_product

Code

public function replaceRenderedFields(AjaxResponse $response, ProductVariationInterface $variation, $view_mode = 'default') {
  $rendered_fields = $this
    ->renderFields($variation, $view_mode);
  foreach ($rendered_fields as $field_name => $rendered_field) {
    $response
      ->addCommand(new ReplaceCommand('.' . $rendered_field['#ajax_replace_class'], $rendered_field));
  }
}