Repository navigation
[6.x] Removed Commerce's JS dependence on the legacy window.Craft global - #4444
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are blocking approval.
No open issues 🎉
What changed in this PR
Removes Commerce’s JavaScript dependency on legacy window.Craft APIs, allowing affected control panel features to work without the Yii adapter.
Changes:
- Migrates requests, notifications, and translations to
@craftcms/cpexports. - Adds a request compatibility wrapper and updates ambient TypeScript declarations.
- Fixes number-only dashboard charts by explicitly identifying the currency scale as a y-axis.
| File | Description |
|---|---|
resources/js/window.d.ts |
Removes the legacy window.Craft declaration. |
resources/js/pages/prices/Index.vue |
Uses exported translation helpers. |
resources/js/modules/ui/UsageCounterNode.vue |
Migrates reset requests and confirmation translations. |
resources/js/modules/ui/CouponGeneratorNode.vue |
Uses the new request wrapper for coupon generation. |
resources/js/modules/orders/order-actions.ts |
Migrates bulk-action requests and notifications. |
resources/js/modules/orders/cp-client.ts |
Wraps exported request and notification APIs. |
resources/js/modules/dashboard/TableWidget.vue |
Migrates empty-state translation. |
resources/js/modules/dashboard/ChartWidget.vue |
Migrates translation and fixes currency-axis configuration. |
resources/js/cms-elements.d.ts |
Declares the newly used @craftcms/cp exports. |
Review effort: Balanced
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.
Description
Without craftcms/yii2-adapter,
window.Crafthas nosendActionRequestort, so coupon generation, usage reset, the order index bulk actions, the dashboard widgets' empty state and the prices page broke.These now use what
@craftcms/cpexports:actionClient,showNotice,showErrorandt. A smallmodules/orders/cp-client.tswrapsactionClient.requestwith the oldsendActionRequest(method, action, {data, params, responseType})shape, so call sites barely changed.window.d.tsno longer declaresCraft, andcms-elements.d.tsdeclares the new exports.Also fixes the Total Orders line chart never drawing.
ChartWidget.vuedeclared acurrencyy-scale with noaxisorposition, and Chart.js 4.6.1 throws (Cannot read properties of undefined (reading 'axis')) when no dataset uses that scale, which is the case for number-only charts. The scale now setsaxis: 'y'.Checked in a task app with the adapter removed: dashboard Top Products widget, prices page, coupon generation, usage reset, and the order index Download PDF action (it reaches the server and shows its error; there's no PDF template in the seed, so a successful download wasn't tested).
Not covered here: the Edit order bulk action's slideout still 500s because
OrdersController::registerJavascript()calls\Craft::$app.