class CurrencyOrderRefresh in Commerce Currency Resolver 8
Checking for mismatch in currencies on order.
@package Drupal\commerce_currency_resolver\EventSubscriber
Hierarchy
- class \Drupal\commerce_currency_resolver\EventSubscriber\CurrencyOrderRefresh implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses CommerceCurrencyResolversRefreshTrait
Expanded class hierarchy of CurrencyOrderRefresh
1 string reference to 'CurrencyOrderRefresh'
1 service uses CurrencyOrderRefresh
File
- src/
EventSubscriber/ CurrencyOrderRefresh.php, line 18
Namespace
Drupal\commerce_currency_resolver\EventSubscriberView source
class CurrencyOrderRefresh implements EventSubscriberInterface {
use CommerceCurrencyResolversRefreshTrait;
/**
* The order refresh.
*
* @var \Drupal\commerce_order\OrderRefreshInterface
*/
protected $orderRefresh;
/**
* Current currency.
*
* @var \Drupal\commerce_currency_resolver\CurrentCurrencyInterface
*/
protected $currentCurrency;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* {@inheritdoc}
*/
public function __construct(CurrentCurrency $currency, OrderRefreshInterface $order_refresh, AccountInterface $account) {
$this->account = $account;
$this->currentCurrency = $currency;
$this->orderRefresh = $order_refresh;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = [
'commerce_order.commerce_order.load' => 'checkCurrency',
];
return $events;
}
/**
* Check for misplace in currency. Refresh order if necessary.
*
* @param \Drupal\commerce_order\Event\OrderEvent $event
* The order event.
*/
public function checkCurrency(OrderEvent $event) {
$orders =& drupal_static(__FUNCTION__, []);
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $event
->getOrder();
// We already have fired this event.
if (isset($orders[$order
->id()])) {
return;
}
// Get order total currency.
if ($this
->shouldCurrencyRefresh($order) && ($order_total = $order
->getTotalPrice())) {
$order_currency = $order_total
->getCurrencyCode();
$resolved_currency = $this->currentCurrency
->getCurrency();
// Compare order total and main resolved currency.
// Refresh order if they are different. We need then alter total price.
// This will trigger order processor which will handle
// correction of total order price and currency.
if ($order_currency !== $resolved_currency) {
// Set as flag to trigger this even once.
$orders[$order
->id()] = TRUE;
// Check if we can refresh order.
$this->orderRefresh
->refresh($order);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommerceCurrencyResolversRefreshTrait:: |
public | function | Check if order belongs to current user. | |
CommerceCurrencyResolversRefreshTrait:: |
public | function | Check if order is in draft status. | |
CommerceCurrencyResolversRefreshTrait:: |
public | function | Detect admin/* paths. | |
CommerceCurrencyResolversRefreshTrait:: |
public | function | Check shipping admin route. | |
CommerceCurrencyResolversRefreshTrait:: |
public | function | Get refresh state based on path. | |
CurrencyOrderRefresh:: |
protected | property | The current user. | |
CurrencyOrderRefresh:: |
protected | property | Current currency. | |
CurrencyOrderRefresh:: |
protected | property | The order refresh. | |
CurrencyOrderRefresh:: |
public | function | Check for misplace in currency. Refresh order if necessary. | |
CurrencyOrderRefresh:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
CurrencyOrderRefresh:: |
public | function |