feat(medusa): Add purchasable prop on variants when setting availability (#3811)
* write integration tests * update variant inventory decorator * update types * add changeset * feedback comments * add yaml schemas * different oas approach * pr feedback * update oas --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Oliver Windall Juhl
parent
7d1a78a84f
commit
2be144ff05
@@ -1,14 +1,15 @@
|
||||
import { Product, ProductOption, ProductStatus, ProductType, ShippingProfile, ShippingProfileType, } from "@medusajs/medusa"
|
||||
import { ProductVariantFactoryData, simpleProductVariantFactory, } from "./simple-product-variant-factory"
|
||||
|
||||
import { Connection } from "typeorm"
|
||||
import faker from "faker"
|
||||
import { Product, ProductOption, ProductType, ShippingProfile, ShippingProfileType, } from "@medusajs/medusa"
|
||||
|
||||
import { ProductVariantFactoryData, simpleProductVariantFactory, } from "./simple-product-variant-factory"
|
||||
|
||||
export type ProductFactoryData = {
|
||||
id?: string
|
||||
is_giftcard?: boolean
|
||||
title?: string
|
||||
type?: string
|
||||
status?: ProductStatus
|
||||
options?: { id: string; title: string }[]
|
||||
variants?: ProductVariantFactoryData[]
|
||||
}
|
||||
@@ -45,6 +46,7 @@ export const simpleProductFactory = async (
|
||||
const toSave = manager.create(Product, {
|
||||
id: prodId,
|
||||
type_id: typeId,
|
||||
status: data.status || ProductStatus.DRAFT,
|
||||
title: data.title || faker.commerce.productName(),
|
||||
is_giftcard: data.is_giftcard || false,
|
||||
discountable: !data.is_giftcard,
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import { Connection } from "typeorm"
|
||||
import faker from "faker"
|
||||
import {
|
||||
MoneyAmount,
|
||||
ProductOptionValue,
|
||||
ProductVariant,
|
||||
MoneyAmount,
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
import { Connection } from "typeorm"
|
||||
import faker from "faker"
|
||||
|
||||
export type ProductVariantFactoryData = {
|
||||
product_id: string
|
||||
id?: string
|
||||
is_giftcard?: boolean
|
||||
inventory_quantity?: number
|
||||
title?: string
|
||||
allow_backorder?: boolean
|
||||
manage_inventory?: boolean
|
||||
options?: { option_id: string; value: string }[]
|
||||
prices?: { currency: string; amount: number }[]
|
||||
}
|
||||
@@ -31,6 +34,8 @@ export const simpleProductVariantFactory = async (
|
||||
const toSave = manager.create(ProductVariant, {
|
||||
id,
|
||||
product_id: data.product_id,
|
||||
allow_backorder: data.allow_backorder || false,
|
||||
manage_inventory: typeof data.manage_inventory !== 'undefined' ? data.manage_inventory : true,
|
||||
inventory_quantity:
|
||||
typeof data.inventory_quantity !== "undefined"
|
||||
? data.inventory_quantity
|
||||
|
||||
Reference in New Issue
Block a user