Building an E-Commerce Store - Browsing Products Chapter 10
let filter = Array.isArray(query[key])? query[key] : [query[key]];
for(attribute of filter) {
if(key == 'vendor') {
hasProperty.vendor = false;
if(product.vendor.handle == attribute) {
hasProperty.vendor = true;
}
}
}
});
return display;
}
This will update the hasProperty object with whether the vendor matches the selected
filter. We can row replicate the functionality with the tags – remembering that tags on a
product are an object we need to filter.
The dynamic properties constructed by the filters will also need to be checked. This is done
by checking the variant object on each variationProduct, and updating the
hasProperty object if it matches:
filtering(product, query) {
let display = false,
hasProperty = {};
Object.keys(query).forEach(key => {
let filter = Array.isArray(query[key])? query[key] : [query[key]];
for(attribute of filter) {
if(key == 'vendor') {
hasProperty.vendor = false;
if(product.vendor.handle == attribute) {
hasProperty.vendor = true;
}
} else if(key == 'tags') {
hasProperty.tags = false;
product[key].map(key => {
if(key.handle == attribute) {
hasProperty.tags = true;
}