Skip to content

Commit

Permalink
feat(cms): add products collection to CMS
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzzy committed Sep 6, 2024
1 parent 9ffa53b commit bb7e6df
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 2 deletions.
126 changes: 126 additions & 0 deletions apps/cms/src/collections/Products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { CollectionConfig } from "payload/types";

/** Products collection stores merch products offerings. */
export const Products: CollectionConfig = {
slug: "products",
admin: {
description: "Merchandise products offerings",
},
fields: [
// by default, payload generates an 'id' field each order automatically
{
name: "name",
type: "text",
required: true,
},
{
name: "colors",
type: "select",
hasMany: true,
options: [
{
label: "Black",
value: "black",
},
{
label: "White",
value: "white",
},
{
label: "Blue",
value: "blue",
},
],
},
{
name: "sizes",
type: "select",
hasMany: true,
options: [
{
label: "Small",
value: "s",
},
{
label: "Medium",
value: "m",
},
{
label: "Large",
value: "l",
},
{
label: "Extra Large",
value: "xl",
},
],
},
{
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: "select",
required: true,
options: [
{
label: "Shirt",
value: "shirt",
},
{
label: "Hat",
value: "hat",
},
],
},
{
name: "size_chart",
type: "text",
},
{
name: "stock",
type: "array",
fields: [
{
name: "color",
type: "select",
options: ["black", "white", "blue"],
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({
]
: [],
});


30 changes: 30 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,35 @@ 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?: ('black' | 'white' | 'blue')[] | null;
sizes?: ('s' | 'm' | 'l' | 'xl')[] | null;
images?:
| {
url: string;
id?: string | null;
}[]
| null;
is_available?: boolean | null;
price: number;
category: 'shirt' | 'hat';
size_chart?: string | null;
stock?:
| {
color: 'black' | 'white' | 'blue';
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

0 comments on commit bb7e6df

Please sign in to comment.