Skip to content

[6.x] Removed Commerce's JS dependence on the legacy window.Craft global - #4444

Merged
lukeholder merged 1 commit into
6.xfrom
feature/6x-further-adaptor-removal
Nov 11, 2026
Merged

lukeholder merged 1 commit into
6.xfrom
feature/6x-further-adaptor-removal

Conversation

@nfourtythree

Copy link
Copy Markdown
Contributor

Description

Without craftcms/yii2-adapter, window.Craft has no sendActionRequest or t, 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/cp exports: actionClient, showNotice, showError and t. A small modules/orders/cp-client.ts wraps actionClient.request with the old sendActionRequest(method, action, {data, params, responseType}) shape, so call sites barely changed. window.d.ts no longer declares Craft, and cms-elements.d.ts declares the new exports.

Also fixes the Total Orders line chart never drawing. ChartWidget.vue declared a currency y-scale with no axis or position, 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 sets axis: '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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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/cp exports.
  • 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

@nfourtythree
nfourtythree marked this pull request as ready for review November 10, 2026 12:33
@nfourtythree
nfourtythree requested a review from a team as a code owner November 10, 2026 12:33
@lukeholder
lukeholder merged commit ed39715 into 6.x Nov 11, 2026
8 checks passed
@lukeholder
lukeholder deleted the feature/6x-further-adaptor-removal branch November 11, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants