Add NewCustomerResolverInterface extension point for new_customer field#37
Merged
MikeVerlinde merged 1 commit intomasterfrom Apr 24, 2026
Merged
Conversation
The `new_customer` value is emitted from three separate call sites (Purchase event, UserData order tag, and PurchaseWebhookEvent), each hardcoding `$order->getCustomerIsGuest()` as the heuristic. That leaves no single, upgrade-safe extension point for merchants who want a different definition (e.g. based on prior order count), and breaks for shops that convert guest orders into customer accounts on `sales_order_place_after` — isGuest() is false by the time the value is read. Extract the check into NewCustomerResolverInterface with a default IsGuestResolver implementation that preserves existing behavior. Merchants can now override the heuristic with a single DI preference. https://claude.ai/code/session_01KrUuLFtrNMyY2ZuwrvH8db
MikeVerlinde
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
new_customerfield in the data layer is currently hardcoded to$order->getCustomerIsGuest()in three separate call sites:DataLayer/Event/Purchase.php:84— used by the MageWire/Hyva customer-data push viaObserver/TriggerPurchaseDataLayerEventDataLayer/Tag/Order/UserData.php:57— used by the shared Luma/Hyva success-page layout (view/frontend/layout/checkout_onepage_success.xml)DataLayer/Event/PurchaseWebhookEvent.php:125— used by the server-to-server webhookTwo problems with this:
ProcessorInterfacehook for the webhook path, andafterGetplugins onPurchasedon't cover the success-page tag.isGuest()is a poor proxy for "new customer". A returning customer can check out as a guest, and a new customer can register an account. More importantly, shops that convert guest orders into customer accounts onsales_order_place_afterobserveisGuest() === falseby the time the value is read, so Google Ads' new-customer bid-modifier never receives a signal.This PR extracts the check into
NewCustomerResolverInterface(isNewCustomer(OrderInterface): bool) with a defaultIsGuestResolverimplementation that preserves existing behavior. All three call sites now delegate to the resolver.For merchants
Override the default by adding a preference in your own module's
di.xml:Backwards compatibility
No behavior change for existing installations — the default resolver returns
(bool)$order->getCustomerIsGuest(), matching the previous three hardcoded expressions.Test plan
bin/magento setup:di:compilesucceeds (new interface + preference resolve)TriggerPurchaseDataLayerEventTestintegration test still passesnew_customer: "true"in dataLayer (default behavior preserved)new_customer: "false"(default behavior preserved)new_customervaluehttps://claude.ai/code/session_01KrUuLFtrNMyY2ZuwrvH8db
Generated by Claude Code