@infrab4a/connect-angular 4.10.0-beta.7 → 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,6 +1763,7 @@ class CatalogService {
1762
1763
  }
1763
1764
  async findCatalog(options, limits) {
1764
1765
  if (this.hasTerm(options) && options.sort === 'most-relevant') {
1766
+ // console.log('Step 1')
1765
1767
  const productsIds = await this.findCatalogIdsBySearch(options.term);
1766
1768
  return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
1767
1769
  }
@@ -1837,10 +1839,18 @@ class CatalogService {
1837
1839
  };
1838
1840
  }
1839
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
+ // )
1840
1849
  const totalResult = await this.productRepository.findCatalog({
1841
- fields: ['id', 'stock'],
1850
+ fields: ['id', 'stock', 'gender'],
1842
1851
  filters: {
1843
1852
  id: { operator: Where.IN, value: productIds },
1853
+ published: { operator: Where.EQUALS, value: true },
1844
1854
  ...this.buildFilterQuery(options?.filters || {}),
1845
1855
  },
1846
1856
  options: {
@@ -1849,19 +1859,50 @@ class CatalogService {
1849
1859
  distinct: ['brand'],
1850
1860
  },
1851
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';
1852
1877
  const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
1853
1878
  const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
1854
- const productIdsStock = productIds.filter((product) => stockData.some((result) => result.id == product));
1855
- 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));
1856
1883
  const limitedProductId = productIdsStock
1857
1884
  .concat(productIdsStockOut)
1858
1885
  .slice(limits.offset, limits.offset + limits.limit);
1886
+ // console.log('limitedProductId', limitedProductId)
1859
1887
  const orderedId = productIds.filter((product) => limitedProductId.includes(product));
1860
1888
  const productResult = await this.productRepository.findCatalog({
1861
1889
  filters: {
1862
1890
  id: { operator: Where.IN, value: orderedId },
1863
1891
  },
1864
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
+ // )
1865
1906
  return {
1866
1907
  data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
1867
1908
  count: totalResult.count,
@@ -1875,12 +1916,19 @@ class CatalogService {
1875
1916
  return this.productsByTerm[term];
1876
1917
  return (this.productsByTerm[term] = await this.productSearch
1877
1918
  .search(term, 999, this.shop == Shops.GLAMSHOP ? 'female' : 'male')
1878
- .then((products) => {
1879
- const withStock = products.filter((_source) => _source.stock > 0);
1880
- const withOutStock = products.filter((_source) => _source.stock <= 0);
1881
- const sorted = [...withStock, ...withOutStock];
1882
- return [...new Set(sorted.map((products) => products.id))];
1883
- }));
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;
1884
1932
  }
1885
1933
  }
1886
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 });