You are here

commerce_add_to_cart_confirmation.module in Commerce add to cart confirmation 1.x

Same filename and directory in other branches
  1. 7 commerce_add_to_cart_confirmation.module

Commerce add to cart confirmation module.

File

commerce_add_to_cart_confirmation.module
View source
<?php

/**
 * @file
 * Commerce add to cart confirmation module.
 */

/**
 * Implements hook_theme().
 */
function commerce_add_to_cart_confirmation_theme() {
  return [
    'commerce_add_to_cart_confirmation' => [
      'template' => 'commerce_add_to_cart_confirmation',
      'path' => drupal_get_path('module', 'commerce_add_to_cart_confirmation') . '/templates',
      'variables' => [
        'title' => NULL,
        'message' => NULL,
        'order_item' => NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_page_attachments().
 */
function commerce_add_to_cart_confirmation_page_attachments(array &$attachments) {
  if (\Drupal::messenger()
    ->messagesByType('commerce-add-to-cart-confirmation')) {
    $attachments['#attached']['library'][] = 'commerce_add_to_cart_confirmation/commerce_add_to_cart_confirmation';
  }
}

/**
 * Implements hook_preprocess_HOOK().
 */
function template_preprocess_commerce_add_to_cart_confirmation(&$variables) {
  $variables['attributes']['class'][] = 'message-inner';
  $variables['attributes']['class'][] = 'commerce-add-to-cart-confirmation';

  // Add variation related class.
  if ($variables['order_item']
    ->hasPurchasedEntity()) {
    $variables['attributes']['class'][] = 'item-type--' . $variables['order_item']
      ->getPurchasedEntity()
      ->bundle();
  }
}