@haus-tech/product-import-export-plugin 3.0.11 → 3.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -350,6 +350,7 @@ let ProductImporter = class ProductImporter {
350
350
  await this.fastImporter.addFacetValueToProduct(createdProductId, facetValueId);
351
351
  }
352
352
  const optionsMap = {};
353
+ await this.fastImporter.removeOptionGroupsFromProduct(createdProductId);
353
354
  for (const [optionGroup, optionGroupIndex] of product.optionGroups.map((group, i) => [group, i])) {
354
355
  const optionGroupMainTranslation = this.getTranslationByCodeOrFirst(optionGroup.translations, ctx.languageCode);
355
356
  const code = (0, normalize_string_1.normalizeString)(`${productMainTranslation.name}-${optionGroupMainTranslation.name}`, '-', optionGroupMainTranslation.languageCode);
@@ -31,6 +31,7 @@ export declare class ExtendedFastImporterService {
31
31
  }): Promise<ID>;
32
32
  createProductOptionGroup(input: CreateProductOptionGroupInput): Promise<ID>;
33
33
  createProductOption(input: CreateProductOptionInput): Promise<ID>;
34
+ removeOptionGroupsFromProduct(productId: ID): Promise<void>;
34
35
  addOptionGroupToProduct(productId: ID, optionGroupId: ID): Promise<void>;
35
36
  createFacet(input: CreateFacetInput): Promise<ID>;
36
37
  createFacetValue(input: CreateFacetValueInput): Promise<ID>;
@@ -211,6 +211,32 @@ let ExtendedFastImporterService = class ExtendedFastImporterService {
211
211
  });
212
212
  return option.id;
213
213
  }
214
+ async removeOptionGroupsFromProduct(productId) {
215
+ this.ensureInitialized();
216
+ const product = await this.connection.getRepository(this.importCtx, core_1.Product).findOne({
217
+ where: { id: productId },
218
+ relations: ['optionGroups', 'optionGroups.options'],
219
+ });
220
+ if (!product) {
221
+ throw new Error(`Product with ID ${productId} not found`);
222
+ }
223
+ if (!product.optionGroups.length) {
224
+ return;
225
+ }
226
+ const promises = product.optionGroups.map((group) => this.connection
227
+ .getRepository(this.importCtx, core_1.ProductOptionGroup)
228
+ .createQueryBuilder()
229
+ .relation(core_1.ProductOptionGroup, 'options')
230
+ .of(group.id)
231
+ .delete());
232
+ await Promise.all(promises);
233
+ await this.connection
234
+ .getRepository(this.importCtx, core_1.Product)
235
+ .createQueryBuilder()
236
+ .relation(core_1.Product, 'optionGroups')
237
+ .of(productId)
238
+ .remove(product.optionGroups.map((o) => o.id));
239
+ }
214
240
  async addOptionGroupToProduct(productId, optionGroupId) {
215
241
  this.ensureInitialized();
216
242
  await this.connection
@@ -10,7 +10,7 @@ export declare class ProductExportService {
10
10
  private configService;
11
11
  constructor(options: PluginInitOptions, productService: ProductService, stockLevelService: StockLevelService, channelService: ChannelService, configService: ConfigService);
12
12
  createExportFile(ctx: RequestContext, selectionIds: ID[], fileName: string, selectedCustomFields: string, exportAssetsAs: 'url' | 'json', selectedExportFields: string, pageSize?: number, concurrency?: number): Promise<string>;
13
- exportProduct(ctx: RequestContext, product: Product, languages: LanguageCode[], filteredCustomFieldNames: string[], exportAssetsAs: 'url' | 'json', csvWriter: CsvWriter<any>, records?: any[]): Promise<void>;
13
+ exportProduct(ctx: RequestContext, product: Product, languages: LanguageCode[], filteredCustomFieldNames: string[], exportAssetsAs: 'url' | 'json', csvWriter: CsvWriter<any>): Promise<void>;
14
14
  private handleAssets;
15
15
  private handleCustomFields;
16
16
  private getStockOnHand;
@@ -110,7 +110,6 @@ let ProductExportService = class ProductExportService {
110
110
  });
111
111
  let currentPage = 1;
112
112
  let hasMore = true;
113
- const records = [];
114
113
  while (hasMore) {
115
114
  const { items, totalItems } = await this.productService.findAll(ctx, {
116
115
  filter: {
@@ -130,13 +129,14 @@ let ProductExportService = class ProductExportService {
130
129
  'variants.options',
131
130
  ]);
132
131
  hasMore = currentPage * pageSize < totalItems;
133
- const exportPromises = items.map((product) => limiter.schedule(async () => this.exportProduct(ctx, product, languages, filteredCustomFieldNames, exportAssetsAs, csvWriter, records)));
132
+ const exportPromises = items.map((product) => limiter.schedule(async () => this.exportProduct(ctx, product, languages, filteredCustomFieldNames, exportAssetsAs, csvWriter)));
134
133
  await Promise.all(exportPromises);
135
134
  currentPage++;
136
135
  }
137
136
  return exportFile;
138
137
  }
139
- async exportProduct(ctx, product, languages, filteredCustomFieldNames, exportAssetsAs, csvWriter, records = []) {
138
+ async exportProduct(ctx, product, languages, filteredCustomFieldNames, exportAssetsAs, csvWriter) {
139
+ const records = [];
140
140
  const { assets = [], facetValues = [], optionGroups = [], variants = [], translations = [], customFields = {}, } = product;
141
141
  const nameTranslations = this.mapTranslations(translations, 'name', languages);
142
142
  const slugTranslations = this.mapTranslations(translations, 'slug', languages);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-tech/product-import-export-plugin",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "description": "A Vendure plugin for importing and exporting products using a CSV file",
5
5
  "author": "Haus Tech",
6
6
  "repository": {