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

Assign product to sales channel #10884

Closed
stelasido opened this issue Jan 8, 2025 · 3 comments
Closed

Assign product to sales channel #10884

stelasido opened this issue Jan 8, 2025 · 3 comments
Assignees

Comments

@stelasido
Copy link

stelasido commented Jan 8, 2025

What Medusa version and documentation are you using?

  • everything latest

Issue Summary

I am using producTService to create a product and sales channel Service to create a sales channel like:

  const productService: IProductModuleService = container.resolve(
    Modules.PRODUCT
  )

  const channelService = container.resolve(
    Modules.SALES_CHANNEL
  )

    defaultChannel = await channelService.createSalesChannels({is_disabled: false, name: DEFAULT_SALES_CHANNEL_NAME});

    await productService.upsertProducts(productObj);

Now, I have a product and a sales channel, but I don't know how to attact a product to the sales channel. Upser/createProduct UpsertProductDTO extends UpdateProductDTO type has nothing for channels. IProductModuleService has no method for set sales channel like createProductCategories. ISalesChannelModuleService type has no such method for assign a product, too.

Another question is - by default it seems that products without a sales channel aren't public querable, why and how to stop that?

@olivermrbl
Copy link
Contributor

olivermrbl commented Jan 8, 2025

Now, I have a product and a sales channel, but I don't know how to attact a product to the sales channel.

What you're looking for here is a Module Link. You can read about it here.

It will look something along these lines:

const linker = container.resolve(ContainerRegistrationKeys.LINK)

const createdLinks = await linker.create({
  [Modules.PRODUCT]: { product_id: "prod_1234" },
  [Modules.SALES_CHANNEL]: { sales_channel_id: "sc_1234" }
})

Another question is - by default it seems that products without a sales channel aren't public querable, why and how to stop that?

In the Store API, we require products to be associated with a sales channel, as this is an indication from where the purchase of the products was made. If you don't need multiple sales channels in your setup, you can use the default channel. This is also how the default Medusa starter is set up.

@olivermrbl olivermrbl self-assigned this Jan 8, 2025
@stelasido
Copy link
Author

Thanks, it is const linker = container.resolve(ContainerRegistrationKeys.REMOTE_LINK), not LINK.

@saranshisatgit
Copy link

I am unable to get the link loaded inside the workflow using the container.resolve() if I access the container from the framework then it works ? What could be wrong ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants