When applying a fixed amount off promotion (order subtotal discount) with a coupon, the following error occurs:
Error: Call to a member function split() on null in Drupal\commerce_promotion\Plugin\Commerce\PromotionOffer\OrderFixedAmountOff->apply() (line 58 of
/app/web/modules/contrib/commerce/modules/promotion/src/Plugin/Commerce/PromotionOffer/OrderFixedAmountOff.php)
The root cause is in commerce_currency_resolver_exchanger module's OrderFixedAmountOff class (modules/exchanger/src/Plugin/Commerce/PromotionOffer/OrderFixedAmountOff.php). This class extends the
base Commerce OrderFixedAmountOff and overrides the create() method to inject additional currency resolver services, but fails to inject the $splitter property that the parent class requires.
When the parent's apply() method executes, it attempts to call $this->splitter->split($order, $amount) at line 58, but $splitter is null, resulting in a fatal error
| Comment | File | Size | Author |
|---|---|---|---|
| commerce_currency_resolver-missing-splitter.patch | 729 bytes | c_archer |
Issue fork commerce_currency_resolver-3568323
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
c_archer commentedComment #5
introfini commentedImproved fix in MR !13
Thanks @c_archer for identifying the root cause and providing the initial patch — it pointed straight to the problem!
I've pushed an alternative fix to MR !13 that goes a step further. The original patch adds
$instance->splitterwhich fixes the immediate crash, but thenew static()pattern still bypasses the rest ofthe parent
create()chain, leaving two other things uninitialized:$this->rounder(fromPromotionOfferBase::create())setConfiguration()is never called, sodefaultConfiguration()values are not merged with stored configThe sibling class
OrderItemFixedAmountOffin the same module already follows the correct pattern — callingparent::create()and then adding its own services. MR !13 applies the same approach toOrderFixedAmountOff:new static()OrderItemFixedAmountOff)new static()withparent::create()so the full chain runs:PromotionOfferBase::create()(sets rounder, calls setConfiguration) →OrderPromotionOfferBase::create()(sets splitter) → our override (sets currency resolver services)
This also future-proofs against any new services added to the parent chain in Commerce core.
Verified both
splitterandrounderare properly initialized after the fix.Comment #8
valictnx to all, updated, add tests, did clean up all of the conditions
Comment #9
valic