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

How to create a product? #10221

Open
1 of 2 tasks
stelasido opened this issue Nov 22, 2024 · 1 comment · May be fixed by #10228
Open
1 of 2 tasks

How to create a product? #10221

stelasido opened this issue Nov 22, 2024 · 1 comment · May be fixed by #10228

Comments

@stelasido
Copy link

What Medusa version and documentation are you using?

v2

Preliminary Checks

Issue Summary

Im following the example from here to create a product: https://docs.medusajs.com/resources/commerce-modules/product
I see this:
message: 'Product "Medusa Shirt" has variants with missing options: [Black Shirt]', name: 'Error', stack: 'Error: Product "Medusa Shirt" has variants with missing options: [Black Shirt]\n' +
With the example, there aren't options in product, Ive tried with it and changed like:

    const products = await productService.createProducts([
      {
        title: "Medusahhhhhhhhhhhhhhhhhhhhh Shirt",
        options: [
          {
            title: "Color121", 
            values: ["black1111"], // not from docs
          },
        ],
        variants: [
          {
            title: "Blackttttttttttttttt Shirt", 
            options: [
              {
                value: "black1111", 
              },
            ],
          },
        ],
      },
    ]);

still the same.
And like that:
const products = await productService.createProducts([
  {
    title: "Medusahhhhhhhhhhhhhhhhhhhhh Shirt",
    options: [
      {
        
        title: "Color121", // Define the option title for the product
        values: ["black1111"], // Provide the possible values for the option
      },
    ],
    variants: [
      {
        title: "Color121", // Variant title
        option: 'black1111',
        value: 'black1111',
        options: ["black1111"],
      },
    ],
  },
]);

`error:   Product "Medusahhhhhhhhhhhhhhhhhhhhh Shirt" has variants with missing options: [Color121]`


How can this issue be resolved?

...

Are you interested in working on this issue?

  • I would like to fix this issue
@sradevski
Copy link
Member

sradevski commented Nov 22, 2024

Hey @stelasido the request should look something like this:

service.createProducts({
            title: "product 1",
            status: ProductStatus.PUBLISHED,
            options: [
              {
                title: "opt-title",
                values: ["val-1", "val-2"],
              },
            ],
            variants: [
              {
                id: "variant-1",
                title: "variant 1",
                options: { "opt-title": "val-1" },
              },
            ],
          })

I'll open a PR to update the docs

@sradevski sradevski linked a pull request Nov 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants