Skip to content

Commit

Permalink
fix(medusa, types): fix promotion HTTP types in cart (medusajs#11304)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser authored Feb 5, 2025
1 parent d348204 commit 9f1a3b2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/friendly-jars-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/types": patch
"@medusajs/medusa": patch
---

fix(medusa, types): fix promotion HTTP types in cart
39 changes: 39 additions & 0 deletions packages/core/types/src/http/cart/store/entities.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApplicationMethodTypeValues } from "../../../promotion"
import { StorePaymentCollection } from "../../payment"
import { StoreProduct, StoreProductVariant } from "../../product"
import { StoreRegion } from "../../region"
Expand Down Expand Up @@ -37,6 +38,10 @@ export interface StoreCart extends Omit<BaseCart, "items"> {
* The cart's region
*/
region?: StoreRegion
/**
* The promotions applied to the cart.
*/
promotions: StoreCartPromotion[]
}
export interface StoreCartLineItem
extends Omit<BaseCartLineItem, "product" | "variant" | "cart"> {
Expand Down Expand Up @@ -80,3 +85,37 @@ export interface StoreCartShippingMethod extends BaseCartShippingMethod {
shipping_method: StoreCartShippingMethod
})[]
}
export interface StoreCartPromotion {
/**
* The promotion's ID.
*/
id: string
/**
* The promotion's code.
*/
code?: string
/**
* Whether the promotion is applied automatically (without the customer needing to enter a code).
*/
is_automatic?: boolean
/**
* How the promotion is applied.
*/
application_method?: {
/**
* The amount to be discounted.
*/
value: string
/**
* The application method's type. If it's `fixed`, the promotion discounts a fixed amount.
* If it's `percentage`, the promotion discounts a percentage.
*/
type: ApplicationMethodTypeValues
/**
* The currency code of the discount.
*
* @example usd
*/
currency_code: string
}
}
14 changes: 14 additions & 0 deletions packages/core/types/src/http/cart/store/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,17 @@ export interface StoreAddAddress {
*/
metadata?: Record<string, unknown> | null
}

export interface StoreCartRemovePromotion {
/**
* The promotion codes to remove from the cart.
*/
promo_codes: string[]
}

export interface StoreCartAddPromotion {
/**
* The promotion codes to add to the cart.
*/
promo_codes: string[]
}
8 changes: 2 additions & 6 deletions packages/medusa/src/api/store/carts/[id]/promotions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import { updateCartPromotionsWorkflow } from "@medusajs/core-flows"
import { PromotionActions } from "@medusajs/framework/utils"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { refetchCart } from "../../helpers"
import {
StoreAddCartPromotionsType,
StoreRemoveCartPromotionsType,
} from "../../validators"
import { HttpTypes } from "@medusajs/framework/types"

export const POST = async (
req: MedusaRequest<StoreAddCartPromotionsType>,
req: MedusaRequest<HttpTypes.StoreCartAddPromotion>,
res: MedusaResponse<HttpTypes.StoreCartResponse>
) => {
const workflow = updateCartPromotionsWorkflow(req.scope)
Expand All @@ -33,7 +29,7 @@ export const POST = async (
}

export const DELETE = async (
req: MedusaRequest<StoreRemoveCartPromotionsType>,
req: MedusaRequest<HttpTypes.StoreCartRemovePromotion>,
res: MedusaResponse<{
cart: HttpTypes.StoreCart
}>
Expand Down

0 comments on commit 9f1a3b2

Please sign in to comment.