Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(client): basic search of products #465 #484

Merged
merged 9 commits into from
Mar 13, 2020
4 changes: 2 additions & 2 deletions packages/composables/__tests__/useCms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("Shopware composables", () => {
await search();
expect(page.value).toEqual(null);
expect(error.value).toBeTruthy();
expect(error.value).toStrictEqual({"message": "Something went wrong..."});
expect(error.value).toStrictEqual({ message: "Something went wrong..." });
});

it("should performs search request with no or empty configuration for SearchCriteria", async () => {
Expand All @@ -64,7 +64,7 @@ describe("Shopware composables", () => {
await search("", { configuration: { associations: [] } });
expect(page.value).toEqual(null);
expect(error.value).toBeTruthy();
expect(error.value).toStrictEqual({"message": "Something went wrong..."});
expect(error.value).toStrictEqual({ message: "Something went wrong..." });
});

it("should return activeCategoryId if it's included within the page object", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ describe("SearchConverter - convertSearchCriteria", () => {
});
});
});
describe("term", () => {
it("should add a term key and proper value", () => {
const result = convertSearchCriteria({
term: "fulltext"
} as any);
expect(result.term).toEqual("fulltext");
});
it("should not add a term key if provided term is null", () => {
const result = convertSearchCriteria({
term: null
} as any);
expect(result).not.toHaveProperty("term");
});
});
describe("configuration", () => {
describe("displayParents", () => {
it("should not return displayGroup grouped parameter and appropriate filter when displayParents switch is on", () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/shopware-6-client/src/helpers/searchConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ShopwareParams {
page?: number;
limit?: number;
sort?: string;
term?: string;
filter?: (
| NotFilter
| MultiFilter
Expand All @@ -37,7 +38,7 @@ export const convertSearchCriteria = (
let params: ShopwareParams = {};

if (!searchCriteria) return params;
const { filters, sort, pagination, configuration } = searchCriteria;
const { filters, sort, pagination, configuration, term } = searchCriteria;

if (pagination) {
const { limit, page } = pagination;
Expand Down Expand Up @@ -66,6 +67,11 @@ export const convertSearchCriteria = (
params.grouping = configuration.grouping;
}

// fulltext query (works for every entity so can be global)
if (term) {
params.term = term;
}

// add extra grouping option and additional filter to prevent displaying redundand products.
if (!configuration || (configuration && !configuration.displayParents)) {
if (!Array.isArray(params.filter)) {
Expand Down