feat: show market categories

This commit is contained in:
Vlad Stan 2023-07-13 18:39:07 +03:00
parent 27e55b00b3
commit 79ce34467c
2 changed files with 36 additions and 1 deletions

View file

@ -148,6 +148,19 @@ const market = async () => {
allCartsItemCount() {
return this.shoppingCarts.map(s => s.products).flat().reduce((t, p) => t + p.orderedQuantity, 0)
},
allCategories() {
const categories = this.products.map(p => p.categories).flat().filter(c => !!c)
const countedCategories = categories.reduce((all, c) => {
all[c] = (all[c] || 0) + 1
return all
}, {})
const x = Object.keys(countedCategories)
.map(category => ({ category, count: countedCategories[category] }))
.sort((a,b) => b.count - a.count)
console.log('### x', x)
return x
}
},
async created() {