feat(medusa, core-workflows, product): slightly improve create cart workflow (#5725)

This commit is contained in:
Adrien de Peretti
2023-12-07 17:05:23 +01:00
committed by GitHub
parent 946db51a9b
commit 85cda7ce37
14 changed files with 136 additions and 43 deletions
+9 -5
View File
@@ -364,11 +364,15 @@ class CartService extends TransactionBaseService {
).id
}
if (data.customer_id) {
const customer = await this.customerService_
.withTransaction(transactionManager)
.retrieve(data.customer_id)
.catch(() => undefined)
if (data.customer_id || data.customer) {
const customer =
(data.customer ??
(data.customer_id &&
(await this.customerService_
.withTransaction(transactionManager)
.retrieve(data.customer_id)
.catch(() => undefined)))) as Customer
rawCart.customer = customer
rawCart.customer_id = customer?.id
rawCart.email = customer?.email
+2
View File
@@ -8,6 +8,7 @@ import { Cart, CartType } from "../models/cart"
import { IsType } from "../utils/validators/is-type"
import { Region } from "../models"
import { ValidateNested } from "class-validator"
import { CustomerTypes } from "@medusajs/types"
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isCart(object: any): object is Cart {
@@ -60,6 +61,7 @@ export type CartCreateProps = {
shipping_address?: Partial<AddressPayload>
gift_cards?: GiftCard[]
discounts?: Discount[]
customer?: CustomerTypes.CustomerDTO
customer_id?: string
type?: CartType
context?: object