This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maciej Kucmus
committed
Oct 25, 2019
1 parent
824732d
commit c22331b
Showing
3 changed files
with
188 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,155 @@ | ||
import { SearchCriteria } from "../packages/shopware-6-client/src/interfaces/search/SearchCriteria"; | ||
import { CategoryForHeadless } from "./Resolver/CategoryForHeadless"; | ||
import { ProductForHeadless } from "./Resolver/ProductForHeadless"; | ||
import { CmsPageForHeadless } from "./Resolver/CmsPageForHeadless"; | ||
import axios from "axios"; | ||
import { PageCriteria } from "./ResolverInterface"; | ||
|
||
interface Resolver { | ||
getPageForHeadless: ( | ||
criteria: PageCriteria | ||
) => PageForHeadless< | ||
ProductForHeadless | CategoryForHeadless | CmsPageForHeadless | ||
>; | ||
} | ||
/** | ||
* use case for category | ||
*/ | ||
const getPageForHeadless = (params: PageCriteria) => | ||
axios.post("/resolver", params); | ||
|
||
interface PageForHeadless<T> { | ||
pageTypeId: PageType; | ||
pageType: string; | ||
pathInfo: string; | ||
seoPathInfo: string; | ||
isCanonical: boolean; | ||
resourceIdentifier: string; | ||
data: T; | ||
} | ||
const searchCriteria: PageCriteria = { | ||
path: "Kids-Toys/Health-Beauty", | ||
includes: ["products", "name"] | ||
}; | ||
|
||
enum PageType { | ||
category = "category", | ||
product = "product", | ||
cmsPage = "cms-page" | ||
} | ||
|
||
interface PageCriteria extends SearchCriteria { | ||
path: string; // path + other possible criteria | ||
includes?: [string]; // array of fields to be included (removes others from payload) | ||
// 1. includes might be available for associated resources as well - to consider | ||
// 2. would be awesome to have a deep mode for associations to get the deeper objects returned | ||
} | ||
!(async () => { | ||
const { data } = await getPageForHeadless(searchCriteria); | ||
// here is an output of the query. | ||
// the includes parameter for associated products should be also handled on server-side, or prepare data models (take them from ./Resolver/PageContentResolver.ts) | ||
// | ||
// data = { | ||
// pageTypeId: "category", | ||
// pathInfo: "/navigation/03dfd5badd3d43bd8a345ef660761e09", | ||
// seoPathInfo: "Kids-Toys/Health-Beauty", | ||
// isCanonical: true, | ||
// resourceIdentifier: "03dfd5badd3d43bd8a345ef660761e09", | ||
// data: { | ||
// name: "Health & Beauty", // only name and products were in includes parameter | ||
// products: [ | ||
// { | ||
// "calculatedListingPrice": {}, | ||
// "calculatedPrices": [], | ||
// "calculatedPrice": {}, | ||
// "sortedProperties": null, | ||
// "isNew": false, | ||
// "parentId": null, | ||
// "childCount": 0, | ||
// "autoIncrement": 46, | ||
// "taxId": "cc3adb9eed9a4a4b9229acd4e67f1ec8", | ||
// "manufacturerId": "8d86cc11ebd54306b1d8f7d2faaa833f", | ||
// "unitId": null, | ||
// "active": true, | ||
// "displayGroup": "c32d8f279db1897716a783e2e3b1944f", | ||
// "price": [ | ||
// { | ||
// "currencyId": "b7d2554b0ce847cd82f3ac9bd1c0dfca", | ||
// "net": 302.52100840336135, | ||
// "gross": 360, | ||
// "linked": true, | ||
// "extensions": [] | ||
// } | ||
// ], | ||
// "manufacturerNumber": null, | ||
// "ean": null, | ||
// "productNumber": "721d6d56b5084776861e60661d821ae7", | ||
// "stock": 47, | ||
// "availableStock": 47, | ||
// "available": true, | ||
// "deliveryTimeId": null, | ||
// "deliveryTime": null, | ||
// "restockTime": 3, | ||
// "isCloseout": false, | ||
// "purchaseSteps": 1, | ||
// "maxPurchase": null, | ||
// "minPurchase": 1, | ||
// "purchaseUnit": null, | ||
// "referenceUnit": null, | ||
// "shippingFree": false, | ||
// "purchasePrice": null, | ||
// "markAsTopseller": null, | ||
// "weight": null, | ||
// "width": null, | ||
// "height": null, | ||
// "length": null, | ||
// "releaseDate": null, | ||
// "categoryTree": [ | ||
// "3f637f17cd9f4891a2d7625d19fb37c9" | ||
// ], | ||
// "optionIds": null, | ||
// "propertyIds": [ | ||
// "06a7ed91305d47e1b7f3d6f7660c8316", | ||
// "0bea5d5f73b046f88f7a27415969dce4", | ||
// "1f0ae04b881342659d87c45ce68899c9", | ||
// "2d5f5d19881a4b90afdde97fbe1a6527", | ||
// "40af119c20a7428cadbc450a047c877e", | ||
// "43231c2e5de1434a8bda2ddd0cd3239c", | ||
// "50a5178bafdb4dfab3873575735d9099", | ||
// "525cf9bcae5d4ee49386e6cb7f11bc96", | ||
// "52e3c67cf79343deb2cf4dd84295989b", | ||
// "59346f081ed849db9d03d92088a0a1f1", | ||
// "6ab2226fd10345a3a8bfadc2d5a3bca4", | ||
// "81d74b7492db4e9f9be0e897e99f9ffd", | ||
// "872a36ad229f4a2bb747e8f504bd8d67", | ||
// "a5f307eb50ed48e3963988787bbfcb74", | ||
// "c7cba0fd0f0242a0afd57715a4e42fd0", | ||
// "ce0d7c8cccae452aaa5e78265c28dccb", | ||
// "d6207bc795c24a958441200528505649", | ||
// "d9231ebabf5e4e5e8695e5e5f5c9d717" | ||
// ], | ||
// "additionalText": null, | ||
// "name": "Synergistic Paper Britchies", | ||
// "keywords": null, | ||
// "description": "Eum ea nihil autem quia odio. Optio ut placeat modi voluptate et voluptatem consequatur veritatis.", | ||
// "metaTitle": null, | ||
// "packUnit": null, | ||
// "variantRestrictions": null, | ||
// "configuratorGroupConfig": null, | ||
// "tax": {}, | ||
// "manufacturer": null, | ||
// "unit": null, | ||
// "prices": [], | ||
// "listingPrices": [], | ||
// "cover": null, | ||
// "parent": null, | ||
// "children": null, | ||
// "media": null, | ||
// "searchKeywords": null, | ||
// "translations": null, | ||
// "categories": null, | ||
// "tags": null, | ||
// "properties": null, | ||
// "options": null, | ||
// "configuratorSettings": null, | ||
// "categoriesRo": null, | ||
// "coverId": "7c8a5bc4c8b841e0bc363ab08c890059", | ||
// "blacklistIds": null, | ||
// "whitelistIds": null, | ||
// "customFields": null, | ||
// "visibilities": null, | ||
// "tagIds": null, | ||
// "productReviews": null, | ||
// "ratingAverage": null, | ||
// "mainCategories": null, | ||
// "_uniqueIdentifier": "f7efff51718d4592b6d655b83d16f1db", | ||
// "versionId": "0fa91ce3e96a4bc2be4bd9ce752c3425", | ||
// "translated": { | ||
// "additionalText": null, | ||
// "name": "Synergistic Paper Britchies", | ||
// "keywords": null, | ||
// "description": "Eum ea nihil autem quia odio. Optio ut placeat modi voluptate et voluptatem consequatur veritatis.", | ||
// "metaTitle": null, | ||
// "packUnit": null, | ||
// "customFields": [] | ||
// }, | ||
// "createdAt": "2019-10-08T09:42:16+00:00", | ||
// "updatedAt": null, | ||
// "extensions": [], | ||
// "id": "f7efff51718d4592b6d655b83d16f1db", | ||
// "parentVersionId": "0fa91ce3e96a4bc2be4bd9ce752c3425", | ||
// "productManufacturerVersionId": "0fa91ce3e96a4bc2be4bd9ce752c3425", | ||
// "productMediaVersionId": null | ||
// } | ||
// ] | ||
// } | ||
// } | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { SearchCriteria } from "@shopware-pwa/shopware-6-client/src/interfaces/search/SearchCriteria"; | ||
import { CategoryForHeadless } from "./Resolver/CategoryForHeadless"; | ||
import { ProductForHeadless } from "./Resolver/ProductForHeadless"; | ||
import { CmsPageForHeadless } from "./Resolver/CmsPageForHeadless"; | ||
|
||
export interface Resolver { | ||
getPageForHeadless: ( | ||
criteria: PageCriteria | ||
) => PageForHeadless< | ||
ProductForHeadless | CategoryForHeadless | CmsPageForHeadless | ||
>; | ||
} | ||
|
||
export interface PageForHeadless<T> { | ||
pageTypeId: PageType; | ||
// pageType: string; | ||
pathInfo: string; | ||
seoPathInfo: string; | ||
isCanonical: boolean; | ||
resourceIdentifier: string; | ||
data: T; | ||
} | ||
|
||
enum PageType { | ||
category = "category", | ||
product = "product", | ||
cmsPage = "cms-page" | ||
} | ||
|
||
export interface PageCriteria extends SearchCriteria { | ||
path: string; // path + other possible criteria | ||
includes?: Array<string>; // array of fields to be included (removes others from payload) | ||
// 1. includes might be available for associated resources as well - to consider | ||
// 2. would be awesome to have a deep mode for associations to get the deeper objects returned | ||
} |