feat(medusa,pricing): Cart pricing context with customer group (#10579)
* fix(carts): Fixes cart modifications not accounting for certain price 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> * chore: update cart workflows to accept new pricing context * chore: add transfer specs * chore: fix specs * chore: modify types + specs * chore: add data migration + dashboard changes * chore: fix update line item workflow * chore: add changeset + unskip spec --------- Co-authored-by: Sergio Campamá <sergiocampama@gmail.com>
This commit is contained in:
@@ -95,9 +95,9 @@ export const PriceListConfigurationForm = ({
|
||||
const rules = { ...priceList.rules } // preserve other rules set on the PL
|
||||
|
||||
if (groupIds.length) {
|
||||
rules["customer_group_id"] = groupIds
|
||||
rules["customer.groups.id"] = groupIds
|
||||
} else {
|
||||
delete rules["customer_group_id"]
|
||||
delete rules["customer.groups.id"]
|
||||
}
|
||||
|
||||
await mutateAsync(
|
||||
|
||||
@@ -12,7 +12,7 @@ export const PriceListConfiguration = () => {
|
||||
|
||||
const { price_list, isPending, isError, error } = usePriceList(id!)
|
||||
|
||||
const customerGroupIds = price_list?.rules.customer_group_id as
|
||||
const customerGroupIds = price_list?.rules?.["customer.groups.id"] as
|
||||
| string[]
|
||||
| undefined
|
||||
|
||||
@@ -37,8 +37,8 @@ export const PriceListConfiguration = () => {
|
||||
const isCustomerGroupsReady = isPending
|
||||
? false
|
||||
: !!customerGroupIds?.length && isCustomerGroupsPending
|
||||
? false
|
||||
: true
|
||||
? false
|
||||
: true
|
||||
|
||||
const ready = !isPending && !!price_list && isCustomerGroupsReady
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ export const PriceListCreateForm = ({
|
||||
const { rules, products } = data
|
||||
|
||||
const rulesPayload = rules?.customer_group_id?.length
|
||||
? { customer_group_id: rules.customer_group_id.map((cg) => cg.id) }
|
||||
? { "customer.groups.id": rules.customer_group_id.map((cg) => cg.id) }
|
||||
: undefined
|
||||
|
||||
const prices = exctractPricesFromProducts(products, regions)
|
||||
@@ -120,10 +120,13 @@ export const PriceListCreateForm = ({
|
||||
) => {
|
||||
form.clearErrors(fields)
|
||||
|
||||
const values = fields.reduce((acc, key) => {
|
||||
acc[key] = form.getValues(key)
|
||||
return acc
|
||||
}, {} as Record<string, unknown>)
|
||||
const values = fields.reduce(
|
||||
(acc, key) => {
|
||||
acc[key] = form.getValues(key)
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, unknown>
|
||||
)
|
||||
|
||||
const validationResult = schema.safeParse(values)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user