forked from a64f7bb4-7358-4778-9fbe-3b882c34cc1d/v1
69 lines
2.4 KiB
PHP
69 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Main module file.
|
|
*/
|
|
|
|
use Drupal\commerce_currency_resolver\Plugin\Commerce\Fee\OrderFixedAmount;
|
|
use Drupal\commerce_currency_resolver\Plugin\Commerce\Fee\OrderItemFixedAmount;
|
|
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_fee_info_alter().
|
|
*/
|
|
function commerce_currency_resolver_commerce_fee_info_alter(array &$definitions) {
|
|
$definitions['order_item_fixed_amount']['class'] = OrderItemFixedAmount::class;
|
|
$definitions['order_fixed_amount']['class'] = OrderFixedAmount::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';
|
|
}
|
|
}
|