mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +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 { 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 = {
|
||||
products: Array<{ path: string }>
|
||||
}
|
||||
|
||||
export default function getAllProductPathsOperation() {
|
||||
function getAllProductPaths(): Promise<GetAllProductPathsResult> {
|
||||
return Promise.resolve({
|
||||
products: data.products.map(({ path }) => ({ path })),
|
||||
async function getAllProductPaths(): Promise<GetAllProductPathsResult> {
|
||||
let products = await Moltin.Products.Limit(200).All();
|
||||
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)
|
||||
return {
|
||||
products: normalizeProducts,
|
||||
// products: data.products,
|
||||
}
|
||||
}
|
||||
return getAllProducts
|
||||
|
@ -3,6 +3,12 @@ import { Product } from '@commerce/types/product'
|
||||
import { GetProductOperation } from '@commerce/types/product'
|
||||
import data from '../../data.json'
|
||||
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({
|
||||
commerce,
|
||||
@ -17,8 +23,22 @@ export default function getProductOperation({
|
||||
config?: Partial<ElasticpathConfig>
|
||||
preview?: boolean
|
||||
} = {}): 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 {
|
||||
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) => {
|
||||
return '';
|
||||
return [
|
||||
{
|
||||
"id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjAss=",
|
||||
"options": [
|
||||
{
|
||||
"__typename": "MultipleChoiceOption",
|
||||
"id": "asd",
|
||||
"displayName": "Size",
|
||||
"values": [
|
||||
{
|
||||
"label": "XL"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
for (let index in products) {
|
||||
let product = products[index];
|
||||
|
||||
normalizeProducts.push({
|
||||
"id": product.hasOwnProperty("id") ? product.id : null,
|
||||
"name": product.hasOwnProperty("name") ? product.name : null,
|
||||
"id": product.hasOwnProperty("id") ? product.id : '',
|
||||
"name": product.hasOwnProperty("name") ? product.name : '',
|
||||
"vendor": "trika",
|
||||
"path": product.hasOwnProperty("name") ? "/" + product.name : null,
|
||||
"slug": `${product.hasOwnProperty("slug") ? product.slug:null}`,
|
||||
"path": product.hasOwnProperty("slug") ? "/" + product.slug : '',
|
||||
"slug": `${product.hasOwnProperty("slug") ? product.slug:''}`,
|
||||
"price": {
|
||||
"value": product.hasOwnProperty("price") ? product.price[0].hasOwnProperty("amount") ? product.price[0].amount : null : null,
|
||||
"currencyCode": product.hasOwnProperty("price") ? product.price[0].hasOwnProperty("currency") ? product.price[0].currency : 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 : '' : ''
|
||||
},
|
||||
"descriptionHtml": product.hasOwnProperty("description") ? product.description : null,
|
||||
"images": [{
|
||||
|
Loading…
x
Reference in New Issue
Block a user