@shopnex/cj-plugin
v1.0.10
Published
A blank template to get started with Payload 3.0
Readme
CJ Dropshipping Plugin for Payload CMS
This plugin integrates CJ Dropshipping into your Payload CMS project by:
- Adding "CJ" as a product source.
- Automatically creating CJ orders after local orders are created.
- (Optionally) generating a
cj-settingscollection for managing API credentials dynamically. - Syncing CJ credentials on app initialization.
Installation
pnpm install @shopnex/cj-pluginor
npm install @shopnex/cj-pluginor
yarn add @shopnex/cj-pluginUsage
Import and add the cjPlugin to your Payload config:
import { buildConfig } from "payload/config";
import { cjPlugin } from "@shopnex/cj-plugin";
export default buildConfig({
collections: [
// your collections
],
plugins: [
cjPlugin({
cjApiKey: "your-cj-api-key",
cjEmailAddress: "[email protected]",
cjRefreshToken: "optional-refresh-token", // optional
asCollection: true, // optional - creates a cj-settings collection
collectionOverrides: {
// optional - override fields or settings for the cj-settings collection
},
}),
],
});Plugin Options
| Option | Type | Required | Description |
| --------------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------- |
| cjApiKey | string | Yes | Your CJ Dropshipping API key. |
| cjEmailAddress | string | Yes | Your CJ account email address. |
| cjRefreshToken | string | No | Your CJ refresh token if available. |
| asCollection | boolean | No | If true, automatically creates a cj-settings collection to manage CJ API credentials per tenant/shop. |
| collectionOverrides | object | No | Allows overriding the default cj-settings collection config (fields, hooks, etc). |
What the Plugin Does
- Modifies the
productscollection:- Adds a
sourceoption:{ label: 'CJ', value: 'cj' }.
- Adds a
- Hooks into the
orderscollection:- On every new order or update, triggers the CJ order creation logic automatically.
- Manages CJ credentials dynamically:
- On Payload startup (
onInit), loads allcj-settingsdocuments and sets up credentials per shop.
- On Payload startup (
- Optional
cj-settingscollection:- If
asCollectionis true, a newcj-settingscollection will be added automatically. - Useful for multi-tenant setups or dynamically changing credentials.
- If
Example: cj-settings Collection
If asCollection: true, the following collection will be generated by default:
| Field | Type | Description |
| ---------- | -------- | --------------------------------- |
| shop | Relation | Reference to your shop or tenant. |
| email | Text | Your CJ email address. |
| apiToken | Text | Your CJ API key. |
You can override this structure with collectionOverrides.
Notes
- The plugin assumes you have a
productscollection with asourceselect field already created. - It assumes you have an
orderscollection. - Make sure the
sourcefield inproductsuses aselecttype withoptionsarray.
License
MIT
