From 203e1fccb404a7408b53767456eee52ea719356c Mon Sep 17 00:00:00 2001 From: adamlamaa <77894378+adamlamaa@users.noreply.github.com> Date: Fri, 10 Nov 2023 08:55:08 +0100 Subject: [PATCH] feat(medusa): Include Product Collections in Seed command (#5510) --- .changeset/light-mirrors-pull.md | 5 +++++ packages/medusa/src/commands/seed.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changeset/light-mirrors-pull.md diff --git a/.changeset/light-mirrors-pull.md b/.changeset/light-mirrors-pull.md new file mode 100644 index 0000000000000..9d2bb4565bd6d --- /dev/null +++ b/.changeset/light-mirrors-pull.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +feat(medusa): Include Product Collections in Seed command diff --git a/packages/medusa/src/commands/seed.ts b/packages/medusa/src/commands/seed.ts index 6d4809dec4d62..c49dad0368ddb 100644 --- a/packages/medusa/src/commands/seed.ts +++ b/packages/medusa/src/commands/seed.ts @@ -1,6 +1,7 @@ import { DataSource, DataSourceOptions } from "typeorm" import { ProductCategoryService, + ProductCollectionService, ProductService, ProductVariantService, RegionService, @@ -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" @@ -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" @@ -131,6 +134,7 @@ const seed = async function ({ directory, migrate, seedFile }: SeedOptions) { const { store: seededStore, regions, + product_collections = [], products, categories = [], shipping_options, @@ -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