You are here

class ShippingCurrencyOrderProcessor in Commerce Currency Resolver 8

Force refresh of shipping rates for shipment for currency changes.

Hierarchy

Expanded class hierarchy of ShippingCurrencyOrderProcessor

1 string reference to 'ShippingCurrencyOrderProcessor'
commerce_currency_resolver_shipping.services.yml in modules/shipping/commerce_currency_resolver_shipping.services.yml
modules/shipping/commerce_currency_resolver_shipping.services.yml
1 service uses ShippingCurrencyOrderProcessor
commerce_currency_resolver_shipping.order_processor in modules/shipping/commerce_currency_resolver_shipping.services.yml
Drupal\commerce_currency_resolver_shipping\ShippingCurrencyOrderProcessor

File

modules/shipping/src/ShippingCurrencyOrderProcessor.php, line 13

Namespace

Drupal\commerce_currency_resolver_shipping
View source
class ShippingCurrencyOrderProcessor implements OrderProcessorInterface {

  /**
   * The shipping order manager.
   *
   * @var \Drupal\commerce_shipping\ShippingOrderManagerInterface
   */
  protected $shippingOrderManager;

  /**
   * Constructs a new ShippingCurrencyOrderProcessor object.
   *
   * @param \Drupal\commerce_shipping\ShippingOrderManagerInterface $shipping_order_manager
   *   The shipping order manager.
   */
  public function __construct(ShippingOrderManagerInterface $shipping_order_manager) {
    $this->shippingOrderManager = $shipping_order_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function process(OrderInterface $order) {

    // No shipment, skip order.
    if (!$this->shippingOrderManager
      ->hasShipments($order)) {
      return;
    }

    // No need to trigger this processor.
    if (!$order
      ->getData(CurrencyHelper::CURRENCY_ORDER_REFRESH)) {
      return;
    }

    // Unset flag.
    $order
      ->unsetData(CurrencyHelper::CURRENCY_ORDER_REFRESH);

    // If we don't have already this flag, trigger it.
    // Otherwise amount on shipment is gonna be on old currency.
    if (!$order
      ->getData(ShippingOrderManagerInterface::FORCE_REFRESH)) {
      $order
        ->setData(ShippingOrderManagerInterface::FORCE_REFRESH, TRUE);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ShippingCurrencyOrderProcessor::$shippingOrderManager protected property The shipping order manager.
ShippingCurrencyOrderProcessor::process public function Processes an order. Overrides OrderProcessorInterface::process
ShippingCurrencyOrderProcessor::__construct public function Constructs a new ShippingCurrencyOrderProcessor object.