Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cms): Add Product API to CMS #159

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions apps/cms/src/collections/Products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { CollectionConfig } from "payload/types";

/** Products collection stores merch products offerings. */
export const Products: CollectionConfig = {
slug: "products",
admin: {
description: "Merchandise products offerings",
defaultColumns: ["name", "category", "price", "is_available"],
},
fields: [
// by default, payload generates an 'id' field each order automatically
{
name: "name",
type: "text",
required: true,
},
{
name: "colors",
type: "text",
required: true,
hasMany: true,
},
{
name: "sizes",
type: "text",
hasMany: true,
},
{
name: "images",
type: "array",
fields: [
{
name: "url",
type: "text",
required: true,
},
],
},
{
name: "is_available",
label: "Is Available",
type: "checkbox",
},
{
name: "price",
type: "number",
required: true,
admin: {
step: 0.01,
},
min: 0,
},
{
name: "category",
type: "text",
required: true,
hasMany: true,
minRows: 1,
},
{
name: "size_chart",
label: "Size Chart",
type: "text",
},
{
name: "stock",
type: "array",
fields: [
{
name: "color",
type: "text",
required: true,
},
{
name: "size",
type: "text",
required: true,
},
{
name: "quantity",
type: "number",
admin: {
step: 1,
},
required: true,
min: 0,
},
],
},
],
};

export default Products;
7 changes: 5 additions & 2 deletions apps/cms/src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import MerchProducts from "./admin/views/MerchProducts";
import MerchPromotion from "./admin/views/MerchPromotion";
import { SCSEIcon, SCSELogo } from "./admin/graphics/Logos";
import BeforeNavLinks from "./admin/components/BeforeNavLinks";
import Order from "./collections/Orders";
import Orders from "./collections/Orders";
import { isUsingCloudStore } from "./utilities/cloud";
import { mongooseAdapter } from "@payloadcms/db-mongodb";
import Products from "./collections/Products";

const adapter = createS3Adapter({
config: {
Expand Down Expand Up @@ -85,7 +86,7 @@ export default buildConfig({
return config
},
},
collections: [Categories, Posts, Tags, Users, Media, Order],
collections: [Categories, Posts, Tags, Users, Media, Orders, Products],
csrf: [
// whitelist of domains to allow cookie auth from
process.env.PAYLOAD_PUBLIC_SERVER_URL,
Expand Down Expand Up @@ -115,3 +116,5 @@ export default buildConfig({
]
: [],
});


31 changes: 31 additions & 0 deletions apps/cms/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface Config {
users: User;
media: Media;
orders: Order;
products: Product;
'payload-preferences': PayloadPreference;
'payload-migrations': PayloadMigration;
};
Expand Down Expand Up @@ -152,6 +153,36 @@ export interface Order {
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "products".
*/
export interface Product {
id: string;
name: string;
colors: string[];
sizes?: string[] | null;
images?:
| {
url: string;
id?: string | null;
}[]
| null;
is_available?: boolean | null;
price: number;
category: string[];
size_chart?: string | null;
stock?:
| {
color: string;
size: string;
quantity: number;
id?: string | null;
}[]
| null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-preferences".
Expand Down
Loading