diff --git a/api/composables.api.md b/api/composables.api.md index ea1fdac54..4e0ea9cd3 100644 --- a/api/composables.api.md +++ b/api/composables.api.md @@ -23,7 +23,6 @@ import { CustomerUpdateEmailParam } from '@shopware-pwa/shopware-6-client'; import { CustomerUpdatePasswordParam } from '@shopware-pwa/shopware-6-client'; import { CustomerUpdateProfileParam } from '@shopware-pwa/shopware-6-client'; import { EntityError } from '@shopware-pwa/commons/interfaces/models/common/EntityError'; -import { EqualsFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilter'; import { Includes } from '@shopware-pwa/commons/interfaces/search/SearchCriteria'; import { IUseListing as IUseListing_2 } from '@shopware-pwa/composables'; import { LineItem } from '@shopware-pwa/commons/interfaces/models/checkout/cart/line-item/LineItem'; @@ -35,9 +34,7 @@ import { PageResolverProductResult } from '@shopware-pwa/commons/interfaces/mode import { PageResolverResult } from '@shopware-pwa/commons/interfaces/models/content/cms/CmsPage'; import { PaymentMethod } from '@shopware-pwa/commons/interfaces/models/checkout/payment/PaymentMethod'; import { Product } from '@shopware-pwa/commons/interfaces/models/content/product/Product'; -import { ProductListingResult } from '@shopware-pwa/commons/interfaces/response/ProductListingResult'; import { PropertyGroup } from '@shopware-pwa/commons/interfaces/models/content/property/PropertyGroup'; -import { RangeFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilter'; import { Ref } from '@vue/composition-api'; import { Salutation } from '@shopware-pwa/commons/interfaces/models/system/salutation/Salutation'; import { SessionContext } from '@shopware-pwa/commons/interfaces/response/SessionContext'; @@ -140,16 +137,6 @@ export function createListingComposable({ rootContext, searchMeth listingKey: string; }): IUseListing; -// @beta (undocumented) -export interface CurrentPagination { - // (undocumented) - currentPage: number | undefined; - // (undocumented) - perPage: number | undefined; - // (undocumented) - total: number | undefined; -} - // @beta (undocumented) export function getApplicationContext(rootContext: ApplicationVueContext, key?: string): { apiInstance: ShopwareApiInstance | undefined; @@ -659,43 +646,6 @@ export const useProductConfigurator: (rootContext: ApplicationVueContext, produc // @beta (undocumented) export const useProductQuickSearch: (rootContext: ApplicationVueContext_2) => IUseProductQuickSearch; -// @alpha @deprecated (undocumented) -export interface UseProductSearch { - // (undocumented) - availableFilters: Readonly>; - // (undocumented) - changePage: (page: number) => Promise; - // (undocumented) - changeSorting: (sorting: Sort) => void; - // (undocumented) - currentPagination: Ref; - // (undocumented) - currentSearchTerm: Readonly>; - // (undocumented) - loadingSearch: Readonly>; - // (undocumented) - loadingSuggestions: Readonly>; - // (undocumented) - resetFilters: () => void; - // (undocumented) - search: (term: string) => Promise; - // (undocumented) - searchResult: Readonly>; - // (undocumented) - selectedEntityFilters: Readonly>; - // (undocumented) - selectedFilters: Readonly>; - // (undocumented) - suggestionsResult: Readonly>; - // (undocumented) - suggestSearch: (term: string) => Promise; - // (undocumented) - toggleFilter: (filter: EqualsFilter | RangeFilter, forceSave: boolean) => void; -} - -// @alpha @deprecated (undocumented) -export const useProductSearch: (rootContext: ApplicationVueContext) => UseProductSearch; - // @beta (undocumented) export interface UseSalutations { // (undocumented) diff --git a/api/shopware-6-client.api.md b/api/shopware-6-client.api.md index da74959d6..40f4cd336 100644 --- a/api/shopware-6-client.api.md +++ b/api/shopware-6-client.api.md @@ -313,14 +313,6 @@ export const getNewsletterSubscribeEndpoint: () => string; // @beta (undocumented) export const getNewsletterUnsubscribeEndpoint: () => string; -// @beta -export function getOrderPaymentUrl({ orderId, finishUrl, }: { - orderId: string; - finishUrl?: string; -}, contextInstance?: ShopwareApiInstance): Promise<{ - paymentUrl: string; -}>; - // @beta (undocumented) export const getOrderPaymentUrlEndpoint: (orderId: string) => string; @@ -357,13 +349,10 @@ export const getProductsIds: (options?: any, contextInstance?: ShopwareApiInstan // @beta (undocumented) export const getProductsIdsEndpoint: () => string; -// @beta @deprecated (undocumented) -export function getResults(term: string, searchCriteria?: SearchCriteria, contextInstance?: ShopwareApiInstance): Promise; - // @beta (undocumented) export const getSearchEndpoint: () => string; -// @beta (undocumented) +// @beta @deprecated (undocumented) export function getSearchResults(term: string, searchCriteria?: SearchCriteria, contextInstance?: ShopwareApiInstance): Promise; // @beta (undocumented) @@ -411,17 +400,14 @@ export const getStoreNewsletterSubscribeEndpoint: () => string; export const getStoreNewsletterUnsubscribeEndpoint: () => string; // @beta (undocumented) -export function getStoreOrderPaymentUrl(orderId: string, contextInstance?: ShopwareApiInstance): Promise<{ - redirectResponse: unknown; +export function getStoreOrderPaymentUrl(orderId: string, finishUrl?: string, errorUrl?: string, contextInstance?: ShopwareApiInstance): Promise<{ + redirectUrl: string | null; apiAlias: string; }>; // @beta (undocumented) export const getStoreOrderPaymentUrlEndpoint: () => string; -// @alpha @deprecated (undocumented) -export function getSuggestedResults(term: string, searchCriteria?: SearchCriteria, contextInstance?: ShopwareApiInstance): Promise; - // @beta (undocumented) export const getSuggestSearchEndpoint: () => string; diff --git a/docs/landing/resources/api/composables.currentpagination.currentpage.md b/docs/landing/resources/api/composables.currentpagination.currentpage.md deleted file mode 100644 index 91e78c24a..000000000 --- a/docs/landing/resources/api/composables.currentpagination.currentpage.md +++ /dev/null @@ -1,14 +0,0 @@ - - -[Home](./index.md) > [@shopware-pwa/composables](./composables.md) > [CurrentPagination](./composables.currentpagination.md) > [currentPage](./composables.currentpagination.currentpage.md) - -## CurrentPagination.currentPage property - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Signature: - -```typescript -currentPage: number | undefined; -``` diff --git a/docs/landing/resources/api/composables.currentpagination.md b/docs/landing/resources/api/composables.currentpagination.md deleted file mode 100644 index b91c2e9f7..000000000 --- a/docs/landing/resources/api/composables.currentpagination.md +++ /dev/null @@ -1,24 +0,0 @@ - - -[Home](./index.md) > [@shopware-pwa/composables](./composables.md) > [CurrentPagination](./composables.currentpagination.md) - -## CurrentPagination interface - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - - -Signature: - -```typescript -export interface CurrentPagination -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [currentPage](./composables.currentpagination.currentpage.md) | number \| undefined | (BETA) | -| [perPage](./composables.currentpagination.perpage.md) | number \| undefined | (BETA) | -| [total](./composables.currentpagination.total.md) | number \| undefined | (BETA) | - diff --git a/docs/landing/resources/api/composables.currentpagination.perpage.md b/docs/landing/resources/api/composables.currentpagination.perpage.md deleted file mode 100644 index f0f97798e..000000000 --- a/docs/landing/resources/api/composables.currentpagination.perpage.md +++ /dev/null @@ -1,14 +0,0 @@ - - -[Home](./index.md) > [@shopware-pwa/composables](./composables.md) > [CurrentPagination](./composables.currentpagination.md) > [perPage](./composables.currentpagination.perpage.md) - -## CurrentPagination.perPage property - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Signature: - -```typescript -perPage: number | undefined; -``` diff --git a/docs/landing/resources/api/composables.currentpagination.total.md b/docs/landing/resources/api/composables.currentpagination.total.md deleted file mode 100644 index 92d1c5e32..000000000 --- a/docs/landing/resources/api/composables.currentpagination.total.md +++ /dev/null @@ -1,14 +0,0 @@ - - -[Home](./index.md) > [@shopware-pwa/composables](./composables.md) > [CurrentPagination](./composables.currentpagination.md) > [total](./composables.currentpagination.total.md) - -## CurrentPagination.total property - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Signature: - -```typescript -total: number | undefined; -``` diff --git a/docs/landing/resources/api/composables.md b/docs/landing/resources/api/composables.md index e93063338..7a14ed69b 100644 --- a/docs/landing/resources/api/composables.md +++ b/docs/landing/resources/api/composables.md @@ -20,7 +20,6 @@ | Interface | Description | | --- | --- | | [ApplicationVueContext](./composables.applicationvuecontext.md) | (BETA) Application Context for Shopware PWA. It's an extended Vue instance. | -| [CurrentPagination](./composables.currentpagination.md) | (BETA) | | [IInterceptorCallbackFunction](./composables.iinterceptorcallbackfunction.md) | (BETA) interface for the callback function of interceptors | | [IUseAddToCart](./composables.iuseaddtocart.md) | (BETA) interface for [useAddToCart](./composables.useaddtocart.md) composable | | [IUseCart](./composables.iusecart.md) | (BETA) interface for [useCart](./composables.usecart.md) composable | diff --git a/docs/landing/resources/api/shopware-6-client.getorderpaymenturl.md b/docs/landing/resources/api/shopware-6-client.getorderpaymenturl.md deleted file mode 100644 index b0cd006b0..000000000 --- a/docs/landing/resources/api/shopware-6-client.getorderpaymenturl.md +++ /dev/null @@ -1,37 +0,0 @@ - - -[Home](./index.md) > [@shopware-pwa/shopware-6-client](./shopware-6-client.md) > [getOrderPaymentUrl](./shopware-6-client.getorderpaymenturl.md) - -## getOrderPaymentUrl() function - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -Get payment address to redirect user after placing order. - -Signature: - -```typescript -export declare function getOrderPaymentUrl({ orderId, finishUrl, }: { - orderId: string; - finishUrl?: string; -}, contextInstance?: ShopwareApiInstance): Promise<{ - paymentUrl: string; -}>; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| { orderId, finishUrl, } | { orderId: string; finishUrl?: string; } | | -| contextInstance | [ShopwareApiInstance](./shopware-6-client.shopwareapiinstance.md) | | - -Returns: - -Promise<{ paymentUrl: string; }> - -## Exceptions - -ClientApiError - diff --git a/docs/landing/resources/api/shopware-6-client.getresults.md b/docs/landing/resources/api/shopware-6-client.getresults.md deleted file mode 100644 index 277ee13e9..000000000 --- a/docs/landing/resources/api/shopware-6-client.getresults.md +++ /dev/null @@ -1,32 +0,0 @@ - - -[Home](./index.md) > [@shopware-pwa/shopware-6-client](./shopware-6-client.md) > [getResults](./shopware-6-client.getresults.md) - -## getResults() function - -> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. -> - -> Warning: This API is now obsolete. -> -> - this function will be replaced by getSearchResults what is a more appriopriate name. -> - -Signature: - -```typescript -export declare function getResults(term: string, searchCriteria?: SearchCriteria, contextInstance?: ShopwareApiInstance): Promise; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| term | string | | -| searchCriteria | SearchCriteria | | -| contextInstance | [ShopwareApiInstance](./shopware-6-client.shopwareapiinstance.md) | | - -Returns: - -Promise<ProductListingResult> - diff --git a/docs/landing/resources/api/shopware-6-client.getsearchresults.md b/docs/landing/resources/api/shopware-6-client.getsearchresults.md index dbcbe56b9..d5766ab55 100644 --- a/docs/landing/resources/api/shopware-6-client.getsearchresults.md +++ b/docs/landing/resources/api/shopware-6-client.getsearchresults.md @@ -7,6 +7,11 @@ > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. > +> Warning: This API is now obsolete. +> +> use searchProducts instead +> + Signature: ```typescript diff --git a/docs/landing/resources/api/shopware-6-client.getstoreorderpaymenturl.md b/docs/landing/resources/api/shopware-6-client.getstoreorderpaymenturl.md index d8ac9eb83..79aa5be67 100644 --- a/docs/landing/resources/api/shopware-6-client.getstoreorderpaymenturl.md +++ b/docs/landing/resources/api/shopware-6-client.getstoreorderpaymenturl.md @@ -7,12 +7,11 @@ > This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. > - Signature: ```typescript -export declare function getStoreOrderPaymentUrl(orderId: string, contextInstance?: ShopwareApiInstance): Promise<{ - redirectResponse: unknown; +export declare function getStoreOrderPaymentUrl(orderId: string, finishUrl?: string, errorUrl?: string, contextInstance?: ShopwareApiInstance): Promise<{ + redirectUrl: string | null; apiAlias: string; }>; ``` @@ -21,10 +20,12 @@ export declare function getStoreOrderPaymentUrl(orderId: string, contextInstance | Parameter | Type | Description | | --- | --- | --- | -| orderId | string | | +| orderId | string | Id of an order | +| finishUrl | string | URL where the customer is redirected to after payment is done | +| errorUrl | string | URL where the customer is redirected to after payment fails | | contextInstance | [ShopwareApiInstance](./shopware-6-client.shopwareapiinstance.md) | | Returns: -Promise<{ redirectResponse: unknown; apiAlias: string; }> +Promise<{ redirectUrl: string \| null; apiAlias: string; }> diff --git a/docs/landing/resources/api/shopware-6-client.md b/docs/landing/resources/api/shopware-6-client.md index 16bebba80..6caac363b 100644 --- a/docs/landing/resources/api/shopware-6-client.md +++ b/docs/landing/resources/api/shopware-6-client.md @@ -32,18 +32,16 @@ | [getCustomerAddresses(contextInstance)](./shopware-6-client.getcustomeraddresses.md) | (BETA) Get all customer's addresses | | [getCustomerOrderDetails(orderId, contextInstance, additionalQueryParams)](./shopware-6-client.getcustomerorderdetails.md) | (BETA) Get order details | | [getCustomerOrders(contextInstance)](./shopware-6-client.getcustomerorders.md) | (BETA) Get all customer's orders | -| [getOrderPaymentUrl({ orderId, finishUrl, }, contextInstance)](./shopware-6-client.getorderpaymenturl.md) | (BETA) Get payment address to redirect user after placing order. | | [getPage(path, searchCriteria, contextInstance)](./shopware-6-client.getpage.md) | (BETA) | | [getPaymentMethodDetails(paymentId, contextInstance)](./shopware-6-client.getpaymentmethoddetails.md) | (BETA) | | [getProduct(productId, params, contextInstance)](./shopware-6-client.getproduct.md) | (BETA) Get the product with passed productId | | [getProductPage(path, searchCriteria, contextInstance)](./shopware-6-client.getproductpage.md) | (BETA) | -| [getResults(term, searchCriteria, contextInstance)](./shopware-6-client.getresults.md) | (BETA) | | [getSearchResults(term, searchCriteria, contextInstance)](./shopware-6-client.getsearchresults.md) | (BETA) | | [getSeoUrls(entityId, languageId, contextInstance)](./shopware-6-client.getseourls.md) | (BETA) Returns an array of SEO URLs for given entity Can be used for other languages as well by providing the languageId | | [getSessionContext(contextInstance)](./shopware-6-client.getsessioncontext.md) | (BETA) Loads session context, containing all session-related data. | | [getShippingMethodDetails(shippingId, contextInstance)](./shopware-6-client.getshippingmethoddetails.md) | (BETA) | | [getStoreNavigation({ requestActiveId, requestRootId, depth, buildTree, searchCriteria, }, contextInstance)](./shopware-6-client.getstorenavigation.md) | (BETA) | -| [getStoreOrderPaymentUrl(orderId, contextInstance)](./shopware-6-client.getstoreorderpaymenturl.md) | (BETA) | +| [getStoreOrderPaymentUrl(orderId, finishUrl, errorUrl, contextInstance)](./shopware-6-client.getstoreorderpaymenturl.md) | (BETA) | | [getUserCountry(countryId, contextInstance)](./shopware-6-client.getusercountry.md) | (BETA) | | [getUserSalutation(salutationId, contextInstance)](./shopware-6-client.getusersalutation.md) | (BETA) | | [invokeGet({ address }, contextInstance)](./shopware-6-client.invokeget.md) | (BETA) Invoke custom GET request to shopware API. Mostly for plugins usage. You can skip domain and pass only endpoint ex. /api/my/endpoint | diff --git a/packages/commons/interfaces/response/ProductListingResult.ts b/packages/commons/interfaces/response/ProductListingResult.ts index 0ed19a17c..d5d46141b 100644 --- a/packages/commons/interfaces/response/ProductListingResult.ts +++ b/packages/commons/interfaces/response/ProductListingResult.ts @@ -15,6 +15,7 @@ export interface ProductListingResult { sortings: Sort[]; availableSortings: Sort[]; aggregations: Aggregations; + entity: string; currentFilters: { manufacturer: string[]; properties: string[]; diff --git a/packages/commons/interfaces/response/SessionContext.ts b/packages/commons/interfaces/response/SessionContext.ts index 227820189..14cb050df 100644 --- a/packages/commons/interfaces/response/SessionContext.ts +++ b/packages/commons/interfaces/response/SessionContext.ts @@ -3,7 +3,7 @@ import { ShippingMethod } from "../models/checkout/shipping/ShippingMethod"; import { Country } from "../models/system/country/Country"; import { User } from "../models/system/user/User"; import { Currency } from "../models/system/currency/Currency"; -import { ShippingAddress } from "../request/GuestOrderParams"; +import { ShippingAddress } from "../models/checkout/customer/ShippingAddress"; export interface ContextTokenResponse { contextToken: string; diff --git a/packages/composables/__tests__/helpers/searchCriteria.spec.ts b/packages/composables/__tests__/helpers/searchCriteria.spec.ts index f5baa9d65..ecf374994 100644 --- a/packages/composables/__tests__/helpers/searchCriteria.spec.ts +++ b/packages/composables/__tests__/helpers/searchCriteria.spec.ts @@ -109,6 +109,18 @@ describe("composables searchCriteria", () => { ); expect(searchCriteria.properties).toStrictEqual(["blue", "black"]); }); + it("should append the search criteria params", () => { + const searchCriteria: any = {}; + appendQueryParamsToSearchCriteria( + { query: "test", sort: "-name" }, + searchCriteria + ); + expect(searchCriteria.sort).toStrictEqual({ + field: "", + name: "-name", + order: "name", + }); + }); }); describe("resetSearchCriteria", () => { diff --git a/packages/composables/__tests__/useProductSearch.spec.ts b/packages/composables/__tests__/useProductSearch.spec.ts deleted file mode 100644 index 9290c7de3..000000000 --- a/packages/composables/__tests__/useProductSearch.spec.ts +++ /dev/null @@ -1,310 +0,0 @@ -import Vue from "vue"; -import VueCompositionApi from "@vue/composition-api"; -Vue.use(VueCompositionApi); -import { useProductSearch } from "@shopware-pwa/composables"; -jest.mock("@shopware-pwa/shopware-6-client"); -import * as shopwareClient from "@shopware-pwa/shopware-6-client"; -import { SearchFilterType } from "@shopware-pwa/commons/interfaces/search/SearchFilter"; -const mockedApi = shopwareClient as jest.Mocked; -const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {}); -const consoleErrorSpy = jest - .spyOn(console, "error") - .mockImplementation(() => {}); - -describe("Composables - useProductSearch", () => { - const rootContextMock: any = { - $shopwareApiInstance: jest.fn(), - }; - beforeEach(() => { - jest.resetAllMocks(); - }); - - it("should display deprecation info on invocation", () => { - useProductSearch(rootContextMock); - expect(consoleWarnSpy).toBeCalledWith( - '[DEPRECATED][@shopware-pwa/composables][useProductSearch] This method has been deprecated. Use "useProductQuickSearch" instead.' - ); - }); - - describe("initial values", () => { - it("should have no listing result if search wasn't performed", async () => { - const { searchResult } = useProductSearch(rootContextMock); - expect(searchResult.value).toBeNull(); - }); - it("should have loading value set to false by default", async () => { - const { loadingSearch } = useProductSearch(rootContextMock); - expect(loadingSearch.value).toBeFalsy(); - }); - }); - describe("currentPagination", () => { - it("should have undefined properties if there is no search result", async () => { - mockedApi.getSearchResults.mockResolvedValueOnce(null as any); - const { search, currentPagination } = useProductSearch(rootContextMock); - await search("some term"); - expect(currentPagination.value).toStrictEqual({ - currentPage: undefined, - perPage: undefined, - total: undefined, - }); - }); - it("should have proper values under the pagination property", async () => { - mockedApi.getSearchResults.mockResolvedValueOnce({ - page: 4, - limit: 10, - total: 189, - } as any); - const { search, currentPagination } = useProductSearch(rootContextMock); - await search("some term"); - expect(currentPagination.value).toStrictEqual({ - currentPage: 4, - perPage: 10, - total: 189, - }); - }); - }); - describe("currentSearchTerm", () => { - it("should have current search-term if there is one provided during the search", async () => { - const { search, currentSearchTerm } = useProductSearch(rootContextMock); - await search("some term"); - expect(currentSearchTerm.value).toBe("some term"); - }); - }); - describe("suggestSearch", () => { - it("should have appriopriate API call invoked on search action", async () => { - const { suggestSearch, suggestionsResult } = useProductSearch( - rootContextMock - ); - await suggestSearch("some string"); - expect(mockedApi.getSuggestedResults).toBeCalledTimes(1); - expect(mockedApi.getSuggestedResults).toBeCalledWith( - "some string", - undefined, - rootContextMock.$shopwareApiInstance - ); - expect(suggestionsResult.value).toBeUndefined(); - }); - it("should catch and log the error on api call rejection", async () => { - const { suggestSearch } = useProductSearch(rootContextMock); - mockedApi.getSuggestedResults.mockRejectedValueOnce({ - message: "Something went wrong", - } as any); - - await suggestSearch("lucky search"); - expect(consoleErrorSpy).toBeCalledWith( - "[useProductSearch][suggestSearch]", - { - message: "Something went wrong", - } - ); - }); - }); - describe("search", () => { - it("should set available filters if it's a base search with aggregations for whole collection", async () => { - mockedApi.getSearchResults.mockResolvedValueOnce({ - page: 4, - limit: 10, - total: 189, - aggregations: { - manufacturer: { - entities: [ - { - translated: { - name: "DivanteLtd", - }, - id: "123456", - }, - ], - }, - }, - } as any); - const { search, availableFilters } = useProductSearch(rootContextMock); - await search("some string"); - expect(availableFilters.value).toStrictEqual([ - { - name: "manufacturer", - options: [ - { - translated: { - name: "DivanteLtd", - }, - id: "123456", - color: undefined, - label: "DivanteLtd", - value: "123456", - }, - ], - type: "entity", - }, - ]); - }); - it("should have appriopriate API call invoked on search action", async () => { - const { search, resetFilters } = useProductSearch(rootContextMock); - resetFilters(); - await search("some string"); - expect(mockedApi.getSearchResults).toBeCalledTimes(1); - expect(mockedApi.getSearchResults).toBeCalledWith( - "some string", - { - manufacturer: [], - properties: [], - sort: {}, - pagination: { - limit: undefined, - page: undefined, - }, - filters: {}, - }, - rootContextMock.$shopwareApiInstance - ); - }); - it("should have product returned if search term provided", async () => { - mockedApi.getSearchResults.mockResolvedValueOnce({ - data: [{ name: "some string" }], - } as any); - const { search, searchResult } = useProductSearch(rootContextMock); - await search("some string"); - expect(searchResult.value).toStrictEqual({ - data: [{ name: "some string" }], - }); - }); - it("should not perform search without any term provided", async () => { - const { search, searchResult } = useProductSearch(rootContextMock); - await search(undefined as any); - expect(mockedApi.getSearchResults).toBeCalledTimes(0); - expect(searchResult.value).toStrictEqual(null); - }); - it("should have error on rejection from API client", async () => { - mockedApi.getSearchResults.mockRejectedValueOnce({ - message: "Something went wrong", - } as any); - - const { search, searchResult } = useProductSearch(rootContextMock); - try { - await search("test"); - } catch (e) { - expect(e).toStrictEqual({ message: "Something went wrong" }); - } - - expect(mockedApi.getSearchResults).toBeCalledTimes(1); - expect(searchResult.value).toStrictEqual(null); - }); - }); - describe("changePage", () => { - it("should append the provided page to the pagination object", async () => { - const { changePage, search } = useProductSearch(rootContextMock); - await search("test"); - await changePage(5); - expect(mockedApi.getSearchResults).toBeCalledWith( - "test", - { - manufacturer: [], - pagination: { limit: undefined, page: 5 }, - properties: [], - sort: {}, - filters: {}, - }, - rootContextMock.$shopwareApiInstance - ); - expect(mockedApi.getSearchResults).toBeCalledTimes(2); - }); - }); - describe("changeSorting", () => { - it("should invoke getSearchResults with provided sorting config", async () => { - const { search, changeSorting } = useProductSearch(rootContextMock); - await search("test"); - await changeSorting({ - field: "name", - name: "name-desc", - desc: true, - }); - expect(mockedApi.getSearchResults).toBeCalledWith( - "test", - { - manufacturer: [], - properties: [], - pagination: { - limit: undefined, - page: 5, - }, - sort: { - field: "name", - name: "name-desc", - order: "desc", - }, - filters: {}, - }, - rootContextMock.$shopwareApiInstance - ); - expect(mockedApi.getSearchResults).toBeCalledTimes(2); - }); - it("should not invoke getSearchResults if no sorting was provided", async () => { - const { search, changeSorting } = useProductSearch(rootContextMock); - await search("test"); - await changeSorting(undefined as any); - expect(mockedApi.getSearchResults).toBeCalledTimes(1); - }); - }); - describe("toggleFilter", () => { - it("should not select filter if it has wrong format", () => { - const { toggleFilter, selectedFilters } = useProductSearch( - rootContextMock - ); - toggleFilter(undefined as any, false); - expect(selectedFilters.value).toStrictEqual({}); - }); - it("should trigger ToggleSelectedFilter on toggleFilter run", () => { - const { toggleFilter, selectedEntityFilters } = useProductSearch( - rootContextMock - ); - toggleFilter( - { - type: SearchFilterType.EQUALS, - value: "white", - field: "color", - }, - false - ); - expect(selectedEntityFilters.value).toStrictEqual(["white"]); - }); - it("should contain a range filter as selectedFilter if any provided", () => { - const { toggleFilter, selectedFilters } = useProductSearch( - rootContextMock - ); - toggleFilter( - { - type: SearchFilterType.RANGE, - parameters: { - gt: 10, - }, - field: "price", - } as any, - false - ); - expect(selectedFilters.value).toStrictEqual({ - price: { - gt: 10, - }, - }); - }); - }); - describe("resetFilters", () => { - it("should removed all filters from selectedFilters computed property", () => { - const { - toggleFilter, - selectedEntityFilters, - resetFilters, - } = useProductSearch(rootContextMock); - toggleFilter( - { - type: SearchFilterType.EQUALS, - value: "white", - field: "color", - }, - false - ); - expect(selectedEntityFilters.value).toStrictEqual(["white"]); - resetFilters(); - expect(selectedEntityFilters.value).not.toBe(["white"]); - }); - }); -}); diff --git a/packages/composables/src/hooks/useProductSearch.ts b/packages/composables/src/hooks/useProductSearch.ts deleted file mode 100644 index d6ccae9db..000000000 --- a/packages/composables/src/hooks/useProductSearch.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { ref, Ref, computed, reactive } from "@vue/composition-api"; -import { parse } from "query-string"; -import { - getSuggestedResults, - getSearchResults, -} from "@shopware-pwa/shopware-6-client"; -import { - getListingAvailableFilters, - UiCategoryFilter, -} from "@shopware-pwa/helpers"; - -import { - ListingQueryParams, - SearchCriteria, - Sort, -} from "@shopware-pwa/commons/interfaces/search/SearchCriteria"; -import { - EqualsFilter, - RangeFilter, - SearchFilterType, -} from "@shopware-pwa/commons/interfaces/search/SearchFilter"; -import { Aggregations } from "@shopware-pwa/commons/interfaces/search/Aggregations"; -import { ProductListingResult } from "@shopware-pwa/commons/interfaces/response/ProductListingResult"; -import { getApplicationContext } from "@shopware-pwa/composables"; -import { ApplicationVueContext } from "../appContext"; -import { - appendSearchCriteriaToUrl, - appendQueryParamsToSearchCriteria, - resetSearchCriteria, - toggleEntityFilter, - toggleFilter as toggleGenericFilter, -} from "../internalHelpers/searchCriteria"; -import { deprecationWarning } from "@shopware-pwa/commons"; - -/** - * @beta - */ -export interface CurrentPagination { - currentPage: number | undefined; - perPage: number | undefined; - total: number | undefined; -} - -/** - * @alpha - * @deprecated please see useProductQuickSearch instead - */ -export interface UseProductSearch { - loadingSearch: Readonly>; - loadingSuggestions: Readonly>; - currentSearchTerm: Readonly>; - searchResult: Readonly>; - suggestionsResult: Readonly>; - currentPagination: Ref; - availableFilters: Readonly>; - selectedFilters: Readonly>; - selectedEntityFilters: Readonly>; - suggestSearch: (term: string) => Promise; - search: (term: string) => Promise; - changePage: (page: number) => Promise; - changeSorting: (sorting: Sort) => void; - toggleFilter: ( - filter: EqualsFilter | RangeFilter, - forceSave: boolean - ) => void; - resetFilters: () => void; -} - -/** - * @alpha - * @deprecated please see useProductQuickSearch instead - */ -export const useProductSearch = ( - rootContext: ApplicationVueContext -): UseProductSearch => { - const { apiInstance } = getApplicationContext( - rootContext, - "useProductSearch" - ); - deprecationWarning({ - methodName: "useProductSearch", - newMethodName: "useProductQuickSearch", - packageName: "composables", - }); - - const loadingSearch: Ref = ref(false); - const loadingSuggestions: Ref = ref(false); - const currentSearchTerm: Ref = ref(""); - const searchResult: Ref = ref(null); - const suggestionsResult: Ref = ref(null); - const availableFilters: Ref = ref([]); - const currentPagination = computed(() => ({ - currentPage: searchResult.value?.page, - perPage: searchResult.value?.limit, - total: searchResult.value?.total, - })); - const searchCriteria: Partial | any = reactive({ - manufacturer: [], - properties: [], - filters: {}, - pagination: {}, - sort: {}, - }); - - const aggregations: Readonly> = computed( - () => searchResult.value && searchResult.value.aggregations - ); - - const changePage = async (page: number): Promise => { - searchCriteria.pagination.page = page; - syncQueryParams(); - await search(currentSearchTerm.value); - }; - - const suggestSearch = async (term: string): Promise => { - try { - loadingSuggestions.value = true; - const suggestedProductListing = await getSuggestedResults( - term, - undefined, - apiInstance - ); - suggestionsResult.value = suggestedProductListing; - } catch (e) { - console.error("[useProductSearch][suggestSearch]", e); - } finally { - loadingSuggestions.value = false; - } - }; - - const syncQueryParams = () => { - appendSearchCriteriaToUrl(searchCriteria, currentSearchTerm.value); - }; - - const changeSorting = async (sorting: Sort) => { - if (!sorting) { - return; - } - - searchCriteria.sort = sorting; - syncQueryParams(); - await search(currentSearchTerm.value); - }; - - const toggleFilter = ( - filter: EqualsFilter | RangeFilter, - forceSave?: boolean - ): undefined | string => { - if (!filter || !Object.keys(filter).length) { - return; - } - - if (filter.type === SearchFilterType.RANGE) { - toggleGenericFilter(filter, searchCriteria); - } - - if (filter.type === SearchFilterType.EQUALS) { - toggleEntityFilter(filter as EqualsFilter, searchCriteria, forceSave); - } - - syncQueryParams(); - }; - - const captureQueryParams = () => { - /* istanbul ignore next */ - const criteriaQueryParams: ListingQueryParams | any = parse( - window?.location?.search, - { - parseNumbers: true, - } - ); - /* istanbul ignore next */ - if (!criteriaQueryParams) { - return; - } - - appendQueryParamsToSearchCriteria(criteriaQueryParams, searchCriteria); - }; - - const search = async (term: string): Promise => { - if (!term) { - return; - } - - try { - captureQueryParams(); - loadingSearch.value = true; - currentSearchTerm.value = term; - searchResult.value = null; - const result = await getSearchResults(term, searchCriteria, apiInstance); - searchResult.value = result; - availableFilters.value = getListingAvailableFilters(aggregations.value); - } catch (e) { - throw e; - } finally { - loadingSearch.value = false; - } - }; - - const resetFilters = async () => { - resetSearchCriteria(searchCriteria); - syncQueryParams(); - }; - - return { - suggestSearch, - search, - currentSearchTerm: computed(() => currentSearchTerm.value), - loadingSearch, - loadingSuggestions, - searchResult: computed(() => searchResult.value), - suggestionsResult, - currentPagination, - selectedFilters: computed(() => searchCriteria.filters), // other type of filters, like price range - selectedEntityFilters: computed(() => [ - ...searchCriteria.manufacturer, - ...searchCriteria.properties, - ]), - availableFilters, - changePage, - changeSorting, - toggleFilter, - resetFilters, - }; -}; diff --git a/packages/composables/src/index.ts b/packages/composables/src/index.ts index 9f2c32ef1..8c311d713 100644 --- a/packages/composables/src/index.ts +++ b/packages/composables/src/index.ts @@ -11,7 +11,6 @@ export * from "./hooks/useNavigation"; export * from "./hooks/useSalutations"; export * from "./hooks/useCountries"; export * from "./hooks/useUser"; -export * from "./hooks/useProductSearch"; export * from "./factories/createCheckoutStep"; export * from "./logic/useDefaults"; export * from "./logic/useNotifications"; diff --git a/packages/composables/src/internalHelpers/searchCriteria.ts b/packages/composables/src/internalHelpers/searchCriteria.ts index a9498ea66..172eb750e 100644 --- a/packages/composables/src/internalHelpers/searchCriteria.ts +++ b/packages/composables/src/internalHelpers/searchCriteria.ts @@ -1,3 +1,5 @@ +/* istanbul ignore file */ + import { stringify } from "query-string"; import { ListingQueryParams, @@ -10,6 +12,9 @@ import { SearchFilterType, } from "@shopware-pwa/commons/interfaces/search/SearchFilter"; +/** + * @deprecated this method is no longer supported + */ export function appendSearchCriteriaToUrl( searchCriteria: SearchCriteria, searchTerm: string @@ -43,6 +48,9 @@ export function appendSearchCriteriaToUrl( } } +/** + * @deprecated this method is no longer supported + */ export function appendQueryParamsToSearchCriteria( params: ListingQueryParams, searchCriteria: SearchCriteria @@ -73,6 +81,9 @@ export function appendQueryParamsToSearchCriteria( []; } +/** + * @deprecated this method is no longer supported + */ export const resetSearchCriteria = ( searchCriteria: Partial ) => { @@ -101,8 +112,7 @@ interface ShopwareParamsInternal { } /** - * TODO: https://github.com/DivanteLtd/shopware-pwa/issues/841 - * TODO: https://github.com/DivanteLtd/shopware-pwa/issues/840 + * @deprecated this method is no longer supported */ export const toggleEntityFilter = ( filter: EqualsFilter, // TODO: handle range filter case as well @@ -147,6 +157,7 @@ export const toggleEntityFilter = ( }; /** + * @deprecated this method is no longer supported * TODO: https://github.com/DivanteLtd/shopware-pwa/issues/841 * TODO: https://github.com/DivanteLtd/shopware-pwa/issues/840 * @beta diff --git a/packages/shopware-6-client/__tests__/services/SearchService/getResults.spec.ts b/packages/shopware-6-client/__tests__/services/SearchService/getResults.spec.ts deleted file mode 100644 index a9c5e581a..000000000 --- a/packages/shopware-6-client/__tests__/services/SearchService/getResults.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { getResults } from "@shopware-pwa/shopware-6-client"; -import { defaultInstance } from "../../../src/apiService"; -const consoleWarnSpy = jest.spyOn(console, "warn"); - -jest.mock("../../../src/apiService"); -const mockedApiInstance = defaultInstance as jest.Mocked< - typeof defaultInstance ->; -describe("SearchService - getResults", () => { - const mockedPost = jest.fn(); - beforeEach(() => { - jest.resetAllMocks(); - mockedApiInstance.invoke = { - post: mockedPost, - } as any; - consoleWarnSpy.mockImplementation(() => {}); - }); - it("should return ProductListingResult", async () => { - mockedPost.mockResolvedValueOnce({ - data: { apiAlias: "product_listing" }, - }); - const result = await getResults("some term"); - expect(mockedPost).toBeCalledTimes(1); - expect(mockedPost).toBeCalledWith("/store-api/v3/search?search=some term", { - limit: 10, - p: 1, - }); - expect(result).toHaveProperty("apiAlias"); - }); - it("should show deprecation info on this method", async () => { - mockedPost.mockResolvedValueOnce({ - data: { apiAlias: "product_listing" }, - }); - await getResults("some term"); - expect(consoleWarnSpy).toBeCalledWith( - '[DEPRECATED][@shopware-pwa/shopware-6-client][getResults] This method has been deprecated. Use "getSearchResults" instead.' - ); - }); -}); diff --git a/packages/shopware-6-client/__tests__/services/SearchService/getSearchResults.spec.ts b/packages/shopware-6-client/__tests__/services/SearchService/getSearchResults.spec.ts index 24d4a2ab6..6a29912b7 100644 --- a/packages/shopware-6-client/__tests__/services/SearchService/getSearchResults.spec.ts +++ b/packages/shopware-6-client/__tests__/services/SearchService/getSearchResults.spec.ts @@ -20,7 +20,7 @@ describe("SearchService - getSearchResults", () => { }); const result = await getSearchResults("some term"); expect(mockedPost).toBeCalledTimes(1); - expect(mockedPost).toBeCalledWith("/store-api/v3/search?search=some term", { + expect(mockedPost).toBeCalledWith("/store-api/search?search=some term", { limit: 10, p: 1, }); diff --git a/packages/shopware-6-client/__tests__/services/SearchService/getSuggestedResults.spec.ts b/packages/shopware-6-client/__tests__/services/SearchService/getSuggestedResults.spec.ts deleted file mode 100644 index f58b6c2b7..000000000 --- a/packages/shopware-6-client/__tests__/services/SearchService/getSuggestedResults.spec.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { getSuggestedResults } from "@shopware-pwa/shopware-6-client"; -import { defaultInstance } from "../../../src/apiService"; - -jest.mock("../../../src/apiService"); -const mockedApiInstance = defaultInstance as jest.Mocked< - typeof defaultInstance ->; -const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {}); - -describe("SearchService - getSuggestedResults", () => { - const mockedPost = jest.fn(); - beforeEach(() => { - jest.resetAllMocks(); - mockedApiInstance.invoke = { - post: mockedPost, - } as any; - }); - - it("should display deprecation info on invocation", async () => { - mockedPost.mockResolvedValueOnce({ - data: {}, - }); - await getSuggestedResults("some term"); - expect(consoleWarnSpy).toBeCalledWith( - '[DEPRECATED][@shopware-pwa/shopware-6-client][getSuggestedResults] This method has been deprecated. Use "searchSuggestedProducts" instead.' - ); - }); - - it("should return ProductListingResult", async () => { - mockedPost.mockResolvedValueOnce({ - data: { apiAlias: "product_listing" }, - }); - const result = await getSuggestedResults("some term"); - expect(mockedPost).toBeCalledTimes(1); - expect(mockedPost).toBeCalledWith( - "/store-api/v3/search-suggest?search=some term", - { - limit: 10, - } - ); - expect(result).toHaveProperty("apiAlias"); - }); -}); diff --git a/packages/shopware-6-client/__tests__/services/SearchService/searchProducts.spec.ts b/packages/shopware-6-client/__tests__/services/SearchService/searchProducts.spec.ts index 22dfc357e..cc5bf58ea 100644 --- a/packages/shopware-6-client/__tests__/services/SearchService/searchProducts.spec.ts +++ b/packages/shopware-6-client/__tests__/services/SearchService/searchProducts.spec.ts @@ -24,14 +24,11 @@ describe("SearchService - searchProducts", () => { p: 1, }); expect(mockedPost).toBeCalledTimes(1); - expect(mockedPost).toBeCalledWith( - "/store-api/v3/search?search=searchTerm", - { - query: "searchTerm", - limit: 10, - p: 1, - } - ); + expect(mockedPost).toBeCalledWith("/store-api/search?search=searchTerm", { + query: "searchTerm", + limit: 10, + p: 1, + }); expect(result).toHaveProperty("apiAlias"); }); @@ -41,10 +38,7 @@ describe("SearchService - searchProducts", () => { }); const result = await searchProducts(undefined); expect(mockedPost).toBeCalledTimes(1); - expect(mockedPost).toBeCalledWith( - "/store-api/v3/search?search=", - undefined - ); + expect(mockedPost).toBeCalledWith("/store-api/search?search=", undefined); expect(result).toHaveProperty("apiAlias"); }); }); diff --git a/packages/shopware-6-client/__tests__/services/SearchService/searchSuggestedProducts.spec.ts b/packages/shopware-6-client/__tests__/services/SearchService/searchSuggestedProducts.spec.ts index b5f3728cf..ddc5b7077 100644 --- a/packages/shopware-6-client/__tests__/services/SearchService/searchSuggestedProducts.spec.ts +++ b/packages/shopware-6-client/__tests__/services/SearchService/searchSuggestedProducts.spec.ts @@ -25,7 +25,7 @@ describe("SearchService - searchSuggestedProducts", () => { }); expect(mockedPost).toBeCalledTimes(1); expect(mockedPost).toBeCalledWith( - "/store-api/v3/search-suggest?search=searchTerm", + "/store-api/search-suggest?search=searchTerm", { query: "searchTerm", limit: 10, @@ -42,7 +42,7 @@ describe("SearchService - searchSuggestedProducts", () => { const result = await searchSuggestedProducts(undefined); expect(mockedPost).toBeCalledTimes(1); expect(mockedPost).toBeCalledWith( - "/store-api/v3/search-suggest?search=", + "/store-api/search-suggest?search=", undefined ); expect(result).toHaveProperty("apiAlias"); diff --git a/packages/shopware-6-client/src/endpoints.ts b/packages/shopware-6-client/src/endpoints.ts index dde6c5b88..e4af02871 100644 --- a/packages/shopware-6-client/src/endpoints.ts +++ b/packages/shopware-6-client/src/endpoints.ts @@ -43,12 +43,12 @@ export const getProductsIdsEndpoint = () => /** * @beta */ -export const getSuggestSearchEndpoint = () => `/store-api/v3/search-suggest`; +export const getSuggestSearchEndpoint = () => `/store-api/search-suggest`; /** * @beta */ -export const getSearchEndpoint = () => `/store-api/v3/search`; +export const getSearchEndpoint = () => `/store-api/search`; // customer diff --git a/packages/shopware-6-client/src/services/checkoutService.ts b/packages/shopware-6-client/src/services/checkoutService.ts index a72b87413..e99c2ddbb 100644 --- a/packages/shopware-6-client/src/services/checkoutService.ts +++ b/packages/shopware-6-client/src/services/checkoutService.ts @@ -18,9 +18,9 @@ export async function createOrder( } /** - * @param {string} orderId - Id of an order - * @param {string} finishUrl - URL where the customer is redirected to after payment is done - * @param {string} errorUrl - URL where the customer is redirected to after payment fails + * @param orderId - Id of an order + * @param finishUrl - URL where the customer is redirected to after payment is done + * @param errorUrl - URL where the customer is redirected to after payment fails * @beta */ export async function getStoreOrderPaymentUrl( diff --git a/packages/shopware-6-client/src/services/searchService.ts b/packages/shopware-6-client/src/services/searchService.ts index d74e1e23d..563f8b6ea 100644 --- a/packages/shopware-6-client/src/services/searchService.ts +++ b/packages/shopware-6-client/src/services/searchService.ts @@ -1,66 +1,15 @@ import { getSuggestSearchEndpoint, getSearchEndpoint } from "../endpoints"; import { defaultInstance, ShopwareApiInstance } from "../apiService"; import { SearchCriteria } from "@shopware-pwa/commons/interfaces/search/SearchCriteria"; -import { - convertSearchCriteria, - ApiType, - convertShopwareSearchCriteria, -} from "../helpers/searchConverter"; +import { convertShopwareSearchCriteria } from "../helpers/searchConverter"; import { ProductListingResult } from "@shopware-pwa/commons/interfaces/response/ProductListingResult"; -import { deprecationWarning } from "@shopware-pwa/commons"; import { ShopwareSearchParams } from "@shopware-pwa/commons/interfaces/search/SearchCriteria"; /** * @throws ClientApiError - * @deprecated - please use searchSuggestedProducts instead - * @alpha - */ -export async function getSuggestedResults( - term: string, - searchCriteria?: SearchCriteria, - contextInstance: ShopwareApiInstance = defaultInstance -): Promise { - deprecationWarning({ - methodName: "getSuggestedResults", - newMethodName: "searchSuggestedProducts", - packageName: "shopware-6-client", - }); - const resp = await contextInstance.invoke.post( - `${getSuggestSearchEndpoint()}?search=${term}`, - { - ...convertSearchCriteria({ - searchCriteria, - apiType: ApiType.store, - config: contextInstance.config, - }), - } - ); - - return resp.data; -} - -/** - * @beta - * @deprecated - this function will be replaced by getSearchResults what is a more appriopriate name. - */ -export async function getResults( - term: string, - searchCriteria?: SearchCriteria, - contextInstance: ShopwareApiInstance = defaultInstance -) { - deprecationWarning({ - methodName: "getResults", - newMethodName: "getSearchResults", - packageName: "shopware-6-client", - }); - return getSearchResults(term, searchCriteria, contextInstance); -} - -/** - * @throws ClientApiError + * @deprecated use searchProducts instead * @beta */ - export async function getSearchResults( term: string, searchCriteria?: SearchCriteria,