CurrentCurrencyInterface should be used when using Dependency Injection

Created on 14 March 2024, 9 months ago
Updated 21 August 2024, 4 months ago

Problem/Motivation

We have some cases we need to override the CurrentCurrency service (commerce_currency_resolver.current_currency).

But doing to leads to problems where CurrentCurrency is used instead of CurrentCurrencyInterface, such as CurrencyCacheContext.php, CurrencyOrderProcessor.php, etc.

Steps to reproduce

Override the commerce_currency_resolver.current_currency service in a custom module.

This causes errors like below;

TypeError: Drupal\commerce_currency_resolver\Cache\Context\CurrencyCacheContext::__construct(): Argument #1 ($current_currency) must be of type Drupal\commerce_currency_resolver\CurrentCurrency, Drupal\custom_currency_resolver\CurrentCurrency given

Proposed resolution

As it "currentCurrency" variables as defined as "CurrentCurrencyInterface" in the classes, dependency injections can be changed to "CurrentCurrencyInterface".

🐛 Bug report
Status

RTBC

Version

1.70

Component

Code

Created by

🇹🇷Turkey mtbrkrgn

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024