1.2.2 • Published 2 months ago
@shopnex/cj-plugin v1.2.2
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-settings
collection for managing API credentials dynamically. - Syncing CJ credentials on app initialization.
Installation
pnpm install @shopnex/cj-plugin
or
npm install @shopnex/cj-plugin
or
yarn add @shopnex/cj-plugin
Usage
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: "your-email@example.com",
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
products
collection:- Adds a
source
option:{ label: 'CJ', value: 'cj' }
.
- Adds a
- Hooks into the
orders
collection:- On every new order or update, triggers the CJ order creation logic automatically.
- Manages CJ credentials dynamically:
- On Payload startup (
onInit
), loads allcj-settings
documents and sets up credentials per shop.
- On Payload startup (
- Optional
cj-settings
collection:- If
asCollection
is true, a newcj-settings
collection 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
products
collection with asource
select field already created. - It assumes you have an
orders
collection. - Make sure the
source
field inproducts
uses aselect
type withoptions
array.
License
MIT