Pinelab-studio / pinelab-vendure-plugins

Monorepo for different Vendure plugins developed by Pinelab
109 stars 49 forks source link

Assign Products to Channel Script #415

Closed martijnvdbrug closed 5 months ago

martijnvdbrug commented 6 months ago

For both Wholesale and the new Fabrix channel for CG, we'd need to assign products to other channels. To be able to reuse things like this, we should create a publishable package in the plugins repository: "@pinelab/vendure-scripts"

It should expose functions that can be used on Vendure projects. To start, we'd need 2 functions:

  1. assignAllProductsToChannel. A helper function that assigns all products of channel X to channel Y, including:
    • Facets and facetvalues connected to the products
    • Assets connected to the products
    • Anything else we might be missing?
  2. assignProductsToChannel([1,3,4,5,6]) (list of product ids to assing to channel).

Some acceptance requirements:

Example code

I imagine we have something like this.

import { assignAllProductsToChannel } from '@pinelab/vendure-scripts';

// Consumers load their Vendure app here first, before using our script, because we need them to load their .env and connect to their db etc.
await bootstrap();

await assignAllProductsToChannel(ctx, {
   sourceChannelId: 1,
   targetChannelId: 2,
});
dalyathan commented 6 months ago

what about variants @martijnvdbrug ?