@haus-tech/product-import-export-plugin 3.0.12 → 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-tech/product-import-export-plugin",
3
- "version": "3.0.12",
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": {