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,pricing): Cart pricing context with customer group #10579

Merged
merged 10 commits into from
Dec 17, 2024

Conversation

riqwan
Copy link
Contributor

@riqwan riqwan commented Dec 12, 2024

what:

  • cart workflows are updated to now accept cart context as pricing context
  • pricing module is updated to handle nested rules
  • customer_group_id rule is renamed customer.groups.id in line with cart shape

Thanks to initial contribution from @sergiocampama - #10493

RESOLVES CMRC-745

… lists (#10493)

*What*

* Fixes #10490
* Expands any available customer_id into its customer_group_ids for cart
  updates that add line items.

*Why*

* Cart updates from the storefront were overriding any valid price lists
  that were correctly being shown in the storefront's product pages.

*How*

* Adds a new workflow step that expands an optional customer_id into the
  customer_group_ids it belongs to.
* Uses this step in the addToCartWorkflow and
  updateLineItemInCartWorkflow workflows.

*Testing*
* Using medusa-dev to test on a local backend.
* Adds integration tests for the addToCart and updateLineItemInCart
  workflows.

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
Copy link

vercel bot commented Dec 12, 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 13, 2024 10:15am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Dec 13, 2024 10:15am
api-reference-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 13, 2024 10:15am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Dec 13, 2024 10:15am
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 13, 2024 10:15am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Dec 13, 2024 10:15am
resources-docs ⬜️ Ignored (Inspect) Visit Preview Dec 13, 2024 10:15am

Copy link

changeset-bot bot commented Dec 12, 2024

🦋 Changeset detected

Latest commit: 713955b

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

This PR includes changesets to release 65 packages
Name Type
@medusajs/dashboard Patch
@medusajs/core-flows Patch
@medusajs/pricing Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/medusa Patch
@medusajs/admin-bundler Patch
integration-tests-http Patch
@medusajs/cli Patch
@medusajs/test-utils Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/workflows-sdk Patch
@medusajs/medusa-oas-cli Patch
@medusajs/oas-github-ci Patch
@medusajs/telemetry Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli 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

@docloulou
Copy link
Contributor

Well spotted ;)

@docloulou
Copy link
Contributor

@riqwan same situation here Order add line item WF

@riqwan
Copy link
Contributor Author

riqwan commented Dec 13, 2024

@docloulou thanks, there are 10 different workflows in orders that needs to be updated, but that will come in a different PR. 🤞🏻

@riqwan riqwan changed the title [wip]: Pricing context with customer group feat(medusa,pricing): Cart pricing context with customer group Dec 13, 2024
@riqwan riqwan marked this pull request as ready for review December 13, 2024 10:14
@riqwan riqwan requested a review from a team as a code owner December 13, 2024 10:14
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.

Overall LGTM, just a comment on the attribute change

import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory"
import { refreshCartItemsWorkflow } from "./refresh-cart-items"

const cartFields = cartFieldsForPricingContext.concat(["items.*"])

export const updateLineItemInCartWorkflowId = "update-line-item-in-cart"
/**
* This workflow updates a cart's line item.
*/
export const updateLineItemInCartWorkflow = createWorkflow(
Copy link
Contributor

Choose a reason for hiding this comment

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

note to self: Input type change is a breaking change.

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, the filter utilities are a bit daunting to review, so primarily looked at the tests, and they seem good :)

@@ -0,0 +1,86 @@
import { isDefined } from "./is-defined"

export function filterObjectByKeys(obj, paths) {
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: A description and example here would be nice to have

[key: string]: any
}

export function flattenObjectToKeyValuePairs(obj: NestedObject): NestedObject {
Copy link
Member

Choose a reason for hiding this comment

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

same suggestion as the previous one

keys.forEach((key) => {
const values = arrayObjects
.map((item) => {
if (item && typeof item === "object") {
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: for those type of check would the util isObject be more convenient?


if (values.length > 0) {
const newPath = `${pathStr}.${key}`
if (values.every((v) => typeof v === "object" && !Array.isArray(v))) {
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: should we use isObject?

Copy link
Contributor Author

@riqwan riqwan Dec 17, 2024

Choose a reason for hiding this comment

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

@adrien2p sorry, just saw this. Will open a new PR with these changes to get this PR into the release.

@riqwan riqwan merged commit 6367bcc into develop Dec 17, 2024
23 checks passed
@sergiocampama
Copy link
Contributor

thanks @riqwan! do you know when a new version might get released with this fix?

@riqwan riqwan deleted the feat/customer-group-context branch December 17, 2024 11:08
@riqwan
Copy link
Contributor Author

riqwan commented Dec 17, 2024

@sergiocampama today!

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.

5 participants