How do you publish all products in a category from code?

I am doing an integration and we need to publish all products in certain categories, as “startup migration task”, since you cant publish all products in a category in a easy way from backoffice.
After “go-live” they will manually publish each new product.

Litium version: 6.1.1

Assuming you have a list of all products in the category:

  1. The base product should have a BaseProductToCategoryLink to the category. You need to add the variant system id for each variant you want to publish to the BaseProductToCategoryLink.ActiveVariantSystemIds
  2. Each variant also needs a VariantToWebSiteLink set to the website system id for the website you want to publish to.

You will need to call MakeWriteableClone() on both base products and variants to be able to add the links correctly and then you can update them using BaseProductService.Update() and VariantService.Update()

That is how we do our migration imports and it seems to work ok.

Well, we don’t have links to variant, we have links to products.
And I cant seem to find a “ProductToWebSiteLink”…

So you publish variants to publish a product?

Answer from slack:

Yes. You can never buy a baseproduct only the variant. So regardless of your setting “UseVariantUrl”. You always have to publish the variant