Skip to content

Commit

Permalink
fix: use regular expressions to ignore letter cases with color, vendo…
Browse files Browse the repository at this point in the history
…r and size filters
  • Loading branch information
luiscelano committed Mar 26, 2022
1 parent af54d9f commit 566e0c4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utils/applyCatalogItemFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import _ from "lodash";
import SimpleSchema from "simpl-schema";
import ReactionError from "@reactioncommerce/reaction-error";

const ArrayStringToArrayRegExp = (items) => items.map((item) => {
const regex = new RegExp(`${item}`, "i");

return regex;
});

const filters = new SimpleSchema({
catalogBooleanFilters: {
type: Object,
Expand Down Expand Up @@ -107,13 +113,13 @@ export default function applyCatalogItemFilters(context, catalogItemFilters) {

if (catalogItemFilters.colors) {
Object.assign(selector, {
"product.variants.title": { $in: catalogItemFilters.colors }
"product.variants.color": { $in: ArrayStringToArrayRegExp(catalogItemFilters.colors) }
});
}

if (catalogItemFilters.sizes) {
Object.assign(selector, {
"product.variants.options.title": { $in: catalogItemFilters.sizes }
"product.variants.size": { $in: ArrayStringToArrayRegExp(catalogItemFilters.sizes) }
});
}

Expand Down

0 comments on commit 566e0c4

Please sign in to comment.