fix(medusa, types): fix promotion HTTP types in cart (#11304)

This commit is contained in:
Shahed Nasser
2025-02-05 12:31:24 +02:00
committed by GitHub
parent d348204fe5
commit 9f1a3b2a42
4 changed files with 61 additions and 6 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/types": patch
"@medusajs/medusa": patch
---
fix(medusa, types): fix promotion HTTP types in cart

View File

@@ -1,3 +1,4 @@
import { ApplicationMethodTypeValues } from "../../../promotion"
import { StorePaymentCollection } from "../../payment"
import { StoreProduct, StoreProductVariant } from "../../product"
import { StoreRegion } from "../../region"
@@ -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"> {
@@ -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
}
}

View File

@@ -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[]
}

View File

@@ -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)
@@ -33,7 +29,7 @@ export const POST = async (
}
export const DELETE = async (
req: MedusaRequest<StoreRemoveCartPromotionsType>,
req: MedusaRequest<HttpTypes.StoreCartRemovePromotion>,
res: MedusaResponse<{
cart: HttpTypes.StoreCart
}>