mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
Add product list page to OrderCloud provider (#525)
* product list page and search working
* categories working
* clean things up like console.log
* undo these
* don't need sort stuff. update comment
* turns out the if statements here are necesary
* very incomplete progress on sign-in
* Revert "very incomplete progress on sign-in"
This reverts commit a8dd2af268
.
This commit is contained in:
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -0,0 +1,39 @@
|
||||
|
||||
import { normalize as normalizeProduct } from '@framework/utils/product'
|
||||
import { ProductsEndpoint } from '.'
|
||||
|
||||
// Get products for the product list page. Search and category filter implemented. Sort and brand filter not implemented.
|
||||
const getProducts: ProductsEndpoint['handlers']['getProducts'] = async ({
|
||||
req,
|
||||
res,
|
||||
body: { search, categoryId, brandId, sort },
|
||||
config: { restBuyerFetch, cartCookie, tokenCookie },
|
||||
}) => {
|
||||
//Use a dummy base as we only care about the relative path
|
||||
const url = new URL('/me/products', 'http://a')
|
||||
|
||||
if (search) {
|
||||
url.searchParams.set('search', search)
|
||||
}
|
||||
if (categoryId) {
|
||||
url.searchParams.set('categoryID', String(categoryId))
|
||||
}
|
||||
|
||||
// Get token from cookies
|
||||
const token = req.cookies[tokenCookie];
|
||||
|
||||
var rawProducts = await restBuyerFetch(
|
||||
'GET',
|
||||
url.pathname + url.search,
|
||||
null,
|
||||
{ token }
|
||||
);
|
||||
|
||||
const products = rawProducts.Items.map(normalizeProduct);
|
||||
const found = rawProducts?.Items?.length > 0;
|
||||
|
||||
res.status(200).json({ data: { products, found } })
|
||||
}
|
||||
|
||||
export default getProducts
|
||||
|
18
framework/ordercloud/api/endpoints/catalog/products/index.ts
Normal file
18
framework/ordercloud/api/endpoints/catalog/products/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { createEndpoint, GetAPISchema } from "@commerce/api"
|
||||
import { ProductsSchema } from "@commerce/types/product"
|
||||
import { OrdercloudAPI } from "@framework/api"
|
||||
import getProducts from "./get-products";
|
||||
import productsEndpoint from '@commerce/api/endpoints/catalog/products'
|
||||
|
||||
export type ProductsAPI = GetAPISchema<OrdercloudAPI, ProductsSchema>
|
||||
|
||||
export type ProductsEndpoint = ProductsAPI['endpoint']
|
||||
|
||||
export const handlers: ProductsEndpoint['handlers'] = { getProducts }
|
||||
|
||||
const productsApi = createEndpoint<ProductsAPI>({
|
||||
handler: productsEndpoint,
|
||||
handlers,
|
||||
})
|
||||
|
||||
export default productsApi
|
Reference in New Issue
Block a user