@infrab4a/connect-angular 4.1.4-beta.1 → 4.1.4-beta.3

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.
@@ -1541,11 +1541,6 @@ class CatalogService {
1541
1541
  const limitedProductId = productIds.slice(limits.offset, limits.limit);
1542
1542
  const productResult = await this.productRepository.findCatalog({
1543
1543
  filters: { id: { operator: Where.IN, value: limitedProductId } },
1544
- options: {
1545
- minimal: ['price'],
1546
- maximum: ['price'],
1547
- ...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
1548
- },
1549
1544
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1550
1545
  const totalResult = await this.productRepository.findCatalog({
1551
1546
  fields: ['id'],
@@ -1558,7 +1553,7 @@ class CatalogService {
1558
1553
  },
1559
1554
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1560
1555
  return {
1561
- data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)),
1556
+ data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1562
1557
  count: totalResult.count,
1563
1558
  maximum: totalResult.maximum,
1564
1559
  minimal: totalResult.minimal,
@@ -1567,7 +1562,12 @@ class CatalogService {
1567
1562
  }
1568
1563
  async findCatalogIdsByElasticSearch(term) {
1569
1564
  return (this.productsByTerm[term] ||
1570
- this.productIndex.search(term, 999, this.shop).then((data) => data.hits.map(({ _source }) => _source.id)));
1565
+ this.productIndex.search(term, 999, this.shop).then(({ hits: products }) => {
1566
+ const withStock = products.filter(({ _source }) => _source.stock.quantity > 0);
1567
+ const withOutStock = products.filter(({ _source }) => _source.stock.quantity <= 0);
1568
+ const sorted = [...withStock, ...withOutStock];
1569
+ return [...new Set(sorted.map(({ _source }) => _source.id))];
1570
+ }));
1571
1571
  }
1572
1572
  }
1573
1573
  CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable });