@infrab4a/connect-angular 4.14.2 → 4.14.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.
@@ -1798,15 +1798,7 @@ class CatalogService {
1798
1798
  if (this.hasTerm(options) && options.filters?.customOptions)
1799
1799
  throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1800
1800
  return await this.findCatalog(options, limits).then(async ({ data, count: total, maximum, minimal, distinct }) => {
1801
- const filterBrands = options.filters?.brands;
1802
- if (isEmpty(distinct?.brand))
1803
- delete options.filters?.brands;
1804
- this.brandsList[this.buildIndexBrands(options)] =
1805
- this.brandsList[this.buildIndexBrands(options)] || distinct?.brand || (await this.fetchBrandsOnly(options));
1806
- options.filters = {
1807
- ...options.filters,
1808
- brands: filterBrands,
1809
- };
1801
+ await this.setBrandsList(options, distinct?.brand);
1810
1802
  return {
1811
1803
  products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1812
1804
  pages: Math.ceil(total / limits.limit),
@@ -1895,8 +1887,7 @@ class CatalogService {
1895
1887
  .concat(mostRelevantWithouyStock);
1896
1888
  const categoryMostRelevants = firstProducts.concat(lastProducts);
1897
1889
  const resultFinal = categoryMostRelevants.slice(limits.offset, limits.offset + limits.limit);
1898
- if (!brandsList && !isEmpty(options.filters?.brands))
1899
- delete options.filters.brands;
1890
+ await this.setBrandsList(options, totalResult.distinct?.brand);
1900
1891
  return {
1901
1892
  data: resultFinal,
1902
1893
  count: totalResult.count,
@@ -1904,7 +1895,7 @@ class CatalogService {
1904
1895
  minimal: totalResult.minimal,
1905
1896
  distinct: {
1906
1897
  ...totalResult.distinct,
1907
- brand: brandsList || totalResult.distinct?.brand || (await this.fetchBrandsOnly(options, productIds)),
1898
+ brand: this.brandsList[this.buildIndexBrands(options)],
1908
1899
  },
1909
1900
  };
1910
1901
  }
@@ -1943,8 +1934,7 @@ class CatalogService {
1943
1934
  id: { operator: Where.IN, value: orderedId },
1944
1935
  },
1945
1936
  });
1946
- if (!brandsList && !isEmpty(options.filters?.brands))
1947
- delete options.filters.brands;
1937
+ await this.setBrandsList(options, totalResult.distinct?.brand);
1948
1938
  return {
1949
1939
  data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1950
1940
  count: totalResult.count,
@@ -1952,7 +1942,7 @@ class CatalogService {
1952
1942
  minimal: totalResult.minimal,
1953
1943
  distinct: {
1954
1944
  ...totalResult.distinct,
1955
- brand: brandsList || totalResult.distinct?.brand || (await this.fetchBrandsOnly(options, productIds)),
1945
+ brand: this.brandsList[this.buildIndexBrands(options)],
1956
1946
  },
1957
1947
  };
1958
1948
  }
@@ -1980,6 +1970,18 @@ class CatalogService {
1980
1970
  return result.distinct.brand;
1981
1971
  });
1982
1972
  }
1973
+ async setBrandsList(options, brands) {
1974
+ const filterBrands = options.filters?.brands;
1975
+ if (isEmpty(brands))
1976
+ delete options.filters?.brands;
1977
+ this.brandsList[this.buildIndexBrands(options)] =
1978
+ this.brandsList[this.buildIndexBrands(options)] || brands || (await this.fetchBrandsOnly(options));
1979
+ this.brandsList[this.buildIndexBrands(options)] = this.brandsList[this.buildIndexBrands(options)].filter(Boolean);
1980
+ options.filters = {
1981
+ ...options.filters,
1982
+ brands: filterBrands,
1983
+ };
1984
+ }
1983
1985
  }
1984
1986
  CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'CategoryRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: 'ProductSearch' }], target: i0.ɵɵFactoryTarget.Injectable });
1985
1987
  CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });