@infrab4a/connect-angular 4.10.0-beta.6 → 4.10.0-beta.8

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.
@@ -1744,6 +1744,7 @@ class CatalogService {
1744
1744
  throw new InvalidArgumentError(`It couldn't filled tags when profile is given`);
1745
1745
  if (this.hasTerm(options) && options.filters?.customOptions)
1746
1746
  throw new InvalidArgumentError(`It couldn't filled customOptions when term is given`);
1747
+ console.log('fetchProducts', options);
1747
1748
  return await this.findCatalog(options, limits).then(({ data, count: total, maximum, minimal, distinct }) => ({
1748
1749
  products: { data: data.map((product) => RoundProductPricesHelper.roundProductPrices(product)), total },
1749
1750
  pages: Math.ceil(total / limits.limit),
@@ -1762,8 +1763,8 @@ class CatalogService {
1762
1763
  }
1763
1764
  async findCatalog(options, limits) {
1764
1765
  if (this.hasTerm(options) && options.sort === 'most-relevant') {
1765
- console.log('findCatalogIdsBySearch', options.term, options.perPage, options.perPage === 9);
1766
- const productsIds = await this.findCatalogIdsBySearch(options.term, options.perPage === 9);
1766
+ // console.log('Step 1')
1767
+ const productsIds = await this.findCatalogIdsBySearch(options.term);
1767
1768
  return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
1768
1769
  }
1769
1770
  if (this.hasCategory(options) && options.sort === 'most-relevant') {
@@ -1838,10 +1839,18 @@ class CatalogService {
1838
1839
  };
1839
1840
  }
1840
1841
  async findCatalogAndSortByMostRevelantByTerm(productIds, options, limits) {
1842
+ // console.log('findCatalogAndSortByMostRevelantByTerm', this.shop, options, limits)
1843
+ // console.log(
1844
+ // 'productIds from search',
1845
+ // productIds.length,
1846
+ // 'preview -> ',
1847
+ // productIds.slice(limits.offset, limits.offset + limits.limit),
1848
+ // )
1841
1849
  const totalResult = await this.productRepository.findCatalog({
1842
- fields: ['id', 'stock'],
1850
+ fields: ['id', 'stock', 'gender'],
1843
1851
  filters: {
1844
1852
  id: { operator: Where.IN, value: productIds },
1853
+ published: { operator: Where.EQUALS, value: true },
1845
1854
  ...this.buildFilterQuery(options?.filters || {}),
1846
1855
  },
1847
1856
  options: {
@@ -1850,19 +1859,50 @@ class CatalogService {
1850
1859
  distinct: ['brand'],
1851
1860
  },
1852
1861
  }, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
1862
+ const productsTotalResult = totalResult.data.slice(limits.offset, limits.offset + limits.limit);
1863
+ // console.log(
1864
+ // 'productsTotalResult',
1865
+ // productsTotalResult.map((p) => {
1866
+ // return {
1867
+ // id: p.id,
1868
+ // stock: p.stock.quantity,
1869
+ // }
1870
+ // }),
1871
+ // )
1872
+ const defaultGender = options?.filters?.gender
1873
+ ? options?.filters?.gender.at(0)
1874
+ : this.shop === Shops.GLAMSHOP
1875
+ ? 'female'
1876
+ : 'male';
1853
1877
  const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1854
1878
  const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1855
- const productIdsStock = productIds.filter((product) => stockData.some((result) => result.id == product));
1856
- const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id == product));
1879
+ const productIdsStockGender = productIds.filter((product) => stockData.some((result) => result.id === product && (result.gender.includes(defaultGender) || result.gender.includes('unisex'))));
1880
+ const productIdsStockNotGender = productIds.filter((product) => stockData.some((result) => result.id === product && !result.gender.includes(defaultGender)));
1881
+ const productIdsStock = productIdsStockGender.concat(productIdsStockNotGender);
1882
+ const productIdsStockOut = productIds.filter((product) => stockOut.some((result) => result.id === product));
1857
1883
  const limitedProductId = productIdsStock
1858
1884
  .concat(productIdsStockOut)
1859
1885
  .slice(limits.offset, limits.offset + limits.limit);
1886
+ // console.log('limitedProductId', limitedProductId)
1860
1887
  const orderedId = productIds.filter((product) => limitedProductId.includes(product));
1861
1888
  const productResult = await this.productRepository.findCatalog({
1862
1889
  filters: {
1863
1890
  id: { operator: Where.IN, value: orderedId },
1864
1891
  },
1865
1892
  });
1893
+ const finalResult = limitedProductId
1894
+ .map((id) => productResult.data.find((product) => product.id === id))
1895
+ .filter(Boolean);
1896
+ // console.log(
1897
+ // 'finalResult',
1898
+ // finalResult.map((p) => {
1899
+ // return {
1900
+ // id: p.id,
1901
+ // name: p.name,
1902
+ // brand: p.brand,
1903
+ // }
1904
+ // }),
1905
+ // )
1866
1906
  return {
1867
1907
  data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1868
1908
  count: totalResult.count,
@@ -1871,17 +1911,24 @@ class CatalogService {
1871
1911
  distinct: totalResult.distinct,
1872
1912
  };
1873
1913
  }
1874
- async findCatalogIdsBySearch(term, preview) {
1914
+ async findCatalogIdsBySearch(term, preview = false) {
1875
1915
  if (this.productsByTerm[term])
1876
1916
  return this.productsByTerm[term];
1877
1917
  return (this.productsByTerm[term] = await this.productSearch
1878
- .search(term, preview ? 9 : 9999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1879
- .then((products) => {
1880
- const withStock = products.filter((_source) => _source.stock > 0);
1881
- const withOutStock = products.filter((_source) => _source.stock <= 0);
1882
- const sorted = [...withStock, ...withOutStock];
1883
- return [...new Set(sorted.map((products) => products.id))];
1884
- }));
1918
+ .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1919
+ .then((products) => [...new Set(products.map((product) => product.id))]));
1920
+ }
1921
+ prepareSearchResult(resultDb, searchIds, options, limits) {
1922
+ const stockData = resultDb.filter((product) => product.stock.quantity > 0);
1923
+ const stockOut = resultDb.filter((product) => product.stock.quantity <= 0);
1924
+ if (options.filters?.gender) {
1925
+ }
1926
+ const productIdsStock = searchIds.filter((product) => stockData.some((result) => result.id === product));
1927
+ const productIdsStockOut = searchIds.filter((product) => stockOut.some((result) => result.id === product));
1928
+ const limitedProductId = productIdsStock
1929
+ .concat(productIdsStockOut)
1930
+ .slice(limits.offset, limits.offset + limits.limit);
1931
+ return limitedProductId;
1885
1932
  }
1886
1933
  }
1887
1934
  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 });
@@ -1973,11 +2020,12 @@ __decorate([
1973
2020
  ], CategoryWithTree.prototype, "children", void 0);
1974
2021
 
1975
2022
  class WishlistService {
1976
- constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productVertexSearch) {
2023
+ constructor(wishlistRepository, shop, productRepository, categoryFilterRepository, categoryRepository, productStockNotificationRepository, productSearch) {
1977
2024
  this.wishlistRepository = wishlistRepository;
1978
2025
  this.shop = shop;
2026
+ this.productSearch = productSearch;
1979
2027
  const categoryStructureAdapter = new NewCategoryStructureAdapter(wishlistRepository);
1980
- this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productVertexSearch);
2028
+ this.catalogService = new CatalogService(productRepository, productStockNotificationRepository, categoryRepository, categoryStructureAdapter, shop, productSearch);
1981
2029
  this.categoryService = new CategoryService(productRepository, categoryRepository, categoryFilterRepository, categoryStructureAdapter, shop);
1982
2030
  }
1983
2031
  getCatalogService() {
@@ -2069,7 +2117,7 @@ class WishlistService {
2069
2117
  return wishlist;
2070
2118
  }
2071
2119
  }
2072
- WishlistService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: 'CategoryRepository' }, { token: 'ProductStockNotificationRepository' }, { token: i1$2.ProductsVertexSearch }], target: i0.ɵɵFactoryTarget.Injectable });
2120
+ WishlistService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: 'CategoryRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'ProductSearch' }], target: i0.ɵɵFactoryTarget.Injectable });
2073
2121
  WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
2074
2122
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
2075
2123
  type: Injectable
@@ -2091,7 +2139,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
2091
2139
  }] }, { type: undefined, decorators: [{
2092
2140
  type: Inject,
2093
2141
  args: ['ProductStockNotificationRepository']
2094
- }] }, { type: i1$2.ProductsVertexSearch }]; } });
2142
+ }] }, { type: undefined, decorators: [{
2143
+ type: Inject,
2144
+ args: ['ProductSearch']
2145
+ }] }]; } });
2095
2146
 
2096
2147
  class CheckoutSubscriptionService {
2097
2148
  constructor(checkoutSubscriptionRepository, dataPersistence, couponService) {