Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(medusa): Include Product Collections in Seed command #5510

Merged
merged 6 commits into from
Nov 10, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
olivermrbl marked this conversation as resolved.
Show resolved Hide resolved
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
Loading