mirror of
https://github.com/vercel/commerce.git
synced 2025-07-04 12:11:22 +00:00
Product detail (#5)
* remove unused imports and localhost added as a local domain * Logo, Favicon and copyrights changed * Logo, Favicon and copyrights changed * Product Details page
This commit is contained in:
parent
66d8737fe6
commit
60f3c68e7e
@ -1,13 +1,22 @@
|
|||||||
import data from '../../data.json'
|
import data from '../../data.json'
|
||||||
|
import { gateway as MoltinGateway } from '@moltin/sdk'
|
||||||
|
import normalizeProduct from '../../utils/normalize'
|
||||||
|
|
||||||
|
const Moltin = MoltinGateway({
|
||||||
|
client_id: process.env.NEXT_PUBLIC_ELASTICPATH_CLIENTID
|
||||||
|
})
|
||||||
|
|
||||||
export type GetAllProductPathsResult = {
|
export type GetAllProductPathsResult = {
|
||||||
products: Array<{ path: string }>
|
products: Array<{ path: string }>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function getAllProductPathsOperation() {
|
export default function getAllProductPathsOperation() {
|
||||||
function getAllProductPaths(): Promise<GetAllProductPathsResult> {
|
async function getAllProductPaths(): Promise<GetAllProductPathsResult> {
|
||||||
return Promise.resolve({
|
let products = await Moltin.Products.Limit(200).All();
|
||||||
products: data.products.map(({ path }) => ({ path })),
|
let normalizeProducts = await normalizeProduct(products.data)
|
||||||
|
let productPaths = normalizeProducts.map(({ path }) => ({ path }));
|
||||||
|
return await Promise.resolve({
|
||||||
|
products: productPaths
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ export default function getAllProductsOperation({
|
|||||||
let normalizeProducts = await normalizeProduct(products.data)
|
let normalizeProducts = await normalizeProduct(products.data)
|
||||||
return {
|
return {
|
||||||
products: normalizeProducts,
|
products: normalizeProducts,
|
||||||
|
// products: data.products,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getAllProducts
|
return getAllProducts
|
||||||
|
@ -3,6 +3,12 @@ import { Product } from '@commerce/types/product'
|
|||||||
import { GetProductOperation } from '@commerce/types/product'
|
import { GetProductOperation } from '@commerce/types/product'
|
||||||
import data from '../../data.json'
|
import data from '../../data.json'
|
||||||
import type { OperationContext } from '@commerce/api/operations'
|
import type { OperationContext } from '@commerce/api/operations'
|
||||||
|
import { gateway as MoltinGateway } from '@moltin/sdk'
|
||||||
|
import normalizeProduct from '../../utils/normalize'
|
||||||
|
|
||||||
|
const Moltin = MoltinGateway({
|
||||||
|
client_id: process.env.NEXT_PUBLIC_ELASTICPATH_CLIENTID
|
||||||
|
})
|
||||||
|
|
||||||
export default function getProductOperation({
|
export default function getProductOperation({
|
||||||
commerce,
|
commerce,
|
||||||
@ -17,8 +23,22 @@ export default function getProductOperation({
|
|||||||
config?: Partial<ElasticpathConfig>
|
config?: Partial<ElasticpathConfig>
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
} = {}): Promise<Product | {} | any> {
|
} = {}): Promise<Product | {} | any> {
|
||||||
|
let variablesS = ''
|
||||||
|
if (typeof variables?.slug == "undefined") {
|
||||||
|
variablesS = ''
|
||||||
|
} else {
|
||||||
|
variablesS = variables.slug;
|
||||||
|
}
|
||||||
|
let products = await Moltin.Products.Filter({
|
||||||
|
eq: {
|
||||||
|
slug: variablesS
|
||||||
|
}
|
||||||
|
}).All();
|
||||||
|
let normalizeProducts = await normalizeProduct(products.data)
|
||||||
|
let productSlugs = normalizeProducts.find(({ slug }) => slug === variables!.slug);
|
||||||
return {
|
return {
|
||||||
product: data.products.find(({ slug }) => slug === variables!.slug),
|
// product: data.products.find(({ slug }) => slug === variables!.slug),
|
||||||
|
product: productSlugs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,21 +28,37 @@ const normalizeProduct = async(products) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const normalizeProductVariants = (productVariants) => {
|
const normalizeProductVariants = (productVariants) => {
|
||||||
return '';
|
return [
|
||||||
|
{
|
||||||
|
"id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjAss=",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"__typename": "MultipleChoiceOption",
|
||||||
|
"id": "asd",
|
||||||
|
"displayName": "Size",
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"label": "XL"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let index in products) {
|
for (let index in products) {
|
||||||
let product = products[index];
|
let product = products[index];
|
||||||
|
|
||||||
normalizeProducts.push({
|
normalizeProducts.push({
|
||||||
"id": product.hasOwnProperty("id") ? product.id : null,
|
"id": product.hasOwnProperty("id") ? product.id : '',
|
||||||
"name": product.hasOwnProperty("name") ? product.name : null,
|
"name": product.hasOwnProperty("name") ? product.name : '',
|
||||||
"vendor": "trika",
|
"vendor": "trika",
|
||||||
"path": product.hasOwnProperty("name") ? "/" + product.name : null,
|
"path": product.hasOwnProperty("slug") ? "/" + product.slug : '',
|
||||||
"slug": `${product.hasOwnProperty("slug") ? product.slug:null}`,
|
"slug": `${product.hasOwnProperty("slug") ? product.slug:''}`,
|
||||||
"price": {
|
"price": {
|
||||||
"value": product.hasOwnProperty("price") ? product.price[0].hasOwnProperty("amount") ? product.price[0].amount : null : null,
|
"value": product.hasOwnProperty("price") ? product.price[0].hasOwnProperty("amount") ? product.price[0].amount : '' : '',
|
||||||
"currencyCode": product.hasOwnProperty("price") ? product.price[0].hasOwnProperty("currency") ? product.price[0].currency : null : null
|
"currencyCode": product.hasOwnProperty("price") ? product.price[0].hasOwnProperty("currency") ? product.price[0].currency : '' : ''
|
||||||
},
|
},
|
||||||
"descriptionHtml": product.hasOwnProperty("description") ? product.description : null,
|
"descriptionHtml": product.hasOwnProperty("description") ? product.description : null,
|
||||||
"images": [{
|
"images": [{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user