@haus-tech/product-import-export-plugin 3.0.5 → 3.0.6

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.
Files changed (52) hide show
  1. package/dist/api/plugin.controller.d.ts +8 -0
  2. package/dist/api/plugin.controller.js +49 -0
  3. package/dist/api/product-export.controller.d.ts +14 -0
  4. package/dist/api/product-export.controller.js +117 -0
  5. package/dist/api/product-import.controller.d.ts +11 -0
  6. package/dist/api/product-import.controller.js +63 -0
  7. package/dist/constants.d.ts +2 -0
  8. package/dist/constants.js +5 -0
  9. package/dist/helpers/generate-asset-hash.d.ts +2 -0
  10. package/dist/helpers/generate-asset-hash.js +15 -0
  11. package/dist/helpers/normalize-string.d.ts +1 -0
  12. package/dist/helpers/normalize-string.js +16 -0
  13. package/dist/helpers/remove-update-at-fields.d.ts +5 -0
  14. package/dist/helpers/remove-update-at-fields.js +19 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +17 -0
  17. package/dist/product-import-export.plugin.d.ts +13 -0
  18. package/dist/product-import-export.plugin.js +153 -0
  19. package/dist/providers/import-providers/asset-importer.d.ts +31 -0
  20. package/dist/providers/import-providers/asset-importer.js +159 -0
  21. package/dist/providers/import-providers/import-parser.d.ts +137 -0
  22. package/dist/providers/import-providers/import-parser.js +600 -0
  23. package/dist/providers/import-providers/product-importer.d.ts +48 -0
  24. package/dist/providers/import-providers/product-importer.js +754 -0
  25. package/dist/services/extended-fast-importer.service.d.ts +44 -0
  26. package/dist/services/extended-fast-importer.service.js +474 -0
  27. package/dist/services/product-export.service.d.ts +23 -0
  28. package/dist/services/product-export.service.js +344 -0
  29. package/dist/services/product-import.service.d.ts +22 -0
  30. package/dist/services/product-import.service.js +84 -0
  31. package/dist/types.d.ts +41 -0
  32. package/dist/types.js +2 -0
  33. package/dist/ui/components/export-dialog.component.d.ts +43 -0
  34. package/dist/ui/components/export-dialog.component.html +78 -0
  35. package/dist/ui/components/export-dialog.component.js +108 -0
  36. package/dist/ui/components/export-dialog.component.ts +142 -0
  37. package/dist/ui/components/product-import.component.d.ts +57 -0
  38. package/dist/ui/components/product-import.component.html +123 -0
  39. package/dist/ui/components/product-import.component.js +413 -0
  40. package/dist/ui/components/product-import.component.ts +550 -0
  41. package/dist/ui/product-export.service.d.ts +14 -0
  42. package/dist/ui/product-export.service.js +107 -0
  43. package/dist/ui/product-export.service.ts +107 -0
  44. package/dist/ui/providers.d.ts +2 -0
  45. package/dist/ui/providers.js +49 -0
  46. package/dist/ui/providers.ts +57 -0
  47. package/dist/ui/routes.d.ts +31 -0
  48. package/dist/ui/routes.js +12 -0
  49. package/dist/ui/routes.ts +11 -0
  50. package/dist/ui/translations/en.json +52 -0
  51. package/dist/ui/translations/sv.json +52 -0
  52. package/package.json +1 -1
@@ -0,0 +1,44 @@
1
+ import { Channel, ChannelService, EntityHydrator, ID, Product, ProductVariant, RequestContextService, StockMovementService, TransactionalConnection, TranslatableSaver } from '@vendure/core';
2
+ import { CreateFacetInput, CreateFacetValueInput, CreateProductInput, CreateProductOptionGroupInput, CreateProductOptionInput, CreateProductVariantInput } from '@vendure/common/lib/generated-types';
3
+ export declare class ExtendedFastImporterService {
4
+ private connection;
5
+ private channelService;
6
+ private stockMovementService;
7
+ private translatableSaver;
8
+ private requestContextService;
9
+ private entityHydrator;
10
+ private defaultChannel;
11
+ private importCtx;
12
+ /** @internal */
13
+ constructor(connection: TransactionalConnection, channelService: ChannelService, stockMovementService: StockMovementService, translatableSaver: TranslatableSaver, requestContextService: RequestContextService, entityHydrator: EntityHydrator);
14
+ /**
15
+ * @description
16
+ * This should be called prior to any of the import methods, as it establishes the
17
+ * default Channel as well as the context in which the new entities will be created.
18
+ *
19
+ * Passing a `channel` argument means that Products and ProductVariants will be assigned
20
+ * to that Channel.
21
+ */
22
+ initialize(channel?: Channel): Promise<void>;
23
+ updateProduct(id: ID, input: CreateProductInput & {
24
+ id: ID;
25
+ }): Promise<ID>;
26
+ removeAllAssetsFromProduct(product: Product): Promise<void>;
27
+ removeAllAssetsFromVariant(variant: ProductVariant): Promise<void>;
28
+ createProduct(input: CreateProductInput): Promise<ID>;
29
+ updateProductOptionGroup(input: CreateProductOptionGroupInput & {
30
+ id: ID;
31
+ }): Promise<ID>;
32
+ createProductOptionGroup(input: CreateProductOptionGroupInput): Promise<ID>;
33
+ createProductOption(input: CreateProductOptionInput): Promise<ID>;
34
+ addOptionGroupToProduct(productId: ID, optionGroupId: ID): Promise<void>;
35
+ createFacet(input: CreateFacetInput): Promise<ID>;
36
+ createFacetValue(input: CreateFacetValueInput): Promise<ID>;
37
+ addFacetValueToProduct(productId: ID, facetValueId: ID): Promise<void>;
38
+ addFacetValueToProductVariant(variantId: ID, facetValueId: ID): Promise<void>;
39
+ updateProductVariant(input: CreateProductVariantInput & {
40
+ id: ID;
41
+ }): Promise<ID>;
42
+ createProductVariant(input: CreateProductVariantInput): Promise<ID>;
43
+ private ensureInitialized;
44
+ }
@@ -0,0 +1,474 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ExtendedFastImporterService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const core_1 = require("@vendure/core");
15
+ const normalize_string_1 = require("../helpers/normalize-string");
16
+ const unique_1 = require("@vendure/common/lib/unique");
17
+ const lodash_1 = require("lodash");
18
+ let ExtendedFastImporterService = class ExtendedFastImporterService {
19
+ connection;
20
+ channelService;
21
+ stockMovementService;
22
+ translatableSaver;
23
+ requestContextService;
24
+ entityHydrator;
25
+ defaultChannel;
26
+ importCtx;
27
+ /** @internal */
28
+ constructor(connection, channelService, stockMovementService, translatableSaver, requestContextService, entityHydrator) {
29
+ this.connection = connection;
30
+ this.channelService = channelService;
31
+ this.stockMovementService = stockMovementService;
32
+ this.translatableSaver = translatableSaver;
33
+ this.requestContextService = requestContextService;
34
+ this.entityHydrator = entityHydrator;
35
+ }
36
+ /**
37
+ * @description
38
+ * This should be called prior to any of the import methods, as it establishes the
39
+ * default Channel as well as the context in which the new entities will be created.
40
+ *
41
+ * Passing a `channel` argument means that Products and ProductVariants will be assigned
42
+ * to that Channel.
43
+ */
44
+ async initialize(channel) {
45
+ this.importCtx = channel
46
+ ? await this.requestContextService.create({
47
+ apiType: 'admin',
48
+ channelOrToken: channel,
49
+ })
50
+ : core_1.RequestContext.empty();
51
+ this.defaultChannel = await this.channelService.getDefaultChannel(this.importCtx);
52
+ }
53
+ async updateProduct(id, input) {
54
+ this.ensureInitialized();
55
+ input.translations?.map((translation) => {
56
+ translation.slug = (0, normalize_string_1.normalizeString)(translation.slug, '-', translation.languageCode);
57
+ });
58
+ const product = await this.translatableSaver.update({
59
+ ctx: this.importCtx,
60
+ input,
61
+ entityType: core_1.Product,
62
+ translationType: core_1.ProductTranslation,
63
+ beforeSave: async (p) => {
64
+ await this.entityHydrator.hydrate(this.importCtx, p, { relations: ['channels'] });
65
+ p.channels = (0, unique_1.unique)([...p.channels, this.defaultChannel, this.importCtx.channel], 'id');
66
+ if (input.facetValueIds) {
67
+ p.facetValues = input.facetValueIds.map((id) => ({ id }));
68
+ }
69
+ if (input.featuredAssetId) {
70
+ p.featuredAsset = { id: input.featuredAssetId };
71
+ }
72
+ },
73
+ });
74
+ if (input.assetIds) {
75
+ const existingAssets = await this.connection
76
+ .getRepository(this.importCtx, core_1.ProductAsset)
77
+ .find({
78
+ where: { productId: id },
79
+ });
80
+ const newAssets = input.assetIds
81
+ .filter((id) => !existingAssets.some((asset) => asset.assetId === id))
82
+ .map((id, i) => new core_1.ProductAsset({ assetId: id, productId: product.id, position: i }));
83
+ await this.connection
84
+ .getRepository(this.importCtx, core_1.ProductAsset)
85
+ .save(newAssets, { reload: false });
86
+ }
87
+ return product.id;
88
+ }
89
+ async removeAllAssetsFromProduct(product) {
90
+ this.ensureInitialized();
91
+ await this.connection
92
+ .getRepository(this.importCtx, core_1.ProductAsset)
93
+ .delete({ productId: product.id });
94
+ product.featuredAsset = undefined;
95
+ }
96
+ async removeAllAssetsFromVariant(variant) {
97
+ this.ensureInitialized();
98
+ await this.connection
99
+ .getRepository(this.importCtx, core_1.ProductVariantAsset)
100
+ .delete({ productVariantId: variant.id });
101
+ variant.featuredAsset = undefined;
102
+ }
103
+ async createProduct(input) {
104
+ this.ensureInitialized();
105
+ // https://github.com/vendure-ecommerce/vendure/issues/2053
106
+ // normalizes slug without validation for faster performance
107
+ input.translations.map((translation) => {
108
+ translation.slug = (0, normalize_string_1.normalizeString)(translation.slug, '-', translation.languageCode);
109
+ });
110
+ const product = await this.translatableSaver.create({
111
+ ctx: this.importCtx,
112
+ input,
113
+ entityType: core_1.Product,
114
+ translationType: core_1.ProductTranslation,
115
+ beforeSave: async (p) => {
116
+ try {
117
+ p.channels = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id');
118
+ if (input.featuredAssetId) {
119
+ p.featuredAsset = { id: input.featuredAssetId };
120
+ }
121
+ }
122
+ catch (error) {
123
+ console.log(error);
124
+ }
125
+ },
126
+ });
127
+ if (input.assetIds) {
128
+ const productAssets = input.assetIds.map((id, i) => new core_1.ProductAsset({
129
+ assetId: id,
130
+ productId: product.id,
131
+ position: i,
132
+ }));
133
+ await this.connection
134
+ .getRepository(this.importCtx, core_1.ProductAsset)
135
+ .save(productAssets, { reload: false });
136
+ }
137
+ return product.id;
138
+ }
139
+ async updateProductOptionGroup(input) {
140
+ this.ensureInitialized();
141
+ const group = await this.translatableSaver.update({
142
+ ctx: this.importCtx,
143
+ input: { ...(0, lodash_1.omit)(input, 'options') },
144
+ entityType: core_1.ProductOptionGroup,
145
+ translationType: core_1.ProductOptionGroupTranslation,
146
+ beforeSave: (group) => {
147
+ group.deletedAt = null;
148
+ },
149
+ });
150
+ return group.id;
151
+ }
152
+ async createProductOptionGroup(input) {
153
+ this.ensureInitialized();
154
+ const groupExists = await this.connection
155
+ .getRepository(this.importCtx, core_1.ProductOptionGroup)
156
+ .findOne({
157
+ where: { code: input.code },
158
+ });
159
+ if (groupExists) {
160
+ await this.translatableSaver.update({
161
+ ctx: this.importCtx,
162
+ input: { ...(0, lodash_1.omit)(input, 'options'), id: groupExists.id },
163
+ entityType: core_1.ProductOptionGroup,
164
+ translationType: core_1.ProductOptionGroupTranslation,
165
+ beforeSave: (group) => {
166
+ group.deletedAt = null;
167
+ },
168
+ });
169
+ return groupExists.id;
170
+ }
171
+ const group = await this.translatableSaver.create({
172
+ ctx: this.importCtx,
173
+ input,
174
+ entityType: core_1.ProductOptionGroup,
175
+ translationType: core_1.ProductOptionGroupTranslation,
176
+ });
177
+ return group.id;
178
+ }
179
+ async createProductOption(input) {
180
+ this.ensureInitialized();
181
+ const optionsExist = await this.connection
182
+ .getRepository(this.importCtx, core_1.ProductOption)
183
+ .findOne({
184
+ where: { code: input.code, groupId: input.productOptionGroupId },
185
+ });
186
+ if (optionsExist) {
187
+ const updatedOption = await this.translatableSaver.update({
188
+ ctx: this.importCtx,
189
+ input: { ...input, id: optionsExist.id },
190
+ entityType: core_1.ProductOption,
191
+ translationType: core_1.ProductOptionTranslation,
192
+ beforeSave: (po) => {
193
+ po.group = { id: input.productOptionGroupId };
194
+ po.deletedAt = null;
195
+ },
196
+ });
197
+ return updatedOption.id;
198
+ }
199
+ const option = await this.translatableSaver.create({
200
+ ctx: this.importCtx,
201
+ input,
202
+ entityType: core_1.ProductOption,
203
+ translationType: core_1.ProductOptionTranslation,
204
+ beforeSave: (po) => {
205
+ po.group = { id: input.productOptionGroupId };
206
+ po.deletedAt = null;
207
+ },
208
+ });
209
+ return option.id;
210
+ }
211
+ async addOptionGroupToProduct(productId, optionGroupId) {
212
+ this.ensureInitialized();
213
+ await this.connection
214
+ .getRepository(this.importCtx, core_1.Product)
215
+ .createQueryBuilder()
216
+ .relation('optionGroups')
217
+ .of(productId)
218
+ .add(optionGroupId);
219
+ }
220
+ async createFacet(input) {
221
+ this.ensureInitialized();
222
+ const facetExists = await this.connection.getRepository(this.importCtx, core_1.Facet).findOne({
223
+ where: { code: input.code },
224
+ relations: ['channels', 'translations'],
225
+ });
226
+ if (facetExists) {
227
+ const facet = await this.translatableSaver.update({
228
+ ctx: this.importCtx,
229
+ input: { ...input, id: facetExists.id },
230
+ entityType: core_1.Facet,
231
+ translationType: core_1.FacetTranslation,
232
+ beforeSave: async (facet) => {
233
+ await this.entityHydrator.hydrate(this.importCtx, facet, { relations: ['channels'] });
234
+ facet.channels = (0, unique_1.unique)([...facet.channels, this.defaultChannel, this.importCtx.channel], 'id');
235
+ },
236
+ });
237
+ return facet.id;
238
+ }
239
+ const facet = await this.translatableSaver.create({
240
+ ctx: this.importCtx,
241
+ input,
242
+ entityType: core_1.Facet,
243
+ translationType: core_1.FacetTranslation,
244
+ beforeSave: async (facet) => {
245
+ facet.channels = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id');
246
+ },
247
+ });
248
+ return facet.id;
249
+ }
250
+ async createFacetValue(input) {
251
+ this.ensureInitialized();
252
+ const facetValueExists = await this.connection
253
+ .getRepository(this.importCtx, core_1.FacetValue)
254
+ .findOne({
255
+ where: { code: input.code },
256
+ relations: ['channels', 'translations'],
257
+ });
258
+ if (facetValueExists) {
259
+ const updatedFacetValue = await this.translatableSaver.update({
260
+ ctx: this.importCtx,
261
+ input: { ...input, id: facetValueExists.id },
262
+ entityType: core_1.FacetValue,
263
+ translationType: core_1.FacetValueTranslation,
264
+ beforeSave: async (facetValue) => {
265
+ await this.entityHydrator.hydrate(this.importCtx, facetValue, { relations: ['channels'] });
266
+ facetValue.facet = { id: input.facetId };
267
+ facetValue.channels = (0, unique_1.unique)([...facetValue.channels, this.defaultChannel, this.importCtx.channel], 'id');
268
+ },
269
+ });
270
+ return updatedFacetValue.id;
271
+ }
272
+ const facetValue = await this.translatableSaver.create({
273
+ ctx: this.importCtx,
274
+ input,
275
+ entityType: core_1.FacetValue,
276
+ translationType: core_1.FacetValueTranslation,
277
+ beforeSave: async (facetValue) => {
278
+ facetValue.facet = { id: input.facetId };
279
+ facetValue.channels = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id');
280
+ },
281
+ });
282
+ return facetValue.id;
283
+ }
284
+ async addFacetValueToProduct(productId, facetValueId) {
285
+ this.ensureInitialized();
286
+ const existingRelation = await this.connection
287
+ .getRepository(this.importCtx, core_1.Product)
288
+ .createQueryBuilder()
289
+ .relation(core_1.Product, 'facetValues')
290
+ .of(productId)
291
+ .loadMany();
292
+ if (!existingRelation.some((relation) => relation.id === facetValueId)) {
293
+ await this.connection
294
+ .getRepository(this.importCtx, core_1.Product)
295
+ .createQueryBuilder()
296
+ .relation(core_1.Product, 'facetValues')
297
+ .of(productId)
298
+ .add(facetValueId);
299
+ }
300
+ }
301
+ async addFacetValueToProductVariant(variantId, facetValueId) {
302
+ this.ensureInitialized();
303
+ const existingRelation = await this.connection
304
+ .getRepository(this.importCtx, core_1.ProductVariant)
305
+ .createQueryBuilder()
306
+ .relation(core_1.ProductVariant, 'facetValues')
307
+ .of(variantId)
308
+ .loadMany();
309
+ if (!existingRelation.some((relation) => relation.id === facetValueId)) {
310
+ await this.connection
311
+ .getRepository(this.importCtx, core_1.ProductVariant)
312
+ .createQueryBuilder()
313
+ .relation(core_1.ProductVariant, 'facetValues')
314
+ .of(variantId)
315
+ .add(facetValueId);
316
+ }
317
+ }
318
+ async updateProductVariant(input) {
319
+ this.ensureInitialized();
320
+ if (!input.optionIds) {
321
+ input.optionIds = [];
322
+ }
323
+ if (input.price == null) {
324
+ input.price = 0;
325
+ }
326
+ const inputWithoutPrice = {
327
+ ...input,
328
+ };
329
+ delete inputWithoutPrice.price;
330
+ const updatedVariant = await this.translatableSaver.update({
331
+ ctx: this.importCtx,
332
+ input: inputWithoutPrice,
333
+ entityType: core_1.ProductVariant,
334
+ translationType: core_1.ProductVariantTranslation,
335
+ beforeSave: async (variant) => {
336
+ await this.entityHydrator.hydrate(this.importCtx, variant, { relations: ['channels'] });
337
+ variant.channels = (0, unique_1.unique)([...variant.channels, this.defaultChannel, this.importCtx.channel], 'id');
338
+ const { optionIds } = input;
339
+ if (optionIds && optionIds.length) {
340
+ variant.options = optionIds.map((id) => ({ id }));
341
+ }
342
+ if (input.facetValueIds) {
343
+ variant.facetValues = input.facetValueIds.map((id) => ({ id }));
344
+ }
345
+ variant.product = { id: input.productId };
346
+ variant.taxCategory = { id: input.taxCategoryId };
347
+ if (input.featuredAssetId) {
348
+ variant.featuredAsset = { id: input.featuredAssetId };
349
+ }
350
+ },
351
+ });
352
+ if (input.assetIds) {
353
+ const existingAssets = await this.connection
354
+ .getRepository(this.importCtx, core_1.ProductVariantAsset)
355
+ .find({
356
+ where: { productVariantId: input.id },
357
+ });
358
+ const newAssets = input.assetIds
359
+ .filter((id) => !existingAssets.some((asset) => asset.assetId === id))
360
+ .map((id, i) => new core_1.ProductVariantAsset({
361
+ assetId: id,
362
+ productVariantId: updatedVariant.id,
363
+ position: i,
364
+ }));
365
+ await this.connection
366
+ .getRepository(this.importCtx, core_1.ProductVariantAsset)
367
+ .save(newAssets, { reload: false });
368
+ }
369
+ await this.stockMovementService.adjustProductVariantStock(this.importCtx, updatedVariant.id, input.stockOnHand ?? 0);
370
+ const assignedChannelIds = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id').map((c) => c.id);
371
+ for (const channelId of assignedChannelIds) {
372
+ const allPrices = await this.connection
373
+ .getRepository(this.importCtx, core_1.ProductVariantPrice)
374
+ .find({
375
+ where: {
376
+ variant: { id: updatedVariant.id },
377
+ },
378
+ });
379
+ let existingVariantPrice = allPrices.find((p) => (0, core_1.idsAreEqual)(p.channelId, channelId) &&
380
+ p.currencyCode === this.importCtx.channel.defaultCurrencyCode);
381
+ if (!existingVariantPrice) {
382
+ const variantPrice = new core_1.ProductVariantPrice({
383
+ price: input.price,
384
+ channelId,
385
+ currencyCode: this.importCtx.channel.defaultCurrencyCode,
386
+ });
387
+ variantPrice.variant = updatedVariant;
388
+ await this.connection.rawConnection
389
+ .getRepository(core_1.ProductVariantPrice)
390
+ .save(variantPrice, { reload: false });
391
+ }
392
+ else {
393
+ existingVariantPrice.price = input.price;
394
+ await this.connection.rawConnection
395
+ .getRepository(core_1.ProductVariantPrice)
396
+ .save(existingVariantPrice, { reload: false });
397
+ }
398
+ }
399
+ return updatedVariant.id;
400
+ }
401
+ async createProductVariant(input) {
402
+ this.ensureInitialized();
403
+ if (!input.optionIds) {
404
+ input.optionIds = [];
405
+ }
406
+ if (input.price == null) {
407
+ input.price = 0;
408
+ }
409
+ const inputWithoutPrice = {
410
+ ...input,
411
+ };
412
+ delete inputWithoutPrice.price;
413
+ const createdVariant = await this.translatableSaver.create({
414
+ ctx: this.importCtx,
415
+ input: inputWithoutPrice,
416
+ entityType: core_1.ProductVariant,
417
+ translationType: core_1.ProductVariantTranslation,
418
+ beforeSave: async (variant) => {
419
+ variant.channels = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id');
420
+ const { optionIds } = input;
421
+ if (optionIds && optionIds.length) {
422
+ variant.options = optionIds.map((id) => ({ id }));
423
+ }
424
+ if (input.facetValueIds) {
425
+ variant.facetValues = input.facetValueIds.map((id) => ({ id }));
426
+ }
427
+ variant.product = { id: input.productId };
428
+ variant.taxCategory = { id: input.taxCategoryId };
429
+ if (input.featuredAssetId) {
430
+ variant.featuredAsset = { id: input.featuredAssetId };
431
+ }
432
+ },
433
+ });
434
+ if (input.assetIds) {
435
+ const variantAssets = input.assetIds.map((id, i) => new core_1.ProductVariantAsset({
436
+ assetId: id,
437
+ productVariantId: createdVariant.id,
438
+ position: i,
439
+ }));
440
+ await this.connection
441
+ .getRepository(this.importCtx, core_1.ProductVariantAsset)
442
+ .save(variantAssets, { reload: false });
443
+ }
444
+ await this.stockMovementService.adjustProductVariantStock(this.importCtx, createdVariant.id, input.stockOnHand ?? 0);
445
+ const assignedChannelIds = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id').map((c) => c.id);
446
+ for (const channelId of assignedChannelIds) {
447
+ const variantPrice = new core_1.ProductVariantPrice({
448
+ price: input.price,
449
+ channelId,
450
+ currencyCode: this.importCtx.channel.defaultCurrencyCode,
451
+ });
452
+ variantPrice.variant = createdVariant;
453
+ await this.connection.rawConnection
454
+ .getRepository(core_1.ProductVariantPrice)
455
+ .save(variantPrice, { reload: false });
456
+ }
457
+ return createdVariant.id;
458
+ }
459
+ ensureInitialized() {
460
+ if (!this.defaultChannel || !this.importCtx) {
461
+ throw new Error("The FastImporterService must be initialized with a call to 'initialize()' before importing data");
462
+ }
463
+ }
464
+ };
465
+ ExtendedFastImporterService = __decorate([
466
+ (0, common_1.Injectable)(),
467
+ __metadata("design:paramtypes", [core_1.TransactionalConnection,
468
+ core_1.ChannelService,
469
+ core_1.StockMovementService,
470
+ core_1.TranslatableSaver,
471
+ core_1.RequestContextService,
472
+ core_1.EntityHydrator])
473
+ ], ExtendedFastImporterService);
474
+ exports.ExtendedFastImporterService = ExtendedFastImporterService;
@@ -0,0 +1,23 @@
1
+ import { EntityHydrator, ID, ProductService, RequestContext, StockLevelService, ChannelService, ConfigService } from '@vendure/core';
2
+ import { PluginInitOptions } from '../types';
3
+ export type RelationType = 'string' | 'boolean' | 'localeString' | 'text' | 'localeText' | 'int' | 'float' | 'datetime' | 'relation';
4
+ export declare class ProductExportService {
5
+ private options;
6
+ private productService;
7
+ private stockLevelService;
8
+ private entityHydratorService;
9
+ private channelService;
10
+ private configService;
11
+ constructor(options: PluginInitOptions, productService: ProductService, stockLevelService: StockLevelService, entityHydratorService: EntityHydrator, channelService: ChannelService, configService: ConfigService);
12
+ createExportFile(ctx: RequestContext, selectionIds: ID[], fileName: string, selectedCustomFields: string, exportAssetsAs: 'url' | 'json', selectedExportFields: string): Promise<string>;
13
+ private handleAssets;
14
+ private handleCustomFields;
15
+ private getStockOnHand;
16
+ private mapTranslations;
17
+ private mapFacetTranslations;
18
+ getCustomFields(ctx: RequestContext, productIds: string[]): Promise<{
19
+ name: string;
20
+ type: string;
21
+ }[]>;
22
+ getConfig(): Promise<PluginInitOptions>;
23
+ }