You are here

commerce_currency_resolver.module in Commerce Currency Resolver 8

Main module file.

File

commerce_currency_resolver.module
View source
<?php

/**
 * @file
 * Main module file.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\commerce_currency_resolver\Plugin\Commerce\PromotionOffer\OrderItemFixedAmountOff;
use Drupal\commerce_currency_resolver\Plugin\Commerce\PromotionOffer\OrderFixedAmountOff;
use Drupal\commerce_currency_resolver\Plugin\Commerce\Condition\OrderTotalPrice;

/**
 * Implements hook_help().
 */
function commerce_currency_resolver_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the commerce_currency_resolver module.
    case 'help.page.commerce_currency_resolver':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Commerce 2 currency support') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_commerce_promotion_offer_info_alter().
 */
function commerce_currency_resolver_commerce_promotion_offer_info_alter(array &$definitions) {
  $definitions['order_item_fixed_amount_off']['class'] = OrderItemFixedAmountOff::class;
  $definitions['order_fixed_amount_off']['class'] = OrderFixedAmountOff::class;
}

/**
 * Implements hook_commerce_condition_info_alter().
 */
function commerce_currency_resolver_commerce_condition_info_alter(array &$definitions) {
  $definitions['order_total_price']['class'] = OrderTotalPrice::class;
}

/**
 * Implements hook_entity_build_defaults_alter().
 */
function commerce_currency_resolver_entity_view_alter(array &$build, EntityInterface $entity, $view_mode) {

  // Check enabled source. We use cache context only for cookie based
  // currency switch.
  $source = \Drupal::config('commerce_currency_resolver.settings')
    ->get('currency_mapping');

  // Add our cache context.
  if ($source === 'cookie' && (isset($build['#commerce_product']) || isset($build['#commerce_product_variation']))) {
    $build['#cache']['contexts'][] = 'currency_resolver';
  }
}

Functions