Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

2.1 KB
Raw Blame
import { model } from "@medusajs/framework/utils"

import OfferCondition from "./offer-condition"

const Offer = model
  .define("Offer", {
    id: model.id({ prefix: "offer" }).primaryKey(),
    seller_id: model.text(),
    variant_id: model.text(),
    product_id: model.text(),
    shipping_profile_id: model.text(),
    sku: model.text().searchable(),
    ean: model.text().searchable().nullable(),
    upc: model.text().searchable().nullable(),
    manage_inventory: model.boolean().default(true),
    allow_backorder: model.boolean().default(false),
    leadtime_to_ship: model.number().nullable(),
    created_by: model.text(),
    variant_count: model.number().computed(),
    metadata: model.json().nullable(),
    condition: model
      .belongsTo(() => OfferCondition, { mappedBy: "offers" })
      .nullable(),
  })
  .indexes([
    {
      name: "IDX_offer_seller_sku_unique",
      on: ["seller_id", "sku"],
      unique: true,
      where: "deleted_at IS NULL",
    },
    {
      name: "IDX_offer_variant_id",
      on: ["variant_id"],
      where: "deleted_at IS NULL",
    },
    {
      name: "IDX_offer_product_id",
      on: ["product_id"],
      where: "deleted_at IS NULL",
    },
    {
      name: "IDX_offer_seller_id",
      on: ["seller_id"],
      where: "deleted_at IS NULL",
    },
    {
      name: "IDX_offer_shipping_profile_id",
      on: ["shipping_profile_id"],
      where: "deleted_at IS NULL",
    },
    {
      name: "IDX_offer_ean",
      on: ["ean"],
      where: "deleted_at IS NULL AND ean IS NOT NULL",
    },
    {
      name: "IDX_offer_condition_id",
      on: ["condition_id"],
      where: "deleted_at IS NULL AND condition_id IS NOT NULL",
    },
    {
      name: "IDX_offer_upc",
      on: ["upc"],
      where: "deleted_at IS NULL AND upc IS NOT NULL",
    },
    {
      name: "IDX_offer_seller_id_created_at",
      on: ["seller_id", "created_at"],
      where: "deleted_at IS NULL",
    },
    {
      name: "IDX_offer_product_id_seller_id_created_at",
      on: ["product_id", "seller_id", "created_at"],
      where: "deleted_at IS NULL",
    },
  ])

export default Offer