@infrab4a/connect-angular 4.5.3-beta.10 → 4.5.3-beta.2
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.
- package/esm2020/services/catalog/catalog.service.mjs +28 -12
- package/fesm2015/infrab4a-connect-angular.mjs +27 -15
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +27 -11
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1736,11 +1736,10 @@ class CatalogService {
|
|
|
1736
1736
|
return this.findCatalogAndSortByMostRevelantByTerm(productsIds, options, limits);
|
|
1737
1737
|
}
|
|
1738
1738
|
if (this.hasCategory(options) && options.sort === 'most-relevant') {
|
|
1739
|
-
const mostRelevant = options.category
|
|
1739
|
+
const { mostRelevant } = options.category;
|
|
1740
1740
|
console.log('mostRelevant', mostRelevant);
|
|
1741
1741
|
const productsIds = await this.productRepository
|
|
1742
1742
|
.find({
|
|
1743
|
-
fields: ['id'],
|
|
1744
1743
|
filters: {
|
|
1745
1744
|
...(await this.buildMainFilter(options)),
|
|
1746
1745
|
},
|
|
@@ -1776,26 +1775,43 @@ class CatalogService {
|
|
|
1776
1775
|
.then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
|
|
1777
1776
|
}
|
|
1778
1777
|
async findCatalogAndSortByMostRevelant(mostRelevants, productIds, options, limits) {
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1778
|
+
const { offset } = limits;
|
|
1779
|
+
if (offset === 0) {
|
|
1780
|
+
limits.limit -= mostRelevants.length;
|
|
1781
|
+
}
|
|
1782
|
+
if (offset > 0) {
|
|
1783
|
+
limits.offset -= mostRelevants.length;
|
|
1784
|
+
}
|
|
1785
|
+
console.log('limits', limits);
|
|
1786
|
+
const mostRelevantProductsIds = [...new Set(...mostRelevants, ...productIds)];
|
|
1782
1787
|
const totalResult = await this.productRepository.findCatalog({
|
|
1788
|
+
fields: ['id', 'stock'],
|
|
1783
1789
|
filters: {
|
|
1784
1790
|
id: { operator: Where.IN, value: mostRelevantProductsIds },
|
|
1791
|
+
...this.buildFilterQuery(options?.filters || {}),
|
|
1785
1792
|
},
|
|
1786
|
-
orderBy: this.buildSortQuery('news'),
|
|
1787
1793
|
options: {
|
|
1788
1794
|
minimal: ['price'],
|
|
1789
1795
|
maximum: ['price'],
|
|
1790
1796
|
distinct: ['brand'],
|
|
1791
1797
|
},
|
|
1792
1798
|
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1793
|
-
const
|
|
1794
|
-
const
|
|
1795
|
-
const
|
|
1796
|
-
const
|
|
1799
|
+
const stockData = totalResult.data.filter((product) => product.stock.quantity > 0);
|
|
1800
|
+
const stockOut = totalResult.data.filter((product) => product.stock.quantity <= 0);
|
|
1801
|
+
const productIdsStock = mostRelevantProductsIds.filter((product) => stockData.some((result) => result.id == product));
|
|
1802
|
+
const productIdsStockOut = mostRelevantProductsIds.filter((product) => stockOut.some((result) => result.id == product));
|
|
1803
|
+
const limitedProductId = productIdsStock
|
|
1804
|
+
.concat(productIdsStockOut)
|
|
1805
|
+
.slice(limits.offset, limits.offset + limits.limit);
|
|
1806
|
+
const orderedId = mostRelevantProductsIds.filter((product) => limitedProductId.includes(product));
|
|
1807
|
+
console.log('orderedId', orderedId);
|
|
1808
|
+
const productResult = await this.productRepository.findCatalog({
|
|
1809
|
+
filters: {
|
|
1810
|
+
id: { operator: Where.IN, value: orderedId },
|
|
1811
|
+
},
|
|
1812
|
+
});
|
|
1797
1813
|
return {
|
|
1798
|
-
data:
|
|
1814
|
+
data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
|
|
1799
1815
|
count: totalResult.count,
|
|
1800
1816
|
maximum: totalResult.maximum,
|
|
1801
1817
|
minimal: totalResult.minimal,
|