Skip to content

Commit

Permalink
feat(medusa): Include Product Collections in Seed command (#5510)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlamaa authored Nov 10, 2023
1 parent 4ad66c1 commit 203e1fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/light-mirrors-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

feat(medusa): Include Product Collections in Seed command
10 changes: 9 additions & 1 deletion packages/medusa/src/commands/seed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DataSource, DataSourceOptions } from "typeorm"
import {
ProductCategoryService,
ProductCollectionService,
ProductService,
ProductVariantService,
RegionService,
Expand All @@ -11,7 +12,6 @@ import {
UserService,
} from "../services"
import getMigrations, { getModuleSharedResources } from "./utils/get-migrations"

import { IPricingModuleService } from "@medusajs/types"
import express from "express"
import fs from "fs"
Expand Down Expand Up @@ -101,6 +101,9 @@ const seed = async function ({ directory, migrate, seedFile }: SeedOptions) {
const storeService: StoreService = container.resolve("storeService")
const userService: UserService = container.resolve("userService")
const regionService: RegionService = container.resolve("regionService")
const productCollectionService: ProductCollectionService = container.resolve(
"productCollectionService"
)
const productService: ProductService = container.resolve("productService")
const productCategoryService: ProductCategoryService = container.resolve(
"productCategoryService"
Expand Down Expand Up @@ -131,6 +134,7 @@ const seed = async function ({ directory, migrate, seedFile }: SeedOptions) {
const {
store: seededStore,
regions,
product_collections = [],
products,
categories = [],
shipping_options,
Expand Down Expand Up @@ -212,6 +216,10 @@ const seed = async function ({ directory, migrate, seedFile }: SeedOptions) {
await createProductCategory(c)
}

for (const pc of product_collections) {
await productCollectionService.withTransaction(tx).create(pc)
}

for (const p of products) {
const variants = p.variants
delete p.variants
Expand Down

0 comments on commit 203e1fc

Please sign in to comment.