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

Conversation

adamlamaa
Copy link
Contributor

What

Implentation of feature request: Support Seeding Product Collections #5508

Allowing Seeding Product Collections from the standard seed.json file and the medusa seed -f ./data/seed.json command.

Why

Because it is not currently possible to seed Product Collections.

How

By providing product_collections in the seed.json file as below:

{
	"product_collections": [
		{
	        "id": "id_electronics",
	        "title": "Electronics",
	        "handle": "electronics",
	        "metadata": {}
      	},
		{
	        "id": "id_fabrics",
	        "title": "Fabrics",
	        "handle": "fabrics",
	        "metadata": {}
      	}
	]
}

On each product, Product Collections can then be added via collection_id

{
	"products": [
		{
			...
			"collection_id": "id_electronics"
		}
	]
}

Testing

I could not find any automated tests for seeding, so I have tested this manually.

You can test this PR by updating the seed.json to the following:

{
  "store": {
    "currencies": ["dkk"],
    "default_currency_code": "dkk"
  },
  "users": [
    {
      "email": "[email protected]",
      "password": "supersecret"
    }
  ],
  "regions": [
    {
      "id": "region-dk",
      "name": "Denmark",
      "currency_code": "dkk",
      "tax_rate": 25,
      "payment_providers": ["manual"],
      "fulfillment_providers": ["manual"],
      "countries": ["dk"]
    }
  ],
  "shipping_options": [
    {
      "name": "Default Shipping",
      "region_id": "region-dk",
      "provider_id": "manual",
      "data": {
        "id": "manual-fulfillment"
      },
      "price_type": "flat_rate",
      "amount": 0
    }
  ],
  "product_collections": [
    {
      "id": "id_electronics",
      "title": "Electronics",
      "handle": "electronics",
      "metadata": {}
    },
    {
      "id": "id_fabrics",
      "title": "Fabrics",
      "handle": "fabrics",
      "metadata": {}
    }
  ],
  "products": [
    {
      "id": "prod_01",
      "title": "Product 1",
      "handle": "prod_01",
      "is_giftcard": false,
      "status": "published",
      "collection_id": "id_electronics"
    },
    {
      "id": "prod_02",
      "title": "Product 2",
      "handle": "prod_02",
      "is_giftcard": false,
      "status": "published",
      "collection_id": "id_fabrics"
    }
  ]
}

Then run

medusa seed -f ./data/seed.json

Validate that you have the products and product collections imported as expected in your local databse.
image

image

@adamlamaa adamlamaa requested a review from a team as a code owner October 31, 2023 13:16
@changeset-bot
Copy link

changeset-bot bot commented Oct 31, 2023

🦋 Changeset detected

Latest commit: 7174ea5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@medusajs/medusa Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 31, 2023

@adamlamaa is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

# Conflicts:
#	packages/medusa/src/commands/seed.ts
@olivermrbl olivermrbl changed the title Include Product Collections in Seed command feat(medusa): Include Product Collections in Seed command Nov 9, 2023
Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adamlamaa, only a minor change before we merge :)

packages/medusa/src/commands/seed.ts Outdated Show resolved Hide resolved
Copy link

vercel bot commented Nov 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Visit Preview Nov 10, 2023 7:53am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Nov 10, 2023 7:53am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Nov 10, 2023 7:53am

@olivermrbl olivermrbl merged commit 203e1fc into medusajs:develop Nov 10, 2023
15 checks passed
@github-actions github-actions bot mentioned this pull request Nov 10, 2023
@adamlamaa adamlamaa deleted the feat/seed_product_collections branch November 10, 2023 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants