From 744243c3d864019ed755046a4160a52f2513725a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Meyer?= Date: Mon, 17 Jul 2023 12:00:48 +0200 Subject: [PATCH] feat(poc): test something --- lib/shopware/api.ts | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/shopware/api.ts b/lib/shopware/api.ts index 377517fe9..46d924035 100644 --- a/lib/shopware/api.ts +++ b/lib/shopware/api.ts @@ -168,20 +168,53 @@ export async function requestSeoUrl( page: number = 1, limit: number = 1 ): Promise { + console.log(handle); try { - const testing = handle.replace('cms/', '').replace('product/', '').replace('search/', ''); - const criteria = { + const FirstCriteria = { + page: page, + limit: limit, + filter: [ + { + type: 'multi', + // @ts-ignore + operator: 'or', + queries: [ + { + type: 'equals', + field: 'seoPathInfo', + value: handle + '/' + }, + { + type: 'equals', + field: 'seoPathInfo', + value: handle + } + ] + } + ] + }; + // @ts-ignore + const firstResult = await apiInstance.invoke('readSeoUrl post /seo-url', FirstCriteria); + if (firstResult.total && firstResult.total > 0) { + return firstResult; + } + + const lastPart = handle.split('/').pop() + ''; + console.log(lastPart); + + const SecondCriteria = { page: page, limit: limit, filter: [ { type: 'contains', field: 'seoPathInfo', - value: testing + value: lastPart } ] }; - return await apiInstance.invoke('readSeoUrl post /seo-url', criteria); + + return await apiInstance.invoke('readSeoUrl post /seo-url', SecondCriteria); } catch (error) { if (error instanceof ApiClientError) { console.error(error);