Skip to content
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

feat(core-flows,medusa,order,types): update orders #10373

Merged
merged 19 commits into from
Dec 3, 2024
Merged

Conversation

fPolic
Copy link
Contributor

@fPolic fPolic commented Nov 29, 2024

What

  • add order update endpoint
  • add workflows and steps for updating orders
  • add registerChanges method to Order module + workflow step

CLOSES CMRC-633

Copy link

vercel bot commented Nov 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 3, 2024 4:54pm
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Dec 3, 2024 4:54pm
api-reference-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 3, 2024 4:54pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview Dec 3, 2024 4:54pm
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 3, 2024 4:54pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Dec 3, 2024 4:54pm
resources-docs ⬜️ Ignored (Inspect) Visit Preview Dec 3, 2024 4:54pm

Copy link

changeset-bot bot commented Nov 29, 2024

⚠️ No Changeset found

Latest commit: 6738799

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

}
})

const change = createOrderChangeStep(orderChangeInput)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

self-comment: should we move the next 4 calls to an order service method like registerOrderChange that would create a dummy change record in case we wanna note that some generic change occurred on an order.
Method would:

  1. create already confirmed order change
  2. create a generic action for the change that is already "applied"

Copy link
Contributor

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. think it would be good to have this generic method on the order class.
That could be used for general "comments" on the order as well.

packages/medusa/src/api/admin/orders/[id]/route.ts Outdated Show resolved Hide resolved
import { setActionReference } from "../set-action-reference"

OrderChangeProcessing.registerActionType(
ChangeActionType.CHANGE_SHIPPING_ADDRESS,
Copy link
Contributor

@olivermrbl olivermrbl Dec 2, 2024

Choose a reason for hiding this comment

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

thought: I would be curious to hear @carlos-r-l-rodrigues's thoughts on creating a more generic action, that can be used for updates that does not have any validation and where the operation is basically just updating the property on the order.

For example:

OrderChangeProcessing.registerActionType(
  ChangeActionType.ORDER_UPDATE,
  {
    operation({ action, currentOrder, options }) {
      /**
       * NOOP: used as a reference for the change
       */

      setActionReference(currentOrder, action, options)
    },
    validate({ action }) {
      /* noop */
    },
  }
)

The order change action generated for this type of update would then be:

Shipping address

const actionInput = transform(
   { order, input, change },
   ({ order, input, change }) => [
     {
       order_change_id: change.id,
       order_id: input.order_id,
       action: ChangeActionType.ORDER_UPDATE,
       version: change.version,
       reference: "shipping_address"
       applied: true,
       reference_id: order.shipping_address?.id,
       details: input.shipping_address as Record<string, unknown>,
     },
   ]
 )

Email

const actionInput = transform(
   { order, input, change },
   ({ order, input, change }) => [
     {
       order_change_id: change.id,
       order_id: input.order_id,
       action: ChangeActionType.ORDER_UPDATE,
       version: change.version,
       reference: "email"
       applied: true,
       reference_id: order.email,
       details: { email: input.email },
     },
   ]
 )

Billing address

const actionInput = transform(
   { order, input, change },
   ({ order, input, change }) => [
     {
       order_change_id: change.id,
       order_id: input.order_id,
       action: ChangeActionType.ORDER_UPDATE,
       version: change.version,
       reference: "billing_address"
       applied: true,
       reference_id: order.billing_address?.id,
       details: input.billing_address as Record<string, unknown>,
     },
   ]
 )

Perhaps, a question to ask: Do we gain anything from having the specific actions? If not, we made as well save ourselves from having multiple actions for these updates.

Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues Dec 2, 2024

Choose a reason for hiding this comment

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

Currently, that action accepts anything, even if there is no "action" associated with it on the Order module.
So, it is really up to us to decide. To me, an ORDER_UPDATE seems to fit well, and anything to distinguish them on the UI, can go on the details

}
})

const change = createOrderChangeStep(orderChangeInput)
Copy link
Contributor

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. think it would be good to have this generic method on the order class.
That could be used for general "comments" on the order as well.

integration-tests/http/__tests__/order/admin/order.spec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

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

This is a neat approach. LGTM – would be good to have @carlos-r-l-rodrigues take a look at it as well

packages/medusa/src/api/admin/orders/[id]/route.ts Outdated Show resolved Hide resolved
@fPolic fPolic changed the title feat(core-flows,medusa,order,types): order update shipping address feat(core-flows,medusa,order,types): update orders Dec 3, 2024
@fPolic fPolic marked this pull request as ready for review December 3, 2024 08:50
Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues left a comment

Choose a reason for hiding this comment

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

Nice... LGTM

@olivermrbl
Copy link
Contributor

@fPolic, should we merge this?

@kodiakhq kodiakhq bot merged commit ab948b7 into develop Dec 3, 2024
23 checks passed
@kodiakhq kodiakhq bot deleted the feat/order-update branch December 3, 2024 17:15
hirotaka pushed a commit to hirotaka/medusa that referenced this pull request Dec 7, 2024
**What**
- add order update endpoint
- add workflows and steps for updating orders
- add `registerChanges` method to Order module + workflow step

---

CLOSES CMRC-633
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants