@haus-tech/product-import-export-plugin 3.0.4 → 3.0.5
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.
- package/package.json +1 -1
- package/dist/api/plugin.controller.d.ts +0 -8
- package/dist/api/plugin.controller.js +0 -49
- package/dist/api/product-export.controller.d.ts +0 -14
- package/dist/api/product-export.controller.js +0 -117
- package/dist/api/product-import.controller.d.ts +0 -11
- package/dist/api/product-import.controller.js +0 -63
- package/dist/constants.d.ts +0 -2
- package/dist/constants.js +0 -5
- package/dist/helpers/generate-asset-hash.d.ts +0 -2
- package/dist/helpers/generate-asset-hash.js +0 -15
- package/dist/helpers/normalize-string.d.ts +0 -1
- package/dist/helpers/normalize-string.js +0 -16
- package/dist/helpers/remove-update-at-fields.d.ts +0 -5
- package/dist/helpers/remove-update-at-fields.js +0 -19
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -17
- package/dist/product-import-export.plugin.d.ts +0 -13
- package/dist/product-import-export.plugin.js +0 -153
- package/dist/providers/import-providers/asset-importer.d.ts +0 -31
- package/dist/providers/import-providers/asset-importer.js +0 -158
- package/dist/providers/import-providers/import-parser.d.ts +0 -137
- package/dist/providers/import-providers/import-parser.js +0 -600
- package/dist/providers/import-providers/product-importer.d.ts +0 -48
- package/dist/providers/import-providers/product-importer.js +0 -753
- package/dist/services/extended-fast-importer.service.d.ts +0 -44
- package/dist/services/extended-fast-importer.service.js +0 -462
- package/dist/services/product-export.service.d.ts +0 -23
- package/dist/services/product-export.service.js +0 -344
- package/dist/services/product-import.service.d.ts +0 -22
- package/dist/services/product-import.service.js +0 -84
- package/dist/types.d.ts +0 -41
- package/dist/types.js +0 -2
- package/dist/ui/components/export-dialog.component.d.ts +0 -43
- package/dist/ui/components/export-dialog.component.html +0 -78
- package/dist/ui/components/export-dialog.component.js +0 -108
- package/dist/ui/components/export-dialog.component.ts +0 -142
- package/dist/ui/components/product-import.component.d.ts +0 -57
- package/dist/ui/components/product-import.component.html +0 -123
- package/dist/ui/components/product-import.component.js +0 -413
- package/dist/ui/components/product-import.component.ts +0 -550
- package/dist/ui/product-export.service.d.ts +0 -14
- package/dist/ui/product-export.service.js +0 -107
- package/dist/ui/product-export.service.ts +0 -107
- package/dist/ui/providers.d.ts +0 -2
- package/dist/ui/providers.js +0 -49
- package/dist/ui/providers.ts +0 -57
- package/dist/ui/routes.d.ts +0 -31
- package/dist/ui/routes.js +0 -12
- package/dist/ui/routes.ts +0 -11
- package/dist/ui/translations/en.json +0 -52
- package/dist/ui/translations/sv.json +0 -52
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,462 +0,0 @@
|
|
|
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
|
-
});
|
|
147
|
-
return group.id;
|
|
148
|
-
}
|
|
149
|
-
async createProductOptionGroup(input) {
|
|
150
|
-
this.ensureInitialized();
|
|
151
|
-
const groupExists = await this.connection
|
|
152
|
-
.getRepository(this.importCtx, core_1.ProductOptionGroup)
|
|
153
|
-
.findOne({
|
|
154
|
-
where: { code: input.code },
|
|
155
|
-
});
|
|
156
|
-
if (groupExists) {
|
|
157
|
-
await this.translatableSaver.update({
|
|
158
|
-
ctx: this.importCtx,
|
|
159
|
-
input: { ...(0, lodash_1.omit)(input, 'options'), id: groupExists.id },
|
|
160
|
-
entityType: core_1.ProductOptionGroup,
|
|
161
|
-
translationType: core_1.ProductOptionGroupTranslation,
|
|
162
|
-
});
|
|
163
|
-
return groupExists.id;
|
|
164
|
-
}
|
|
165
|
-
const group = await this.translatableSaver.create({
|
|
166
|
-
ctx: this.importCtx,
|
|
167
|
-
input,
|
|
168
|
-
entityType: core_1.ProductOptionGroup,
|
|
169
|
-
translationType: core_1.ProductOptionGroupTranslation,
|
|
170
|
-
});
|
|
171
|
-
return group.id;
|
|
172
|
-
}
|
|
173
|
-
async createProductOption(input) {
|
|
174
|
-
this.ensureInitialized();
|
|
175
|
-
const optionsExist = await this.connection
|
|
176
|
-
.getRepository(this.importCtx, core_1.ProductOption)
|
|
177
|
-
.findOne({
|
|
178
|
-
where: { code: input.code, groupId: input.productOptionGroupId },
|
|
179
|
-
});
|
|
180
|
-
if (optionsExist) {
|
|
181
|
-
const updatedOption = await this.translatableSaver.update({
|
|
182
|
-
ctx: this.importCtx,
|
|
183
|
-
input: { ...input, id: optionsExist.id },
|
|
184
|
-
entityType: core_1.ProductOption,
|
|
185
|
-
translationType: core_1.ProductOptionTranslation,
|
|
186
|
-
beforeSave: (po) => (po.group = { id: input.productOptionGroupId }),
|
|
187
|
-
});
|
|
188
|
-
return updatedOption.id;
|
|
189
|
-
}
|
|
190
|
-
const option = await this.translatableSaver.create({
|
|
191
|
-
ctx: this.importCtx,
|
|
192
|
-
input,
|
|
193
|
-
entityType: core_1.ProductOption,
|
|
194
|
-
translationType: core_1.ProductOptionTranslation,
|
|
195
|
-
beforeSave: (po) => (po.group = { id: input.productOptionGroupId }),
|
|
196
|
-
});
|
|
197
|
-
return option.id;
|
|
198
|
-
}
|
|
199
|
-
async addOptionGroupToProduct(productId, optionGroupId) {
|
|
200
|
-
this.ensureInitialized();
|
|
201
|
-
await this.connection
|
|
202
|
-
.getRepository(this.importCtx, core_1.Product)
|
|
203
|
-
.createQueryBuilder()
|
|
204
|
-
.relation('optionGroups')
|
|
205
|
-
.of(productId)
|
|
206
|
-
.add(optionGroupId);
|
|
207
|
-
}
|
|
208
|
-
async createFacet(input) {
|
|
209
|
-
this.ensureInitialized();
|
|
210
|
-
const facetExists = await this.connection.getRepository(this.importCtx, core_1.Facet).findOne({
|
|
211
|
-
where: { code: input.code },
|
|
212
|
-
relations: ['channels', 'translations'],
|
|
213
|
-
});
|
|
214
|
-
if (facetExists) {
|
|
215
|
-
const facet = await this.translatableSaver.update({
|
|
216
|
-
ctx: this.importCtx,
|
|
217
|
-
input: { ...input, id: facetExists.id },
|
|
218
|
-
entityType: core_1.Facet,
|
|
219
|
-
translationType: core_1.FacetTranslation,
|
|
220
|
-
beforeSave: async (facet) => {
|
|
221
|
-
await this.entityHydrator.hydrate(this.importCtx, facet, { relations: ['channels'] });
|
|
222
|
-
facet.channels = (0, unique_1.unique)([...facet.channels, this.defaultChannel, this.importCtx.channel], 'id');
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
|
-
return facet.id;
|
|
226
|
-
}
|
|
227
|
-
const facet = await this.translatableSaver.create({
|
|
228
|
-
ctx: this.importCtx,
|
|
229
|
-
input,
|
|
230
|
-
entityType: core_1.Facet,
|
|
231
|
-
translationType: core_1.FacetTranslation,
|
|
232
|
-
beforeSave: async (facet) => {
|
|
233
|
-
facet.channels = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id');
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
return facet.id;
|
|
237
|
-
}
|
|
238
|
-
async createFacetValue(input) {
|
|
239
|
-
this.ensureInitialized();
|
|
240
|
-
const facetValueExists = await this.connection
|
|
241
|
-
.getRepository(this.importCtx, core_1.FacetValue)
|
|
242
|
-
.findOne({
|
|
243
|
-
where: { code: input.code },
|
|
244
|
-
relations: ['channels', 'translations'],
|
|
245
|
-
});
|
|
246
|
-
if (facetValueExists) {
|
|
247
|
-
const updatedFacetValue = await this.translatableSaver.update({
|
|
248
|
-
ctx: this.importCtx,
|
|
249
|
-
input: { ...input, id: facetValueExists.id },
|
|
250
|
-
entityType: core_1.FacetValue,
|
|
251
|
-
translationType: core_1.FacetValueTranslation,
|
|
252
|
-
beforeSave: async (facetValue) => {
|
|
253
|
-
await this.entityHydrator.hydrate(this.importCtx, facetValue, { relations: ['channels'] });
|
|
254
|
-
facetValue.facet = { id: input.facetId };
|
|
255
|
-
facetValue.channels = (0, unique_1.unique)([...facetValue.channels, this.defaultChannel, this.importCtx.channel], 'id');
|
|
256
|
-
},
|
|
257
|
-
});
|
|
258
|
-
return updatedFacetValue.id;
|
|
259
|
-
}
|
|
260
|
-
const facetValue = await this.translatableSaver.create({
|
|
261
|
-
ctx: this.importCtx,
|
|
262
|
-
input,
|
|
263
|
-
entityType: core_1.FacetValue,
|
|
264
|
-
translationType: core_1.FacetValueTranslation,
|
|
265
|
-
beforeSave: async (facetValue) => {
|
|
266
|
-
facetValue.facet = { id: input.facetId };
|
|
267
|
-
facetValue.channels = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id');
|
|
268
|
-
},
|
|
269
|
-
});
|
|
270
|
-
return facetValue.id;
|
|
271
|
-
}
|
|
272
|
-
async addFacetValueToProduct(productId, facetValueId) {
|
|
273
|
-
this.ensureInitialized();
|
|
274
|
-
const existingRelation = await this.connection
|
|
275
|
-
.getRepository(this.importCtx, core_1.Product)
|
|
276
|
-
.createQueryBuilder()
|
|
277
|
-
.relation(core_1.Product, 'facetValues')
|
|
278
|
-
.of(productId)
|
|
279
|
-
.loadMany();
|
|
280
|
-
if (!existingRelation.some((relation) => relation.id === facetValueId)) {
|
|
281
|
-
await this.connection
|
|
282
|
-
.getRepository(this.importCtx, core_1.Product)
|
|
283
|
-
.createQueryBuilder()
|
|
284
|
-
.relation(core_1.Product, 'facetValues')
|
|
285
|
-
.of(productId)
|
|
286
|
-
.add(facetValueId);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
async addFacetValueToProductVariant(variantId, facetValueId) {
|
|
290
|
-
this.ensureInitialized();
|
|
291
|
-
const existingRelation = await this.connection
|
|
292
|
-
.getRepository(this.importCtx, core_1.ProductVariant)
|
|
293
|
-
.createQueryBuilder()
|
|
294
|
-
.relation(core_1.ProductVariant, 'facetValues')
|
|
295
|
-
.of(variantId)
|
|
296
|
-
.loadMany();
|
|
297
|
-
if (!existingRelation.some((relation) => relation.id === facetValueId)) {
|
|
298
|
-
await this.connection
|
|
299
|
-
.getRepository(this.importCtx, core_1.ProductVariant)
|
|
300
|
-
.createQueryBuilder()
|
|
301
|
-
.relation(core_1.ProductVariant, 'facetValues')
|
|
302
|
-
.of(variantId)
|
|
303
|
-
.add(facetValueId);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
async updateProductVariant(input) {
|
|
307
|
-
this.ensureInitialized();
|
|
308
|
-
if (!input.optionIds) {
|
|
309
|
-
input.optionIds = [];
|
|
310
|
-
}
|
|
311
|
-
if (input.price == null) {
|
|
312
|
-
input.price = 0;
|
|
313
|
-
}
|
|
314
|
-
const inputWithoutPrice = {
|
|
315
|
-
...input,
|
|
316
|
-
};
|
|
317
|
-
delete inputWithoutPrice.price;
|
|
318
|
-
const updatedVariant = await this.translatableSaver.update({
|
|
319
|
-
ctx: this.importCtx,
|
|
320
|
-
input: inputWithoutPrice,
|
|
321
|
-
entityType: core_1.ProductVariant,
|
|
322
|
-
translationType: core_1.ProductVariantTranslation,
|
|
323
|
-
beforeSave: async (variant) => {
|
|
324
|
-
await this.entityHydrator.hydrate(this.importCtx, variant, { relations: ['channels'] });
|
|
325
|
-
variant.channels = (0, unique_1.unique)([...variant.channels, this.defaultChannel, this.importCtx.channel], 'id');
|
|
326
|
-
const { optionIds } = input;
|
|
327
|
-
if (optionIds && optionIds.length) {
|
|
328
|
-
variant.options = optionIds.map((id) => ({ id }));
|
|
329
|
-
}
|
|
330
|
-
if (input.facetValueIds) {
|
|
331
|
-
variant.facetValues = input.facetValueIds.map((id) => ({ id }));
|
|
332
|
-
}
|
|
333
|
-
variant.product = { id: input.productId };
|
|
334
|
-
variant.taxCategory = { id: input.taxCategoryId };
|
|
335
|
-
if (input.featuredAssetId) {
|
|
336
|
-
variant.featuredAsset = { id: input.featuredAssetId };
|
|
337
|
-
}
|
|
338
|
-
},
|
|
339
|
-
});
|
|
340
|
-
if (input.assetIds) {
|
|
341
|
-
const existingAssets = await this.connection
|
|
342
|
-
.getRepository(this.importCtx, core_1.ProductVariantAsset)
|
|
343
|
-
.find({
|
|
344
|
-
where: { productVariantId: input.id },
|
|
345
|
-
});
|
|
346
|
-
const newAssets = input.assetIds
|
|
347
|
-
.filter((id) => !existingAssets.some((asset) => asset.assetId === id))
|
|
348
|
-
.map((id, i) => new core_1.ProductVariantAsset({
|
|
349
|
-
assetId: id,
|
|
350
|
-
productVariantId: updatedVariant.id,
|
|
351
|
-
position: i,
|
|
352
|
-
}));
|
|
353
|
-
await this.connection
|
|
354
|
-
.getRepository(this.importCtx, core_1.ProductVariantAsset)
|
|
355
|
-
.save(newAssets, { reload: false });
|
|
356
|
-
}
|
|
357
|
-
await this.stockMovementService.adjustProductVariantStock(this.importCtx, updatedVariant.id, input.stockOnHand ?? 0);
|
|
358
|
-
const assignedChannelIds = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id').map((c) => c.id);
|
|
359
|
-
for (const channelId of assignedChannelIds) {
|
|
360
|
-
const allPrices = await this.connection
|
|
361
|
-
.getRepository(this.importCtx, core_1.ProductVariantPrice)
|
|
362
|
-
.find({
|
|
363
|
-
where: {
|
|
364
|
-
variant: { id: updatedVariant.id },
|
|
365
|
-
},
|
|
366
|
-
});
|
|
367
|
-
let existingVariantPrice = allPrices.find((p) => (0, core_1.idsAreEqual)(p.channelId, channelId) &&
|
|
368
|
-
p.currencyCode === this.importCtx.channel.defaultCurrencyCode);
|
|
369
|
-
if (!existingVariantPrice) {
|
|
370
|
-
const variantPrice = new core_1.ProductVariantPrice({
|
|
371
|
-
price: input.price,
|
|
372
|
-
channelId,
|
|
373
|
-
currencyCode: this.importCtx.channel.defaultCurrencyCode,
|
|
374
|
-
});
|
|
375
|
-
variantPrice.variant = updatedVariant;
|
|
376
|
-
await this.connection.rawConnection
|
|
377
|
-
.getRepository(core_1.ProductVariantPrice)
|
|
378
|
-
.save(variantPrice, { reload: false });
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
existingVariantPrice.price = input.price;
|
|
382
|
-
await this.connection.rawConnection
|
|
383
|
-
.getRepository(core_1.ProductVariantPrice)
|
|
384
|
-
.save(existingVariantPrice, { reload: false });
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return updatedVariant.id;
|
|
388
|
-
}
|
|
389
|
-
async createProductVariant(input) {
|
|
390
|
-
this.ensureInitialized();
|
|
391
|
-
if (!input.optionIds) {
|
|
392
|
-
input.optionIds = [];
|
|
393
|
-
}
|
|
394
|
-
if (input.price == null) {
|
|
395
|
-
input.price = 0;
|
|
396
|
-
}
|
|
397
|
-
const inputWithoutPrice = {
|
|
398
|
-
...input,
|
|
399
|
-
};
|
|
400
|
-
delete inputWithoutPrice.price;
|
|
401
|
-
const createdVariant = await this.translatableSaver.create({
|
|
402
|
-
ctx: this.importCtx,
|
|
403
|
-
input: inputWithoutPrice,
|
|
404
|
-
entityType: core_1.ProductVariant,
|
|
405
|
-
translationType: core_1.ProductVariantTranslation,
|
|
406
|
-
beforeSave: async (variant) => {
|
|
407
|
-
variant.channels = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id');
|
|
408
|
-
const { optionIds } = input;
|
|
409
|
-
if (optionIds && optionIds.length) {
|
|
410
|
-
variant.options = optionIds.map((id) => ({ id }));
|
|
411
|
-
}
|
|
412
|
-
if (input.facetValueIds) {
|
|
413
|
-
variant.facetValues = input.facetValueIds.map((id) => ({ id }));
|
|
414
|
-
}
|
|
415
|
-
variant.product = { id: input.productId };
|
|
416
|
-
variant.taxCategory = { id: input.taxCategoryId };
|
|
417
|
-
if (input.featuredAssetId) {
|
|
418
|
-
variant.featuredAsset = { id: input.featuredAssetId };
|
|
419
|
-
}
|
|
420
|
-
},
|
|
421
|
-
});
|
|
422
|
-
if (input.assetIds) {
|
|
423
|
-
const variantAssets = input.assetIds.map((id, i) => new core_1.ProductVariantAsset({
|
|
424
|
-
assetId: id,
|
|
425
|
-
productVariantId: createdVariant.id,
|
|
426
|
-
position: i,
|
|
427
|
-
}));
|
|
428
|
-
await this.connection
|
|
429
|
-
.getRepository(this.importCtx, core_1.ProductVariantAsset)
|
|
430
|
-
.save(variantAssets, { reload: false });
|
|
431
|
-
}
|
|
432
|
-
await this.stockMovementService.adjustProductVariantStock(this.importCtx, createdVariant.id, input.stockOnHand ?? 0);
|
|
433
|
-
const assignedChannelIds = (0, unique_1.unique)([this.defaultChannel, this.importCtx.channel], 'id').map((c) => c.id);
|
|
434
|
-
for (const channelId of assignedChannelIds) {
|
|
435
|
-
const variantPrice = new core_1.ProductVariantPrice({
|
|
436
|
-
price: input.price,
|
|
437
|
-
channelId,
|
|
438
|
-
currencyCode: this.importCtx.channel.defaultCurrencyCode,
|
|
439
|
-
});
|
|
440
|
-
variantPrice.variant = createdVariant;
|
|
441
|
-
await this.connection.rawConnection
|
|
442
|
-
.getRepository(core_1.ProductVariantPrice)
|
|
443
|
-
.save(variantPrice, { reload: false });
|
|
444
|
-
}
|
|
445
|
-
return createdVariant.id;
|
|
446
|
-
}
|
|
447
|
-
ensureInitialized() {
|
|
448
|
-
if (!this.defaultChannel || !this.importCtx) {
|
|
449
|
-
throw new Error("The FastImporterService must be initialized with a call to 'initialize()' before importing data");
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
ExtendedFastImporterService = __decorate([
|
|
454
|
-
(0, common_1.Injectable)(),
|
|
455
|
-
__metadata("design:paramtypes", [core_1.TransactionalConnection,
|
|
456
|
-
core_1.ChannelService,
|
|
457
|
-
core_1.StockMovementService,
|
|
458
|
-
core_1.TranslatableSaver,
|
|
459
|
-
core_1.RequestContextService,
|
|
460
|
-
core_1.EntityHydrator])
|
|
461
|
-
], ExtendedFastImporterService);
|
|
462
|
-
exports.ExtendedFastImporterService = ExtendedFastImporterService;
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|