You are here

dc_ajax_add_cart_popup.module in Commerce Ajax Add to Cart 8

Display a modal popup after a product is added to the cart with AJAX.

File

modules/dc_ajax_add_cart_popup/dc_ajax_add_cart_popup.module
View source
<?php

/**
 * @file
 * Display a modal popup after a product is added to the cart with AJAX.
 */

/**
 * Implements hook_theme().
 */
function dc_ajax_add_cart_popup_theme($existing, $type, $theme, $path) {
  return [
    'dc_ajax_add_cart_popup' => [
      'variables' => [
        'product_variation' => NULL,
        'product_variation_entity' => NULL,
        'cart_url' => NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function dc_ajax_add_cart_popup_form_commerce_order_item_dc_ajax_add_cart_form_alter(&$form, &$form_state, $form_id) {
  $form['#attached']['library'][] = 'core/drupal.dialog.ajax';
  $form['actions']['submit']['#ajax']['disable-refocus'] = TRUE;
}