From 3e35c09c0db3a44c559151e66f3da1e65ef6a0bd Mon Sep 17 00:00:00 2001 From: mkucmus Date: Wed, 1 Jul 2020 13:23:59 +0200 Subject: [PATCH 1/2] feat(composables): handle the includes parameter within the product-listing endpoint --- packages/composables/src/hooks/useProductListing.ts | 3 +++ .../src/internalHelpers/includesParameter.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/composables/src/hooks/useProductListing.ts b/packages/composables/src/hooks/useProductListing.ts index 5b8956518..489cfafa7 100644 --- a/packages/composables/src/hooks/useProductListing.ts +++ b/packages/composables/src/hooks/useProductListing.ts @@ -22,6 +22,7 @@ import { getApplicationContext, } from "@shopware-pwa/composables"; import { ApplicationVueContext } from "../appContext"; +import { getProductListingIncludes } from "../internalHelpers/includesParameter"; /** * @alpha @@ -147,6 +148,8 @@ export const useProductListing = ( name: "productReviews", }, ], + // performance enhancement - fetch only the relevant fields + includes: getProductListingIncludes(), }, }; diff --git a/packages/composables/src/internalHelpers/includesParameter.ts b/packages/composables/src/internalHelpers/includesParameter.ts index d143129ae..f66f70883 100644 --- a/packages/composables/src/internalHelpers/includesParameter.ts +++ b/packages/composables/src/internalHelpers/includesParameter.ts @@ -57,3 +57,15 @@ export const getPageIncludes = () => ({ product_group_option: PRODUCT_GROUP_OPTION, product_group: PRODUCT_GROUP, }); + +/** + * Parameters for product listing - aligned with getCategoryProductsListing method of @shopware-pwa/shopware-6-client + */ +export const getProductListingIncludes = () => ({ + product: PRODUCT, + product_media: PRODUCT_MEDIA, + media: MEDIA, + calculated_price: PRODUCT_CALCULATED_PRICE, + product_group_option: PRODUCT_GROUP_OPTION, + product_group: PRODUCT_GROUP, +}); From 8256bf4b2cd40784792214d0b48538f4c567ecf0 Mon Sep 17 00:00:00 2001 From: mkucmus Date: Thu, 2 Jul 2020 15:41:33 +0200 Subject: [PATCH 2/2] Update useProductListing.ts --- packages/composables/src/hooks/useProductListing.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/composables/src/hooks/useProductListing.ts b/packages/composables/src/hooks/useProductListing.ts index 489cfafa7..889e54f81 100644 --- a/packages/composables/src/hooks/useProductListing.ts +++ b/packages/composables/src/hooks/useProductListing.ts @@ -149,6 +149,7 @@ export const useProductListing = ( }, ], // performance enhancement - fetch only the relevant fields + // TODO: https://github.com/DivanteLtd/shopware-pwa/issues/911 includes: getProductListingIncludes(), }, };