@haus-tech/product-import-export-plugin 3.0.12 → 3.0.14

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
@@ -1,6 +1,6 @@
1
1
  /// <reference types="Multer" />
2
2
  import { OnModuleInit } from '@nestjs/common';
3
- import { RequestContext, JobQueueService, SerializedRequestContext, SearchService, LanguageCode } from '@vendure/core';
3
+ import { RequestContext, JobQueueService, SerializedRequestContext, SearchService, LanguageCode, EventBus, CollectionService, ProductService } from '@vendure/core';
4
4
  import { PluginInitOptions, UpdatingStrategy } from '../types';
5
5
  import { ProductImporter } from '../providers/import-providers/product-importer';
6
6
  export declare class ProductImportService implements OnModuleInit {
@@ -8,8 +8,11 @@ export declare class ProductImportService implements OnModuleInit {
8
8
  private jobQueueService;
9
9
  private productImporter;
10
10
  private searchService;
11
+ private collectionService;
12
+ private productService;
13
+ private eventBus;
11
14
  private productImportQueue;
12
- constructor(options: PluginInitOptions, jobQueueService: JobQueueService, productImporter: ProductImporter, searchService: SearchService);
15
+ constructor(options: PluginInitOptions, jobQueueService: JobQueueService, productImporter: ProductImporter, searchService: SearchService, collectionService: CollectionService, productService: ProductService, eventBus: EventBus);
13
16
  onModuleInit(): Promise<void>;
14
17
  processFile(ctx: RequestContext, file: Express.Multer.File, updateProductSlug: boolean, mainLanguage: LanguageCode, updatingStrategy: UpdatingStrategy): Promise<import("@vendure/core/dist/job-queue/subscribable-job").SubscribableJob<{
15
18
  ctx: SerializedRequestContext;
@@ -23,12 +23,18 @@ let ProductImportService = class ProductImportService {
23
23
  jobQueueService;
24
24
  productImporter;
25
25
  searchService;
26
+ collectionService;
27
+ productService;
28
+ eventBus;
26
29
  productImportQueue;
27
- constructor(options, jobQueueService, productImporter, searchService) {
30
+ constructor(options, jobQueueService, productImporter, searchService, collectionService, productService, eventBus) {
28
31
  this.options = options;
29
32
  this.jobQueueService = jobQueueService;
30
33
  this.productImporter = productImporter;
31
34
  this.searchService = searchService;
35
+ this.collectionService = collectionService;
36
+ this.productService = productService;
37
+ this.eventBus = eventBus;
32
38
  }
33
39
  async onModuleInit() {
34
40
  this.productImportQueue = await this.jobQueueService.createQueue({
@@ -49,6 +55,12 @@ let ProductImportService = class ProductImportService {
49
55
  jobResult = result;
50
56
  },
51
57
  complete: async () => {
58
+ // Hack for triggering apply-collection-filters job
59
+ const firstProduct = await this.productService.findAll(ctx, {
60
+ take: 1,
61
+ });
62
+ this.eventBus.publish(new core_1.ProductEvent(ctx, firstProduct.items[0], 'updated'));
63
+ // Reindex the search index
52
64
  await this.searchService.reindex(ctx);
53
65
  resolve((0, lodash_1.omit)(jobResult, 'currentProduct'));
54
66
  },
@@ -79,6 +91,9 @@ ProductImportService = __decorate([
79
91
  __param(0, (0, common_1.Inject)(constants_1.PRODUCT_IMPORT_EXPORT_PLUGIN_OPTIONS)),
80
92
  __metadata("design:paramtypes", [Object, core_1.JobQueueService,
81
93
  product_importer_1.ProductImporter,
82
- core_1.SearchService])
94
+ core_1.SearchService,
95
+ core_1.CollectionService,
96
+ core_1.ProductService,
97
+ core_1.EventBus])
83
98
  ], ProductImportService);
84
99
  exports.ProductImportService = ProductImportService;
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.14",
4
4
  "description": "A Vendure plugin for importing and exporting products using a CSV file",
5
5
  "author": "Haus Tech",
6
6
  "repository": {