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(medusa, core-flows, fulfillment): calculate SO price endpoint #10532

Merged
merged 10 commits into from
Dec 12, 2024

Conversation

fPolic
Copy link
Contributor

@fPolic fPolic commented Dec 10, 2024

What

  • endpoint + flow for fetching calculated price for a shipping option

CLOSES CMRC-777

Copy link

vercel bot commented Dec 10, 2024

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

Name Status Preview Comments Updated (UTC)
api-reference 🔄 Building (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 7:58pm
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 7:58pm
5 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 7:58pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 7:58pm
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 7:58pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 7:58pm
resources-docs ⬜️ Ignored (Inspect) Visit Preview Dec 11, 2024 7:58pm

Copy link

changeset-bot bot commented Dec 10, 2024

⚠️ No Changeset found

Latest commit: 24fb6e0

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

@fPolic fPolic force-pushed the feat/calculate-so-price-endpoint branch from 2fbd99d to 5d36c2c Compare December 11, 2024 08:50
@fPolic fPolic changed the base branch from feat/create-so-calculated-prices to develop December 11, 2024 08:51
/**
* The calculation context needed for the associated fulfillment provider to calculate the price of a shipping option.
*/
context: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

q: is it enough to pass the cart id and the rest of what is needed can be fetched by the provider or should we pass specific customer info, address info etc. (if, for example, a calculated option is used in an RMA flow)

Copy link
Contributor

@olivermrbl olivermrbl Dec 11, 2024

Choose a reason for hiding this comment

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

Think we will need more, such as items to calculate prices on product/inventory item dimensions. To be consistent with other providers, we don't want to delegate the responsibility of fetching data from core modules to the provider (yet). This should be a preliminary step and passed to the provider.

Just looping in @srindom – he might have an idea about what we could start with

Copy link
Contributor

@olivermrbl olivermrbl Dec 11, 2024

Choose a reason for hiding this comment

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

@fPolic to unblock the PR, here's what I think we will definitely need:

  • Items, e.g. package dimensions and weight
  • Shipping address, e.g. distance from origin to destination

We can add these now and expand in the future in case we need more.

@fPolic fPolic marked this pull request as ready for review December 11, 2024 09:40
@fPolic fPolic requested a review from a team as a code owner December 11, 2024 09:40
@@ -53,7 +53,6 @@ export interface IFulfillmentProvider {
*/
calculatePrice(
optionData: Record<string, unknown>,
Copy link
Contributor

@olivermrbl olivermrbl Dec 11, 2024

Choose a reason for hiding this comment

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

thought: think we still need data – I believe the current naming is cause for confusion.

optionData – data that was populated when creating the shipping option, e.g. requires_drop_point.
data – data that is populated when you create the shipping method, e.g. drop_point_id: 1

For requests that are made prior to adding the shipping method to a cart, the data might be empty.

For example:

POST /store/shipping-options/:id/calculate

However, when adding the shipping method to cart and the price is calculated, you might need the data for the calculation.

For example:

POST /store/carts/:id/shipping-methods
{ option_id: "so_1234", data: { drop_point_id: 1 } }

In your implementation of calculatePrice, the calculated price might depend on the drop point ID (maybe a farfetched example):

// pseudo code
calculatePrice() {
  if (drop_point_id) {
    const acceptPackageSizes = await this.fetchDropPointPackageSizes(drop_point_id)

    const price = // one of those package sizes
    return price
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh ok, thanks for clarifying - will revert the changes

packages/core/utils/src/fulfillment/provider.ts Outdated Show resolved Hide resolved
/**
* The calculation context needed for the associated fulfillment provider to calculate the price of a shipping option.
*/
context: {
Copy link
Contributor

@olivermrbl olivermrbl Dec 11, 2024

Choose a reason for hiding this comment

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

Think we will need more, such as items to calculate prices on product/inventory item dimensions. To be consistent with other providers, we don't want to delegate the responsibility of fetching data from core modules to the provider (yet). This should be a preliminary step and passed to the provider.

Just looping in @srindom – he might have an idea about what we could start with

@kodiakhq kodiakhq bot merged commit 472e92e into develop Dec 12, 2024
23 checks passed
jimrarras pushed a commit to jimrarras/medusa that referenced this pull request Jan 28, 2025
…edusajs#10532)

**What**
- endpoint + flow for fetching calculated price for a shipping option

---

CLOSES CMRC-777
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