@infrab4a/connect-angular 4.19.0-beta.0 → 4.19.0-beta.10

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.
@@ -1390,6 +1390,30 @@ class CatalogService {
1390
1390
  this.productSearch = productSearch;
1391
1391
  this.productsByTerm = {};
1392
1392
  this.brandsList = {};
1393
+ this.fields = [
1394
+ 'id',
1395
+ 'name',
1396
+ 'slug',
1397
+ 'images',
1398
+ 'miniatures',
1399
+ 'price',
1400
+ 'stock',
1401
+ 'published',
1402
+ 'CEST',
1403
+ 'EAN',
1404
+ 'NCM',
1405
+ 'brand',
1406
+ 'costPrice',
1407
+ 'hasVariants',
1408
+ 'isKit',
1409
+ 'sku',
1410
+ 'rate',
1411
+ 'tags',
1412
+ 'type',
1413
+ 'shoppingCount',
1414
+ 'gender',
1415
+ 'createdAt',
1416
+ ];
1393
1417
  this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
1394
1418
  const filters = {};
1395
1419
  if (clubDiscount?.length)
@@ -1452,7 +1476,7 @@ class CatalogService {
1452
1476
  return '';
1453
1477
  };
1454
1478
  }
1455
- async fetchProducts(options) {
1479
+ async fetchProducts(options, optionsCache) {
1456
1480
  const limits = this.buildLimitQuery(options);
1457
1481
  if (this.hasProfile(options) && options.filters?.customOptions)
1458
1482
  throw new InvalidArgumentError(`It couldn't filled customOptions when profile is given`);
@@ -1460,7 +1484,7 @@ class CatalogService {
1460
1484
  throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1461
1485
  if (this.hasTerm(options) && options.filters?.customOptions)
1462
1486
  throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1463
- return await this.findCatalog(options, limits).then(async ({ data, count: total, maximum, minimal, distinct }) => {
1487
+ return await this.findCatalog(options, limits, optionsCache).then(async ({ data, count: total, maximum, minimal, distinct }) => {
1464
1488
  await this.setBrandsList(options, distinct?.brand);
1465
1489
  return {
1466
1490
  products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
@@ -1479,7 +1503,7 @@ class CatalogService {
1479
1503
  async addCustomerToStockNotification(shop, productId, name, email) {
1480
1504
  return this.productStockNotificationRepository.addCustomerEmail(shop, productId, name, email);
1481
1505
  }
1482
- async findCatalog(options, limits) {
1506
+ async findCatalog(options, limits, optionsCache) {
1483
1507
  if (this.hasTerm(options) && options.sort === 'most-relevant') {
1484
1508
  const productsIds = await this.findCatalogIdsBySearch(options.term);
1485
1509
  return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
@@ -1493,11 +1517,12 @@ class CatalogService {
1493
1517
  ...(await this.buildMainFilter(options)),
1494
1518
  ...this.buildFilterQuery(options?.filters || {}),
1495
1519
  },
1496
- })
1520
+ }, undefined, optionsCache)
1497
1521
  .then((products) => products.data.map((product) => product.id));
1498
- return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits);
1522
+ return this.findCatalogAndSortByMostRevelant(mostRelevant, productsIds, options, limits, optionsCache);
1499
1523
  }
1500
1524
  const repoParams = {
1525
+ fields: this.fields,
1501
1526
  filters: {
1502
1527
  ...(await this.buildMainFilter(options)),
1503
1528
  ...this.buildFilterQuery(options?.filters || {}),
@@ -1513,8 +1538,8 @@ class CatalogService {
1513
1538
  },
1514
1539
  };
1515
1540
  if (['biggest-price', 'lowest-price', 'biggest-discount', 'best-rating'].includes(options.sort))
1516
- return this.productRepository.findCatalog(repoParams);
1517
- return this.productRepository.findCatalog(repoParams, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1541
+ return this.productRepository.findCatalog(repoParams, undefined, optionsCache);
1542
+ return this.productRepository.findCatalog(repoParams, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
1518
1543
  }
1519
1544
  async buildMainFilter({ category, profile, term, }) {
1520
1545
  if (category)
@@ -1526,10 +1551,11 @@ class CatalogService {
1526
1551
  .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1527
1552
  .then((data) => ({ id: { operator: Where.IN, value: data.map((_source) => _source.id) } }));
1528
1553
  }
1529
- async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
1554
+ async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits, optionsCache) {
1530
1555
  const brandsList = this.brandsList[this.buildIndexBrands(options)];
1531
1556
  const mostRelevantProductsIds = [...new Set(mostRelevants.concat(productIds))];
1532
1557
  const totalResult = await this.productRepository.findCatalog({
1558
+ fields: this.fields,
1533
1559
  filters: {
1534
1560
  id: { operator: Where.IN, value: mostRelevantProductsIds },
1535
1561
  ...this.buildFilterQuery(options?.filters || {}),
@@ -1540,7 +1566,7 @@ class CatalogService {
1540
1566
  maximum: ['price'],
1541
1567
  ...(!brandsList && isEmpty(options.filters?.brands) ? { distinct: ['brand'] } : {}),
1542
1568
  },
1543
- }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1569
+ }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
1544
1570
  const mostRelevantWithouyStock = totalResult.data.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
1545
1571
  const firstProducts = totalResult.data
1546
1572
  .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
@@ -1596,6 +1622,7 @@ class CatalogService {
1596
1622
  filters: {
1597
1623
  id: { operator: Where.IN, value: orderedId },
1598
1624
  },
1625
+ fields: this.fields,
1599
1626
  });
1600
1627
  await this.setBrandsList(options, totalResult.distinct?.brand);
1601
1628
  return {
@@ -1678,20 +1705,20 @@ class CategoryService {
1678
1705
  this.categoryStructureAdapter = categoryStructureAdapter;
1679
1706
  this.shop = shop;
1680
1707
  }
1681
- async fetchBrands(category, options) {
1708
+ async fetchBrands(category, options, optionsCache) {
1682
1709
  const brands = await this.productRepository
1683
1710
  .findCatalog({
1684
1711
  filters: await this.categoryStructureAdapter.buildProductFilterByCategory(category),
1685
1712
  fields: ['brand'],
1686
- }, options?.mainGender ? options?.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female')
1713
+ }, options?.mainGender ? options?.mainGender : this.shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache)
1687
1714
  .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
1688
1715
  return this.categoryRepository
1689
- .find({ filters: { brandCategory: true, shop: options?.shop || this.shop }, orderBy: { name: 'asc' } })
1716
+ .find({ filters: { brandCategory: true, shop: options?.shop || this.shop }, orderBy: { name: 'asc' } }, optionsCache)
1690
1717
  .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1691
1718
  }
1692
- async fetchFilterOptions(category) {
1719
+ async fetchFilterOptions(category, optionsCache) {
1693
1720
  return await this.categoryFilterRepository
1694
- .find({ filters: { categoryId: +category.id } })
1721
+ .find({ filters: { categoryId: +category.id } }, optionsCache)
1695
1722
  .then(({ data }) => data.map((categoryFilter) => categoryFilter.filter));
1696
1723
  }
1697
1724
  }