|
@@ -6,6 +6,7 @@ import {
|
|
|
DeletionResponse,
|
|
DeletionResponse,
|
|
|
DeletionResult,
|
|
DeletionResult,
|
|
|
MoveCollectionInput,
|
|
MoveCollectionInput,
|
|
|
|
|
+ PreviewCollectionVariantsInput,
|
|
|
UpdateCollectionInput,
|
|
UpdateCollectionInput,
|
|
|
} from '@vendure/common/lib/generated-types';
|
|
} from '@vendure/common/lib/generated-types';
|
|
|
import { pick } from '@vendure/common/lib/pick';
|
|
import { pick } from '@vendure/common/lib/pick';
|
|
@@ -361,6 +362,43 @@ export class CollectionService implements OnModuleInit {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async previewCollectionVariants(
|
|
|
|
|
+ ctx: RequestContext,
|
|
|
|
|
+ input: PreviewCollectionVariantsInput,
|
|
|
|
|
+ options?: ListQueryOptions<ProductVariant>,
|
|
|
|
|
+ relations?: RelationPaths<Collection>,
|
|
|
|
|
+ ): Promise<PaginatedList<ProductVariant>> {
|
|
|
|
|
+ const filters = this.getCollectionFiltersFromInput(input);
|
|
|
|
|
+ const ancestorFilters = await this.getAncestors(input.collectionId).then(ancestors =>
|
|
|
|
|
+ ancestors.reduce(
|
|
|
|
|
+ (_filters, c) => [..._filters, ...(c.filters || [])],
|
|
|
|
|
+ [] as ConfigurableOperation[],
|
|
|
|
|
+ ),
|
|
|
|
|
+ );
|
|
|
|
|
+ const applicableFilters = filters.concat(ancestorFilters);
|
|
|
|
|
+ let qb = this.listQueryBuilder.build(ProductVariant, options, {
|
|
|
|
|
+ relations: relations ?? ['taxCategory'],
|
|
|
|
|
+ channelId: ctx.channelId,
|
|
|
|
|
+ where: { deletedAt: null },
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ entityAlias: 'productVariant',
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const { collectionFilters } = this.configService.catalogOptions;
|
|
|
|
|
+ for (const filterType of collectionFilters) {
|
|
|
|
|
+ const filtersOfType = applicableFilters.filter(f => f.code === filterType.code);
|
|
|
|
|
+ if (filtersOfType.length) {
|
|
|
|
|
+ for (const filter of filtersOfType) {
|
|
|
|
|
+ qb = filterType.apply(qb, filter.args);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return qb.getManyAndCount().then(([items, totalItems]) => ({
|
|
|
|
|
+ items,
|
|
|
|
|
+ totalItems,
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
async create(ctx: RequestContext, input: CreateCollectionInput): Promise<Translated<Collection>> {
|
|
async create(ctx: RequestContext, input: CreateCollectionInput): Promise<Translated<Collection>> {
|
|
|
await this.slugValidator.validateSlugs(ctx, input, CollectionTranslation);
|
|
await this.slugValidator.validateSlugs(ctx, input, CollectionTranslation);
|
|
|
const collection = await this.translatableSaver.create({
|
|
const collection = await this.translatableSaver.create({
|
|
@@ -480,7 +518,7 @@ export class CollectionService implements OnModuleInit {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private getCollectionFiltersFromInput(
|
|
private getCollectionFiltersFromInput(
|
|
|
- input: CreateCollectionInput | UpdateCollectionInput,
|
|
|
|
|
|
|
+ input: CreateCollectionInput | UpdateCollectionInput | PreviewCollectionVariantsInput,
|
|
|
): ConfigurableOperation[] {
|
|
): ConfigurableOperation[] {
|
|
|
const filters: ConfigurableOperation[] = [];
|
|
const filters: ConfigurableOperation[] = [];
|
|
|
if (input.filters) {
|
|
if (input.filters) {
|