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

fix(medusa): Shipping profile CRUD #3154

Merged
merged 16 commits into from Feb 6, 2023
Merged

Conversation

kasperkristensen
Copy link
Contributor

@kasperkristensen kasperkristensen commented Feb 1, 2023

What

  • Fixes wrong payload class for POST /admin/shipping-profiles
  • Fixes wrong payload class for POST /admin/shipping-profiles/:id
  • Fixes an issue where updating a shipping profile with products and/or shipping options would fail.
  • Fixes an issue where passing profile_id to ShippingOptionService.update() would not update the shipping profile of the option.

Testing

  • Adds new simpleshippingProfileFactory
  • Adds new integration test suite for shipping profiles operations.

Resolves CORE-1065

@kasperkristensen kasperkristensen requested a review from a team as a code owner February 1, 2023 13:48
@changeset-bot
Copy link

changeset-bot bot commented Feb 1, 2023

🦋 Changeset detected

Latest commit: f719693

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@medusajs/medusa Patch
@medusajs/inventory Patch

Not sure what this means? Click here to learn what changesets are.

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

@kasperkristensen kasperkristensen changed the title fix: Shipping profile CRUD fix(medusa): Shipping profile CRUD Feb 1, 2023
@kasperkristensen kasperkristensen linked an issue Feb 1, 2023 that may be closed by this pull request
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.

Nice work, just a couple of comments 💪

packages/medusa/src/services/shipping-profile.ts Outdated Show resolved Hide resolved
Comment on lines 371 to 373
await productServiceTx.update(pId, {
profile_id: profileId,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

thought(non-blocking): Would it make sense to create a dedicated method to handle bulk updating in the service or repo layer? I imagine this operation can get nasty when adding > 10000 products, which is likely to happen when creating new profiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that would make sense, as the current way does not scale. I will add a method to the ProductService that can run the update in a single query instead. 😄

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest to do like we do when we migrate the other methods to accept a collection. Like in the cart, line items etc. The update method could accept an id or a collection of ids so it is aligned with the rest of the codebase. Otherwise in some places we will have two different methods and other places one method. A method that handle a collection can handle a collection of one item as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adrien2p I think we would need to change up the update product method a bit in order for it to work with more than one product at a time, with regards to how it can be used to update nested relations such as variants.

While it wouldn't be a breaking change as we can keep the endpoint as is for now, we would open up for people to use the update method in a way that would break. We would need to make the update method accept a map of product ids and updates in order for it to work with variants, to make sure the nested updates only apply to the correct product, which would definitely be a breaking change IMO. So I think it's out of scope for this PR.

Nvm just saw that we've removed variants creation/updates from the product method. Still think my point is somewhat valid, in regards to stuff like images and thumbnails as it would overwrite images and thumbnails for all updated products, unless we allowed the users to pass a map, with images they want to keep for each product. But if you think it's a good idea I am open to it @olivermrbl @adrien2p

I've pushed the originally suggested changes for now

packages/medusa/src/services/shipping-profile.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.

LGTM, great work! 💪

@kodiakhq kodiakhq bot merged commit d0adaf5 into develop Feb 6, 2023
@kodiakhq kodiakhq bot deleted the fix/create-shipping-profile branch February 6, 2023 16:57
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.

[CORE-1065] Shipping Profile type is null
3 participants