From 5b508e779bc97a84269eea62071aa7f6ba5dc6e4 Mon Sep 17 00:00:00 2001 From: Wojciech Sikora Date: Wed, 17 Apr 2024 12:17:56 +0200 Subject: [PATCH 1/2] docs: document usage of middlewareModule with Magento 2 integration --- .../2.getting-started/1.quick-start.md | 121 ++++++++---------- .../2.getting-started/3.supported-features.md | 4 + docs/content/3.basics/1.products.md | 12 +- docs/content/3.basics/2.cart.md | 18 +-- docs/content/3.basics/3.authenthication.md | 2 +- docs/content/3.basics/4.users.md | 10 +- docs/content/3.basics/5.wishlist.md | 6 +- docs/content/3.basics/6.checkout.md | 22 ++-- docs/content/3.basics/7.misc.md | 28 ++-- docs/content/4.advanced/custom-queries.md | 59 +++++---- 10 files changed, 135 insertions(+), 147 deletions(-) diff --git a/docs/content/2.getting-started/1.quick-start.md b/docs/content/2.getting-started/1.quick-start.md index 2e54f6599..377fe6a15 100644 --- a/docs/content/2.getting-started/1.quick-start.md +++ b/docs/content/2.getting-started/1.quick-start.md @@ -4,7 +4,6 @@ Your Alokai application has two parts: 1. **Server Middleware** - an Express.js application that can connect to your various third-party services (like Magento). - 2. **Front-end application** - any application using JavaScript or TypeScript that can connect to the server middleware. Popular choices include [Nuxt](https://nuxt.com/) and [Next.js](https://nextjs.org/). In this section, we will explain in a step-by-step guide how to use Magento 2 integration in each part of your Alokai application. @@ -22,7 +21,6 @@ Learn more about the SDK in our [Key concepts: SDK](/sdk) docs. - Magento configured - if you don't have your Magento 2 configured, see our [Magento Installation](./magento.md) guide. - Install Node.js version >=16.0 - ## Server Middleware The first step to setup your integration is to create and configure your server middleware layer to connect to your Magento 2 backend. @@ -33,11 +31,10 @@ For an example of a generic server middleware configuration, check out one of [o If you have the server middleware configured, you can move directly to the [SDK preparation](./quick-start.md#configuring-the-sdk) part. ::: - 1. Install the dependencies needed to create your server middleware and to create a server-to-server connection with the Magento 2 backend and the server middleware. ```bash -yarn add @vue-storefront/middleware @vue-storefront/magento-api +yarn add @vue-storefront/middleware @vue-storefront/magento-api # npm install @vue-storefront/middleware @vue-storefront/magento-api @@ -49,53 +46,53 @@ yarn add @vue-storefront/middleware @vue-storefront/magento-api ```javascript // middleware.config.js -import {config} from "dotenv"; +import { config } from "dotenv"; config(); const cookieNames = { - currencyCookieName: 'vsf-currency', - countryCookieName: 'vsf-country', - localeCookieName: 'vsf-locale', - cartCookieName: 'vsf-cart', - customerCookieName: 'vsf-customer', - storeCookieName: 'vsf-store', - messageCookieName: 'vsf-message' + currencyCookieName: "vsf-currency", + countryCookieName: "vsf-country", + localeCookieName: "vsf-locale", + cartCookieName: "vsf-cart", + customerCookieName: "vsf-customer", + storeCookieName: "vsf-store", + messageCookieName: "vsf-message", }; export const integrations = { magento: { - location: '@vue-storefront/magento-api/server', - configuration: { - api: process.env.VSF_MAGENTO_GRAPHQL_URL, - cookies: { - ...cookieNames, - }, - cookiesDefaultOpts: { - httpOnly: process.env.VSF_COOKIE_HTTP_ONLY || false, - secure: process.env.VSF_COOKIE_SECURE || false, - sameSite: process.env.VSF_COOKIE_SAME_SITE || 'lax', - path: process.env.VSF_COOKIE_PATH || '/', - }, - defaultStore: 'default', - customApolloHttpLinkOptions: { - useGETForQueries: true, - }, - magentoBaseUrl: process.env.VSF_MAGENTO_BASE_URL, - magentoApiEndpoint: process.env.VSF_MAGENTO_GRAPHQL_URL, - imageProvider: process.env.NUXT_IMAGE_PROVIDER, - recaptcha: { - isEnabled: process.env.VSF_RECAPTCHA_ENABLED === 'true', - sitekey: process.env.VSF_RECAPTCHA_SITE_KEY, - secretkey: process.env.VSF_RECAPTCHA_SECRET_KEY, - version: process.env.VSF_RECAPTCHA_VERSION, - score: process.env.VSF_RECAPTCHA_MIN_SCORE, - }, - customer: { - customer_create_account_confirm: true, - }, + location: "@vue-storefront/magento-api/server", + configuration: { + api: process.env.VSF_MAGENTO_GRAPHQL_URL, + cookies: { + ...cookieNames, + }, + cookiesDefaultOpts: { + httpOnly: process.env.VSF_COOKIE_HTTP_ONLY || false, + secure: process.env.VSF_COOKIE_SECURE || false, + sameSite: process.env.VSF_COOKIE_SAME_SITE || "lax", + path: process.env.VSF_COOKIE_PATH || "/", }, - } + defaultStore: "default", + customApolloHttpLinkOptions: { + useGETForQueries: true, + }, + magentoBaseUrl: process.env.VSF_MAGENTO_BASE_URL, + magentoApiEndpoint: process.env.VSF_MAGENTO_GRAPHQL_URL, + imageProvider: process.env.NUXT_IMAGE_PROVIDER, + recaptcha: { + isEnabled: process.env.VSF_RECAPTCHA_ENABLED === "true", + sitekey: process.env.VSF_RECAPTCHA_SITE_KEY, + secretkey: process.env.VSF_RECAPTCHA_SECRET_KEY, + version: process.env.VSF_RECAPTCHA_VERSION, + score: process.env.VSF_RECAPTCHA_MIN_SCORE, + }, + customer: { + customer_create_account_confirm: true, + }, + }, + }, }; ``` @@ -124,9 +121,9 @@ NUXT_IMAGE_PROVIDER=ipx ```javascript // middleware.js -import {createServer} from "@vue-storefront/middleware"; -import {integrations} from "./middleware.config.js"; -import cors from 'cors'; +import { createServer } from "@vue-storefront/middleware"; +import { integrations } from "./middleware.config.js"; +import cors from "cors"; (async () => { const app = await createServer({ integrations }); @@ -150,7 +147,6 @@ import cors from 'cors'; console.log(`Middleware started: ${host}:${port}`); }); })(); - ``` 5. Your middleware is ready. You can start it by running `node middleware.js`. Most likely, you'll want to setup this command as a script in your `package.json` file. @@ -167,40 +163,29 @@ import cors from 'cors'; ## Configuring the SDK -Now, let's configure the SDK in the frontend part of your application to communicate with the server middleware. +Now, let's configure the SDK in the frontend part of your application to communicate with the server middleware. -1. Install the SDK package and the Magento 2 module. These packages will allow you to create an instance of the SDK and then extend it with methods to communicate with Magento 2 via your server middleware. - -```bash -yarn add @vue-storefront/sdk @vue-storefront/magento-sdk - -# npm install @vue-storefront/sdk @vue-storefront/magento-sdk - -# pnpm install @vue-storefront/sdk @vue-storefront/magento-sdk -``` - -2. Initialize the SDK. Configure Magento 2 module with `apiUrl` that points to the server middleware. +1. Initialize the SDK. Configure `middlewareModule` with `apiUrl` that points to the Magento 2 integration in the Alokai Middleware. ```ts -import { buildModule, initSDK } from '@vue-storefront/sdk'; -import { magentoModule, MagentoModuleType } from '@vue-storefront/sdk/magento-sdk'; +import { buildModule, initSDK, middlewareModule } from "@vue-storefront/sdk"; +import { Endpoints } from "@vue-storefront/magento-api"; const sdkConfig = { - magento: buildModule(magentoModule, { - apiUrl: 'http://localhost:8181/magento' - }) + magento: buildModule(middlewareModule, { + apiUrl: "http://localhost:8181/magento", + }), }; -export const sdk = initSDK(sdkConfig); +export const sdk = initSDK(sdkConfig); ``` - +2. Your SDK is ready! You can now import it in the different parts of your frontend application and call methods with `sdk.magento.`. To see a full list of methods offered by the Magento 2 integration, check out the [API Reference](/integrations/magento/api/magento-api). For example, we can call the `products` method to fetch products from Magento 2. ```ts -import { sdk } from './sdk'; -const products = await sdk.magento.products({}) +import { sdk } from "./sdk"; +const products = await sdk.magento.products({}); // returns ProductInterface[] - ``` diff --git a/docs/content/2.getting-started/3.supported-features.md b/docs/content/2.getting-started/3.supported-features.md index be97cb0b8..018d4c632 100644 --- a/docs/content/2.getting-started/3.supported-features.md +++ b/docs/content/2.getting-started/3.supported-features.md @@ -2,6 +2,10 @@ This page lists the Magento 2 features supported by this integration. +:::tip API Reference +You can find all available SAPCC module methods, their description and examples in the [API Reference](/integrations/magento/api/magento-api). +::: + ## Product types | Feature | Is supported | Additional comments | diff --git a/docs/content/3.basics/1.products.md b/docs/content/3.basics/1.products.md index 0e7c91536..39876884a 100644 --- a/docs/content/3.basics/1.products.md +++ b/docs/content/3.basics/1.products.md @@ -3,17 +3,17 @@ In this section, we will cover the basics of products. We will show you how to fetch products from in a variety of ways. ## Overview -There are two main functions to fetch products from Magento 2: [productDetails](../api/magento-sdk/productDetails) and [products](../api/magento-sdk/products). Both are very similar and accept the same arguments. The main difference is in the reponse they return. The [productDetails](../api/magento-sdk/productDetails) method returns a single product related data, while the [products](../reference/api/magento-sdk/products) method returns a list of products related data. +There are two main functions to fetch products from Magento 2: [productDetails](/integrations/magento/api/magento-api/productDetails) and [products](/integrations/magento/api/magento-api/products). Both are very similar and accept the same arguments. The main difference is in the reponse they return. The [productDetails](/integrations/magento/api/magento-api/productDetails) method returns a single product related data, while the [products](/integrations/magento/api/magento-api/products) method returns a list of products related data. The first one is optimized to be used on single product pages, while the second one is optimized to be used on product list pages like category pages, search results pages, etc. ## References | Method | Description | |--------------------------------------------------------------------|--------------------------------| -| [productDetails](../api/magento-sdk/productDetails) | Method to fetch product details | -| [products](../api/magento-sdk/products) | Method to fetch products | -| [relatedProducts](../api/magento-sdk/relatedProducts) | Method to fetch related products | -| [upsellProducts](../api/magento-sdk/upsellProducts) | Method to fetch upsell products | -| [productReview](../api/magento-sdk/productReview) | Method to fetch reviews | +| [productDetails](/integrations/magento/api/magento-api/productDetails) | Method to fetch product details | +| [products](/integrations/magento/api/magento-api/products) | Method to fetch products | +| [relatedProducts](/integrations/magento/api/magento-api/relatedProducts) | Method to fetch related products | +| [upsellProducts](/integrations/magento/api/magento-api/upsellProducts) | Method to fetch upsell products | +| [productReview](/integrations/magento/api/magento-api/productReview) | Method to fetch reviews | diff --git a/docs/content/3.basics/2.cart.md b/docs/content/3.basics/2.cart.md index de93b7986..7bfc4bcd0 100644 --- a/docs/content/3.basics/2.cart.md +++ b/docs/content/3.basics/2.cart.md @@ -14,15 +14,15 @@ Using listed method you can implement the full cart functionality in your storef ## References | Method | Description | |------------------------------------------------------------------------------|----------------------------------------------------| -| [cart](../api/magento-sdk/cart) | Method to fetch/guestrt data | -| [customerCart](../api/magento-sdk/customerCart) | Method to fetch logged in customer cart data | -| [createEmptyCart](../api/magento-sdk/createEmptyCart) | Method to create a new cart | -| [updateCartItems](../api/magento-sdk/updateCartItems) | Method to update cart items | -| [removeItemFromCart](../api/magento-sdk/removeItemFromCart) | Method to remove item from cart | -| [applyCouponToCart](../api/magento-sdk/applyCouponToCart) | Method to apply coupon to cart | -| [removeCouponFromCart](../api/magento-sdk/removeCouponFromCart) | Method to remove coupon from cart | -| [cartTotalQty](../api/magento-sdk/cartTotalQty) | Method to fetch cart total items quantity | -| [mergeCarts](../api/magento-sdk/mergeCarts) | Method to merge guest and logged in customer carts | +| [cart](/integrations/magento/api/magento-api/cart) | Method to fetch/guestrt data | +| [customerCart](/integrations/magento/api/magento-api/customerCart) | Method to fetch logged in customer cart data | +| [createEmptyCart](/integrations/magento/api/magento-api/createEmptyCart) | Method to create a new cart | +| [updateCartItems](/integrations/magento/api/magento-api/updateCartItems) | Method to update cart items | +| [removeItemFromCart](/integrations/magento/api/magento-api/removeItemFromCart) | Method to remove item from cart | +| [applyCouponToCart](/integrations/magento/api/magento-api/applyCouponToCart) | Method to apply coupon to cart | +| [removeCouponFromCart](/integrations/magento/api/magento-api/removeCouponFromCart) | Method to remove coupon from cart | +| [cartTotalQty](/integrations/magento/api/magento-api/cartTotalQty) | Method to fetch cart total items quantity | +| [mergeCarts](/integrations/magento/api/magento-api/mergeCarts) | Method to merge guest and logged in customer carts | diff --git a/docs/content/3.basics/3.authenthication.md b/docs/content/3.basics/3.authenthication.md index 83bcc3b58..4adf3b01a 100644 --- a/docs/content/3.basics/3.authenthication.md +++ b/docs/content/3.basics/3.authenthication.md @@ -15,4 +15,4 @@ Methods like `customer`, `customerCart`, `updateCustomer`, `changeCustomerPasswo ## References | Method | Description | |-----------------------------------------------------------------------|-----------------------------------| -| [generateCustomerToken](/integrations/magento/api/magento-sdk/generateCustomerToken) | Method to generate customer token | +| [generateCustomerToken](/integrations/magento/api/magento-api/generateCustomerToken) | Method to generate customer token | diff --git a/docs/content/3.basics/4.users.md b/docs/content/3.basics/4.users.md index e3cf1a00b..eef8b2db0 100644 --- a/docs/content/3.basics/4.users.md +++ b/docs/content/3.basics/4.users.md @@ -11,11 +11,11 @@ Methods in this section helps you to implement full user functionality in your s ## References | Method | Description | |----------------------------------------------------------------------------------|------------------------------------| -| [customer](../api/magento-sdk/customer) | Method to fetch customer data | -| [createCustomer](../api/magento-sdk/createCustomer) | Method to create new customer | -| [updateCustomer](../api/magento-sdk/updateCustomer) | Method to update customer | -| [changeCustomerPassword](../api/magento-sdk/changeCustomerPassword) | Method to change customer password | -| [createCustomerAddress](../api/magento-sdk/createCustomerAddress) | Method to create customer address | +| [customer](/integrations/magento/api/magento-api/customer) | Method to fetch customer data | +| [createCustomer](/integrations/magento/api/magento-api/createCustomer) | Method to create new customer | +| [updateCustomer](/integrations/magento/api/magento-api/updateCustomer) | Method to update customer | +| [changeCustomerPassword](/integrations/magento/api/magento-api/changeCustomerPassword) | Method to change customer password | +| [createCustomerAddress](/integrations/magento/api/magento-api/createCustomerAddress) | Method to create customer address | diff --git a/docs/content/3.basics/5.wishlist.md b/docs/content/3.basics/5.wishlist.md index 2fbc3a296..c229b5078 100644 --- a/docs/content/3.basics/5.wishlist.md +++ b/docs/content/3.basics/5.wishlist.md @@ -11,6 +11,6 @@ Because only logged in users can have a wishlist, all methods in this section re ## References | Method | Description | |------------------------------------------------------------------------------------|----------------------------------------------| -| [addProductToWishlist](../api/magento-sdk/addProductToWishList) | Method to add a product to wishlist | -| [removeProductsFromWishlist](../api/magento-sdk/removeProductsFromWishlist) | Method to remove a product to wishlist | -| [wishlistItemsCount](../api/magento-sdk/wishlistItemsCount) | Method to get items quantity in the wishlist | +| [addProductToWishlist](/integrations/magento/api/magento-api/addProductToWishList) | Method to add a product to wishlist | +| [removeProductsFromWishlist](/integrations/magento/api/magento-api/removeProductsFromWishlist) | Method to remove a product to wishlist | +| [wishlistItemsCount](/integrations/magento/api/magento-api/wishlistItemsCount) | Method to get items quantity in the wishlist | diff --git a/docs/content/3.basics/6.checkout.md b/docs/content/3.basics/6.checkout.md index ed6501a9c..65975475b 100644 --- a/docs/content/3.basics/6.checkout.md +++ b/docs/content/3.basics/6.checkout.md @@ -10,14 +10,14 @@ We provide a set of methods that allow you to implement the full checkout functi | Method | Description | |--------------------------------------------------------------------------------------------------------------|----------------------------------------------------| -| [getAvailableShippingMethods](../api/magento-sdk/getAvailableShippingMethods) | Method to fetch guest available shipping methods | -| [getAvailablePaymentMethods](../api/magento-sdk/getAvailablePaymentMethods) | Method to fetch guest available payment methods | -| [getAvailableCustomerShippingMethods](../api/magento-sdk/getAvailableCustomerShippingMethods) | Method to fetch customer available sipping methods | -| [getAvailableCustomerPaymentMethods](../api/magento-sdk/getAvailableCustomerPaymentMethods) | Method to fetch customer available payment methods | -| [getCustomerAddresses](../api/magento-sdk/getCustomerAddresses) | Method to fetch customer addresses | -| [setShippingAddressesOnCart](../api/magento-sdk/setShippingAddressesOnCart) | Method to set shipping addresses on cart | -| [setBillingAddressOnCart](../api/magento-sdk/setBillingAddressOnCart) | Method to set billing addresse on cart | -| [setShippingMethodsOnCart](../api/magento-sdk/setShippingMethodsOnCart) | Method to set shipping methods on cart | -| [setPaymentMethodOnCart](../api/magento-sdk/setPaymentMethodOnCart) | Method to set payment method on cart | -| [setGuestEmailOnCart](../api/magento-sdk/setGuestEmailOnCart) | Method to set email on the guest cart | -| [placeOrder](../api/magento-sdk/placeOrder) | Method to place an order | +| [getAvailableShippingMethods](/integrations/magento/api/magento-api/getAvailableShippingMethods) | Method to fetch guest available shipping methods | +| [getAvailablePaymentMethods](/integrations/magento/api/magento-api/getAvailablePaymentMethods) | Method to fetch guest available payment methods | +| [getAvailableCustomerShippingMethods](/integrations/magento/api/magento-api/getAvailableCustomerShippingMethods) | Method to fetch customer available sipping methods | +| [getAvailableCustomerPaymentMethods](/integrations/magento/api/magento-api/getAvailableCustomerPaymentMethods) | Method to fetch customer available payment methods | +| [getCustomerAddresses](/integrations/magento/api/magento-api/getCustomerAddresses) | Method to fetch customer addresses | +| [setShippingAddressesOnCart](/integrations/magento/api/magento-api/setShippingAddressesOnCart) | Method to set shipping addresses on cart | +| [setBillingAddressOnCart](/integrations/magento/api/magento-api/setBillingAddressOnCart) | Method to set billing addresse on cart | +| [setShippingMethodsOnCart](/integrations/magento/api/magento-api/setShippingMethodsOnCart) | Method to set shipping methods on cart | +| [setPaymentMethodOnCart](/integrations/magento/api/magento-api/setPaymentMethodOnCart) | Method to set payment method on cart | +| [setGuestEmailOnCart](/integrations/magento/api/magento-api/setGuestEmailOnCart) | Method to set email on the guest cart | +| [placeOrder](/integrations/magento/api/magento-api/placeOrder) | Method to place an order | diff --git a/docs/content/3.basics/7.misc.md b/docs/content/3.basics/7.misc.md index 00bf5cb1b..d8a71ee60 100644 --- a/docs/content/3.basics/7.misc.md +++ b/docs/content/3.basics/7.misc.md @@ -8,50 +8,50 @@ Methdos in this section are used to fetch various configuration data. | Method | Description | |--------------------------------------------------------------------|----------------------------------| -| [availableStores](../api/magento-sdk/availableStores) | Method to fetch available stores | -| [countries](../api/magento-sdk/countries) | Method to fetch available countries | -| [currency](../api/magento-sdk/currency) | Method to fetch available currency | -| [storeConfig](../api/magento-sdk/storeConfig) | Method to fetch available storeConfig | +| [availableStores](/integrations/magento/api/magento-api/availableStores) | Method to fetch available stores | +| [countries](/integrations/magento/api/magento-api/countries) | Method to fetch available countries | +| [currency](/integrations/magento/api/magento-api/currency) | Method to fetch available currency | +| [storeConfig](/integrations/magento/api/magento-api/storeConfig) | Method to fetch available storeConfig | ### CMS Methods in this section are used to fetch CMS data. | Method | Description | |--------------------------------------------------------------------|----------------------------------| -| [cmsBlocks](../api/magento-sdk/cmsBlocks) | Method to fetch cms blocks | -| [cmsPage](../api/magento-sdk/cmsPage) | Method to fetch cms page | +| [cmsBlocks](/integrations/magento/api/magento-api/cmsBlocks) | Method to fetch cms blocks | +| [cmsPage](/integrations/magento/api/magento-api/cmsPage) | Method to fetch cms page | ### Routing Methods in this section are used to fetch routing data. | Method | Description | |----------------------------------------------|-----------------------------------| -| [route](../api/magento-sdk/route) | Method to fetch route object data | +| [route](/integrations/magento/api/magento-api/route) | Method to fetch route object data | ### Customer reviews Methods in this section are used to fetch customer reviews data. | Method | Description | |----------------------------------------------------------------------------------------------|---------------------------------------------| -| [createProductReview](../api/magento-sdk/createProductReview) | Method to create product review | -| [productReview](../api/magento-sdk/productReview) | Method to fetch product review | -| [reviews](../api/magento-sdk/reviews) | Method to fetch reviews created by customer | -| [productReviewRatingsMetadata](../api/magento-sdk/productReviewRatingsMetadata) | Method to fetch product reviews metadata | +| [createProductReview](/integrations/magento/api/magento-api/createProductReview) | Method to create product review | +| [productReview](/integrations/magento/api/magento-api/productReview) | Method to fetch product review | +| [reviews](/integrations/magento/api/magento-api/reviews) | Method to fetch reviews created by customer | +| [productReviewRatingsMetadata](/integrations/magento/api/magento-api/productReviewRatingsMetadata) | Method to fetch product reviews metadata | ### Newsletter Methods in this section are used to fetch newsletter data. | Method | Description | |-------------------------------------------------------------------------------------|------------------------------------------| -| [subscribeEmailToNewsletter](../api/magento-sdk/subscribeEmailToNewsletter) | Method to subscribe to newsletter | +| [subscribeEmailToNewsletter](/integrations/magento/api/magento-api/subscribeEmailToNewsletter) | Method to subscribe to newsletter | ### Custom Queries Methods in this section are used to create custom queries and mutations. | Method | Description | |------------------------------------------------------------|------------------------------------| -| [customQuery](../api/magento-sdk/customQuery) | Method to create a custom query | -| [customMutation](../api/magento-sdk/customMutation) | Method to create a custom mutation | +| [customQuery](/integrations/magento/api/magento-api/customQuery) | Method to create a custom query | +| [customMutation](/integrations/magento/api/magento-api/customMutation) | Method to create a custom mutation | diff --git a/docs/content/4.advanced/custom-queries.md b/docs/content/4.advanced/custom-queries.md index 3173fea66..fc1d88263 100644 --- a/docs/content/4.advanced/custom-queries.md +++ b/docs/content/4.advanced/custom-queries.md @@ -4,11 +4,11 @@ Sometimes, you may need to fetch data from the API that is not covered by the default methods. In this case, you can use the the custom queries feature to extend defaults by your own GraphQL queries. - Creating a custom query requires a few steps: -* adding a custom query to the `middleware.config.js` file, -* (optional) overwriting the default response interface. -* using the custom query in the method. + +- adding a custom query to the `middleware.config.js` file, +- (optional) overwriting the default response interface. +- using the custom query in the method. ## Custom queries in middleware.config.js @@ -19,24 +19,27 @@ In the example below, we are adding a custom query called `customer-custom-query ```ts // middleware.config.js -module.exports = { - integrations: { - magento: { +// ... + +export const integrations = { + magento: { + location: "@vue-storefront/magento-api/server", + configuration: { // ... - customQueries: { - 'customer-custom-query': ({ query, variables, metadata }) => ({ - variables, - query: ` + }, + customQueries: { + "customer-custom-query": ({ query, variables, metadata }) => ({ + variables, + query: ` query customer { customer { ${metadata.fields} } } - ` - }), - } - } - } + `, + }), + }, + }, }; ``` @@ -51,30 +54,26 @@ Notice how we are using the type parameter to overwrite the default response int ::: ```ts -import { sdk } from '~/sdk.config.ts'; +import { sdk } from "~/sdk.config.ts"; type CustomerCustomQueryResponse = { customer: { email: string; firstname: string; lastname: string; - } -} + }; +}; const customQuery = { - customer: 'customer-custom-query', + customer: "customer-custom-query", metadata: { - fields: 'email firstname lastname' - } + fields: "email firstname lastname", + }, }; // We assume that token was already fetched and stored in the `token` variable. -const result = await sdk.magento.customer({ - customQuery, - customHeaders: { Authorization: `Bearer ${token}` } -}); +const result = await sdk.magento.customer( + customQuery, + customHeaders: { Authorization: `Bearer ${token}` }, +); ``` - - From e46e482c3f6447e2a01c618d14a8343d3ffc701e Mon Sep 17 00:00:00 2001 From: Wojciech Sikora <35867383+WojtekTheWebDev@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:44:47 +0200 Subject: [PATCH 2/2] Update docs/content/2.getting-started/3.supported-features.md Co-authored-by: Matt Maribojoc --- docs/content/2.getting-started/3.supported-features.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/2.getting-started/3.supported-features.md b/docs/content/2.getting-started/3.supported-features.md index 018d4c632..656d222bf 100644 --- a/docs/content/2.getting-started/3.supported-features.md +++ b/docs/content/2.getting-started/3.supported-features.md @@ -3,7 +3,7 @@ This page lists the Magento 2 features supported by this integration. :::tip API Reference -You can find all available SAPCC module methods, their description and examples in the [API Reference](/integrations/magento/api/magento-api). +You can find descriptions and examples for all of the available SAPCC module methods in the [API Reference](/integrations/magento/api/magento-api). ::: ## Product types