import { ComposableFunctionArgs , Context , Logger , ProductsSearchParams , } from '@vue-storefront/core' ; import { GetProductSearchParams , RelatedProductQuery , } from '@vue-storefront/magento-api' ; import { UseRelatedProducts } from '../../types/composables' ; import { useRelatedProductsFactory , UseRelatedProductsFactoryParams , } from '../../factories/useRelatedProductsFactory' ; const factoryParams = { productsSearch : async ( context , params ) => { Logger . debug ( '[Magento] Load related products based on ' , { params } ) ; const { customQuery , ... searchParams } = params ; const { data } = await context . $magento . api . relatedProduct ( searchParams as GetProductSearchParams ) ; Logger . debug ( '[Result]:' , { data } ) ; return data . products ?. items [ 0 ] ?. related_products ; } , } ; const useRelatedProducts = useRelatedProductsFactory < RelatedProductQuery [ 'products' ] [ 'items' ] [ 0 ] [ 'related_products' ] , ProductsSearchParams > ( factoryParams ) ; export default useRelatedProducts ;