You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently calling useListing-composable for example from a component, unhandled error happens.
See code below:
/** * @public */exportfunctionuseListing(params?: {listingType: ListingType;categoryId?: string;defaultSearchCriteria?: RequestParameters<"searchPage">;}): UseListingReturn{constlistingType=params?.listingType||"categoryListing";// const { getDefaults } = useDefaults({ defaultsKey: contextName }); // ⚠️ necessary?const{ apiClient }=useShopwareContext();letsearchMethod;if(listingType==="productSearchListing"){searchMethod=async(searchCriteria: RequestParameters<"searchPage">)=>{returnapiClient.invoke("searchPage post /search",{
...searchCriteria,});};}else{const{ category }=useCategory();// 🚨 This causes unhandled error when category context is not present.searchMethod=async(searchCriteria: RequestParameters<"searchPage">)=>{if(!category.value?.id){thrownewError("[useListing][search] Search category id does not exist.",);}returnapiClient.invoke("readProductListing post /product-listing/{categoryId} sw-include-seo-urls",{"sw-include-seo-urls": true,
...searchCriteria,categoryId: category.value.id,},);};}returncreateListingComposable({listingKey: listingType,
searchMethod,searchDefaults:
params?.defaultSearchCriteria||({}asRequestParameters<"searchPage">),//getDefaults(),});}
Expected Behavior
If Category context is not present, the code should use the params.categoryId if exists. If params.categoryId does not exsist, then it should cracefully throw an handled error.
** Fix proposition **
/** * @public */exportfunctionuseListing(params?: {listingType: ListingType;categoryId?: string;defaultSearchCriteria?: RequestParameters<"searchPage">;}): UseListingReturn{constlistingType=params?.listingType||"categoryListing";const{ apiClient }=useShopwareContext();letsearchMethod;if(listingType==="productSearchListing"){searchMethod=async(searchCriteria: RequestParameters<"searchPage">)=>{returnapiClient.invoke("searchPage post /search",{
...searchCriteria,});};}else{letresourceId: string|undefined;try{const{ category }=useCategory();resourceId=category.value?.id;}catch(error){if(errorinstanceofContextError){resourceId=params?.categoryId;}else{console.error(error);}}searchMethod=async(searchCriteria: RequestParameters<"searchPage">)=>{if(!resourceId){thrownewError("[useListing][search] Search category id does not exist.",);}returnapiClient.invoke("readProductListing post /product-listing/{categoryId} sw-include-seo-urls",{"sw-include-seo-urls": true,
...searchCriteria,categoryId: resourceId,},);};}returncreateListingComposable({listingKey: listingType,
searchMethod,searchDefaults:
params?.defaultSearchCriteria||({}asRequestParameters<"searchPage">),//getDefaults(),});}
Steps To Reproduce
Create Nuxt project with Shopware frontends modules and add proper configs
Create some page
Create component listing-example.vue
Add following code to the component
<template>
<!-- No need to add anything here in this example -->
</template>
<scriptlang="ts"setup>const { search, getElements,} =useListing({ listingType: "categoryListing", categoryId: <your-category-id>, // entrypoint to browse defaultSearchCriteria: { // set the default criteria search: "", // Add the 'search' property with an empty string value limit: 25, p: 1, },});awaitsearch({ search: '' });</script>
### Environment
```markdown
- OS: Latest MacOS Sonoma
- Node: 18.18.0
- Yarn: 1.22.19
Anything else?
No response
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Current Behavior
Currently calling useListing-composable for example from a component, unhandled error happens.
See code below:
Expected Behavior
If Category context is not present, the code should use the params.categoryId if exists. If params.categoryId does not exsist, then it should cracefully throw an handled error.
** Fix proposition **
Steps To Reproduce
listing-example.vue
Anything else?
No response
The text was updated successfully, but these errors were encountered: