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:
Philip KorsholmandOliver Windall Juhl authored and GitHub committed 2023-04-20 08:54:26 +02:00
1 parent 7d1a78a84f
commit 2be144ff05
27 files changed
+395 -70

No files matched your search

+18 -6
View File
@@ -1,8 +1,3 @@
import { DbAwareColumn, generateEntityId } from "../utils"
import { MoneyAmount } from "./money-amount"
import { Product } from "./product"
import { ProductOptionValue } from "./product-option-value"
import { SoftDeletableEntity } from "../interfaces"
import {
BeforeInsert,
Column,
@@ -10,10 +5,15 @@ import {
Index,
JoinColumn,
ManyToOne,
OneToMany
OneToMany,
} from "typeorm"
import { DbAwareColumn, generateEntityId } from "../utils"
import { MoneyAmount } from "./money-amount"
import { Product } from "./product"
import { ProductOptionValue } from "./product-option-value"
import { ProductVariantInventoryItem } from "./product-variant-inventory-item"
import { SoftDeletableEntity } from "../interfaces"
@Entity()
export class ProductVariant extends SoftDeletableEntity {
@@ -103,6 +103,8 @@ export class ProductVariant extends SoftDeletableEntity {
@DbAwareColumn({ type: "jsonb", nullable: true })
metadata: Record<string, unknown>
purchasable?: boolean
@BeforeInsert()
private beforeInsert(): void {
this.id = generateEntityId(this.id, "variant")
@@ -264,4 +266,14 @@ export class ProductVariant extends SoftDeletableEntity {
* nullable: true
* type: object
* example: {car: "white"}
* purchasable:
* description: |
* Only used with the inventory modules.
* A boolean value indicating whether the Product Variant is purchasable.
* A variant is purchasable if:
* - inventory is not managed
* - it has no inventory items
* - it is in stock
* - it is backorderable.
* type: boolean
*/