-
-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(core-flows,order,medusa,types): Version shipping method adjustments & implement missing creation flow for versioned adjustments #14482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NicolasGorga
wants to merge
26
commits into
develop
Choose a base branch
from
feat/version-order-shipping-method-adjustments
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,917
−316
Open
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
1c18e02
Pass shipping_methods to computeActions context
NicolasGorga 581573f
Tests
NicolasGorga b1dab6f
Add changeset
NicolasGorga 03d0a75
Implementation plan
NicolasGorga a24b8ac
Update db model and add missing indexes
NicolasGorga 083b5ab
Migration
NicolasGorga 7e8a90e
Update todos status
NicolasGorga dbbc932
Data migration script
NicolasGorga 0e1ef49
Update plan
NicolasGorga 63b8fe9
Create versioned shipping methods upon order changes
NicolasGorga 314420e
Delete adjustments on version reversion
NicolasGorga 2abf746
Update plan
NicolasGorga b732970
Fix
NicolasGorga 26bdf7b
Module tests
NicolasGorga d4479d1
Add changeset
NicolasGorga ae6522b
New order change action type to include shipping methods adjustments …
NicolasGorga ef4b875
Inlcude backfill inside migration file since it is not cross module
NicolasGorga 5e72cb1
Fix tests
NicolasGorga b99bb22
Add versioned find of shipping_method adjustments to order repo
NicolasGorga 23df8e6
Pass adjustments to populate when related entity
NicolasGorga d58d91c
Fix tests
NicolasGorga 1155381
Remove new indes on order line item adjustment and version
NicolasGorga 8f21655
Merge branch 'develop' into feat/version-order-shipping-method-adjust…
NicolasGorga a0f877c
Test
NicolasGorga a9d4111
Merge branch 'develop' into feat/version-order-shipping-method-adjust…
NicolasGorga 47cde33
Merge branch 'develop' into feat/version-order-shipping-method-adjust…
NicolasGorga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@medusajs/core-flows": patch | ||
| --- | ||
|
|
||
| fix(core-flows): Pass shipping_methods to computeActions context |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "@medusajs/core-flows": patch | ||
| "@medusajs/order": patch | ||
| "@medusajs/types": patch | ||
| "@medusajs/medusa": patch | ||
| --- | ||
|
|
||
| feat(core-flows,order,medusa,types): Version shipping method adjustments & implement missing creation flow for versioned adjustments |
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
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
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
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
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
42 changes: 42 additions & 0 deletions
42
packages/medusa/src/migration-scripts/backfill-shipping-adjustment-versions.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { ExecArgs } from "@medusajs/framework/types" | ||
| import { ContainerRegistrationKeys } from "@medusajs/framework/utils" | ||
|
|
||
| /** | ||
| * Data migration to backfill version field for existing order_shipping_method_adjustment records. | ||
| * Sets adjustment versions based on the latest order_shipping version for their associated shipping method. | ||
| */ | ||
| export default async function backfillShippingAdjustmentVersions({ | ||
NicolasGorga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| container, | ||
| }: ExecArgs) { | ||
| const knex = container.resolve(ContainerRegistrationKeys.PG_CONNECTION) | ||
| const logger = container.resolve(ContainerRegistrationKeys.LOGGER) | ||
|
|
||
| logger.info("Backfilling shipping method adjustment versions") | ||
|
|
||
| try { | ||
| await knex.transaction(async (trx) => { | ||
| const result = await trx.raw(` | ||
| WITH latest_order_shipping_version AS ( | ||
| SELECT | ||
| os.shipping_method_id AS shipping_method_id, | ||
| MAX(os.version) AS version | ||
| FROM "order_shipping" os | ||
| WHERE os.deleted_at IS NULL | ||
| GROUP BY os.shipping_method_id | ||
| ) | ||
| UPDATE "order_shipping_method_adjustment" osma | ||
| SET version = losv.version | ||
| FROM latest_order_shipping_version losv | ||
| WHERE osma.shipping_method_id = losv.shipping_method_id | ||
| AND osma.version <> losv.version | ||
| `) | ||
|
|
||
| logger.info( | ||
| `Successfully backfilled shipping method adjustment versions (${result.rowCount} rows updated)` | ||
| ) | ||
| }) | ||
| } catch (e) { | ||
| logger.error("Failed to backfill shipping method adjustment versions", e) | ||
| throw e | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: belive the part that is missing is that in this file,
prepareAdjustmentsFromPromotionActionsStepreturns shipping adjustments which we need to store on the change action (or create a new action dedicated to shipping adjustments).Then this adjustments need to be applied when processing a change, see:
packages/modules/order/src/utils/actions/item-adjustments-replace.tsedit: from the plan, I see that some of this was explicitley skipped but without the full flow, new adjustments wont't be created and won't be filtered for that order version when fetching order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good point, will look into it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed lmkwyt @fPolic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, think we are almost there...next thing to consider is when we fetch an order at a specific version that only shipping adjustments for that version are fetched: see
packages/modules/order/src/utils/base-repository-find.tsandloadItemAdjustmentsmethod for referrenceThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed