You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.4 KiB
61 lines
1.4 KiB
const grades = [ |
|
"پیش دبستان", |
|
"اول", |
|
"دوم", |
|
"سوم", |
|
"چهارم", |
|
"پنجم", |
|
"ششم", |
|
"هفتم", |
|
"هشتم", |
|
"نهم", |
|
"دهم", |
|
"یازدهم", |
|
"دوازدهم", |
|
]; |
|
class filter { |
|
productsPage = (products, options) => { |
|
const { grade, subject, sort } = options; |
|
|
|
if (grade.length > 0 || subject.length > 0 || sort) { |
|
localStorage.setItem("filter", "ON"); |
|
} |
|
let finalSort; |
|
let byGradeFilter = []; |
|
if (grade.length > 0) { |
|
grade.map((item1) => { |
|
for (let i = 0; i < products.length; i++) { |
|
if (grades[products[i].gradeId] === item1) { |
|
byGradeFilter.push(products[i]); |
|
} |
|
} |
|
}); |
|
} else { |
|
byGradeFilter = products; |
|
} |
|
let bySubjectFilter = []; |
|
if (subject.length > 0) { |
|
subject.map((item1) => { |
|
for (let i = 0; i < byGradeFilter.length; i++) { |
|
if (byGradeFilter[i].name === item1) { |
|
bySubjectFilter.push(byGradeFilter[i]); |
|
} |
|
} |
|
}); |
|
} else { |
|
bySubjectFilter = byGradeFilter; |
|
} |
|
|
|
if (sort === "گران ترین") { |
|
finalSort = bySubjectFilter.sort((item1, item2) => { |
|
return item1.product[0].price - item2.product[0].price; |
|
}); |
|
} else { |
|
finalSort = bySubjectFilter; |
|
} |
|
}; |
|
} |
|
|
|
const _filter = new filter(); |
|
|
|
export default _filter;
|
|
|