重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
b2c-custom-objects by salesforcecommercecloud/b2c-developer-tooling
npx skills add https://github.com/salesforcecommercecloud/b2c-developer-tooling --skill b2c-custom-objects自定义对象用于存储不适合标准系统对象的业务数据。它们支持站点范围和机构范围(全局)的数据,并通过 Script API 和 OCAPI 提供完整的 CRUD 操作。
| 使用场景 | 示例 |
|---|---|
| 业务配置 | 存储每个站点或全局的配置 |
| 集成数据 | 缓存外部系统的响应 |
| 自定义实体 | 忠诚度等级、自定义促销、供应商数据 |
| 临时处理 | 作业处理队列、导入暂存 |
自定义对象在业务管理器的 管理 > 站点开发 > 自定义对象类型 下定义。每种类型包含:
CustomConfig)var CustomObjectMgr = require('dw/object/CustomObjectMgr');
// 通过类型和键获取单个自定义对象
var config = CustomObjectMgr.getCustomObject('CustomConfig', 'myConfigKey');
if (config) {
var value = config.custom.configValue;
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
var CustomObjectMgr = require('dw/object/CustomObjectMgr');
var Transaction = require('dw/system/Transaction');
Transaction.wrap(function() {
// 创建新的自定义对象(类型,键值)
var obj = CustomObjectMgr.createCustomObject('CustomConfig', 'newKey');
obj.custom.configValue = 'myValue';
obj.custom.isActive = true;
});
var CustomObjectMgr = require('dw/object/CustomObjectMgr');
// 使用属性过滤器查询
var objects = CustomObjectMgr.queryCustomObjects(
'CustomConfig', // 类型
'custom.isActive = {0}', // 查询(使用位置参数)
'creationDate desc', // 排序顺序
true // 参数 {0} 的值
);
while (objects.hasNext()) {
var obj = objects.next();
// 处理对象
}
objects.close();
var CustomObjectMgr = require('dw/object/CustomObjectMgr');
var Transaction = require('dw/system/Transaction');
Transaction.wrap(function() {
var obj = CustomObjectMgr.getCustomObject('CustomConfig', 'keyToDelete');
if (obj) {
CustomObjectMgr.remove(obj);
}
});
var CustomObjectMgr = require('dw/object/CustomObjectMgr');
// 获取某种类型的所有对象
var allConfigs = CustomObjectMgr.getAllCustomObjects('CustomConfig');
while (allConfigs.hasNext()) {
var config = allConfigs.next();
// 处理
}
allConfigs.close();
| 方法 | 描述 |
|---|---|
getCustomObject(type, keyValue) | 通过类型和键获取单个对象 |
createCustomObject(type, keyValue) | 创建新对象(在事务内) |
remove(object) | 删除对象(在事务内) |
queryCustomObjects(type, query, sortString, ...args) | 使用过滤器进行查询 |
getAllCustomObjects(type) | 获取某种类型的所有对象 |
describe(type) | 获取自定义对象类型的元数据 |
GET /s/-/dw/data/v25_6/custom_objects/{object_type}/{key}
Authorization: Bearer {token}
注意: 对于站点范围的对象,使用 /s/{site_id}/dw/data/v25_6/custom_objects/...;对于机构范围(全局)的对象,使用 /s/-/dw/data/v25_6/custom_objects/...。
PUT /s/-/dw/data/v25_6/custom_objects/{object_type}/{key}
Authorization: Bearer {token}
Content-Type: application/json
{
"key_property": "myKey",
"c_configValue": "myValue",
"c_isActive": true
}
PATCH /s/-/dw/data/v25_6/custom_objects/{object_type}/{key}
Authorization: Bearer {token}
Content-Type: application/json
{
"c_configValue": "updatedValue"
}
DELETE /s/-/dw/data/v25_6/custom_objects/{object_type}/{key}
Authorization: Bearer {token}
POST /s/-/dw/data/v25_6/custom_object_search/{object_type}
Authorization: Bearer {token}
Content-Type: application/json
{
"query": {
"bool_query": {
"must": [
{ "term_query": { "field": "c_isActive", "value": true } }
]
}
},
"select": "(**)",
"sorts": [{ "field": "creation_date", "sort_order": "desc" }],
"start": 0,
"count": 25
}
| 查询类型 | 描述 | 示例 |
|---|---|---|
term_query | 精确匹配 | {"field": "c_status", "value": "active"} |
text_query | 全文搜索 | {"fields": ["c_name"], "search_phrase": "test"} |
range_query | 范围比较 | {"field": "c_count", "from": 1, "to": 10} |
bool_query | 组合查询 | {"must": [...], "should": [...], "must_not": [...]} |
match_all_query | 匹配所有记录 | {} |
对于从前端商店进行只读访问,请使用 Shopper Custom Objects API。这需要特定的 OAuth 范围。
GET https://{shortCode}.api.commercecloud.salesforce.com/custom-object/shopper-custom-objects/v1/organizations/{organizationId}/custom-objects/{objectType}/{key}?siteId={siteId}
Authorization: Bearer {shopper_token}
对于 Shopper Custom Objects API,请在您的 SLAS 客户端中配置以下范围:
sfcc.shopper-custom-objects - 对所有自定义对象类型的全局读取权限sfcc.shopper-custom-objects.{objectType} - 特定类型的读取权限注意: SLAS 客户端最多可以拥有 20 个自定义对象范围。
自定义对象类型还必须在业务管理器中启用购物者访问权限。
所有自定义对象都拥有以下系统字段,可用于 OCAPI 搜索查询:
creation_date - 对象创建时间(日期)last_modified - 对象最后修改时间(日期)key_value_string - 字符串键值key_value_integer - 整数键值site_id - 站点标识符(针对站点范围的对象)objects.close())getCustomObject() 返回的 null 值var CustomObjectMgr = require('dw/object/CustomObjectMgr');
var Site = require('dw/system/Site');
function getConfig(key, defaultValue) {
var configKey = Site.current.ID + '_' + key;
var obj = CustomObjectMgr.getCustomObject('SiteConfig', configKey);
if (obj && obj.custom.value !== null) {
return JSON.parse(obj.custom.value);
}
return defaultValue;
}
function setConfig(key, value) {
var Transaction = require('dw/system/Transaction');
var configKey = Site.current.ID + '_' + key;
Transaction.wrap(function() {
var obj = CustomObjectMgr.getCustomObject('SiteConfig', configKey);
if (!obj) {
obj = CustomObjectMgr.createCustomObject('SiteConfig', configKey);
}
obj.custom.value = JSON.stringify(value);
});
}
var CustomObjectMgr = require('dw/object/CustomObjectMgr');
var Transaction = require('dw/system/Transaction');
// 添加到队列
function enqueue(data) {
var key = 'job_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
Transaction.wrap(function() {
var obj = CustomObjectMgr.createCustomObject('JobQueue', key);
obj.custom.data = JSON.stringify(data);
obj.custom.status = 'pending';
});
}
// 处理队列
function processQueue() {
var pending = CustomObjectMgr.queryCustomObjects(
'JobQueue',
'custom.status = {0}',
'creationDate asc',
'pending'
);
while (pending.hasNext()) {
var job = pending.next();
Transaction.wrap(function() {
job.custom.status = 'processing';
});
try {
var data = JSON.parse(job.custom.data);
processJob(data);
Transaction.wrap(function() {
CustomObjectMgr.remove(job);
});
} catch (e) {
Transaction.wrap(function() {
job.custom.status = 'failed';
job.custom.error = e.message;
});
}
}
pending.close();
}
每周安装数
67
代码仓库
GitHub 星标数
33
首次出现
2026年2月17日
安全审计
安装于
github-copilot61
codex58
cursor58
opencode57
gemini-cli56
amp56
Custom objects store business data that doesn't fit into standard system objects. They support both site-scoped and organization-scoped (global) data, with full CRUD operations via Script API and OCAPI.
| Use Case | Example |
|---|---|
| Business configuration | Store configuration per site or globally |
| Integration data | Cache external system responses |
| Custom entities | Loyalty tiers, custom promotions, vendor data |
| Temporary processing | Job processing queues, import staging |
Custom objects are defined in Business Manager under Administration > Site Development > Custom Object Types. Each type has:
CustomConfig)var CustomObjectMgr = require('dw/object/CustomObjectMgr');
// Get a single custom object by type and key
var config = CustomObjectMgr.getCustomObject('CustomConfig', 'myConfigKey');
if (config) {
var value = config.custom.configValue;
}
var CustomObjectMgr = require('dw/object/CustomObjectMgr');
var Transaction = require('dw/system/Transaction');
Transaction.wrap(function() {
// Create new custom object (type, keyValue)
var obj = CustomObjectMgr.createCustomObject('CustomConfig', 'newKey');
obj.custom.configValue = 'myValue';
obj.custom.isActive = true;
});
var CustomObjectMgr = require('dw/object/CustomObjectMgr');
// Query with attribute filter
var objects = CustomObjectMgr.queryCustomObjects(
'CustomConfig', // Type
'custom.isActive = {0}', // Query (uses positional params)
'creationDate desc', // Sort order
true // Parameter value for {0}
);
while (objects.hasNext()) {
var obj = objects.next();
// Process object
}
objects.close();
var CustomObjectMgr = require('dw/object/CustomObjectMgr');
var Transaction = require('dw/system/Transaction');
Transaction.wrap(function() {
var obj = CustomObjectMgr.getCustomObject('CustomConfig', 'keyToDelete');
if (obj) {
CustomObjectMgr.remove(obj);
}
});
var CustomObjectMgr = require('dw/object/CustomObjectMgr');
// Get all objects of a type
var allConfigs = CustomObjectMgr.getAllCustomObjects('CustomConfig');
while (allConfigs.hasNext()) {
var config = allConfigs.next();
// Process
}
allConfigs.close();
| Method | Description |
|---|---|
getCustomObject(type, keyValue) | Get single object by type and key |
createCustomObject(type, keyValue) | Create new object (within transaction) |
remove(object) | Delete object (within transaction) |
queryCustomObjects(type, query, sortString, ...args) | Query with filters |
getAllCustomObjects(type) | Get all objects of a type |
describe(type) |
GET /s/-/dw/data/v25_6/custom_objects/{object_type}/{key}
Authorization: Bearer {token}
Note: Use /s/{site_id}/dw/data/v25_6/custom_objects/... for site-scoped objects, or /s/-/dw/data/v25_6/custom_objects/... for organization-scoped (global) objects.
PUT /s/-/dw/data/v25_6/custom_objects/{object_type}/{key}
Authorization: Bearer {token}
Content-Type: application/json
{
"key_property": "myKey",
"c_configValue": "myValue",
"c_isActive": true
}
PATCH /s/-/dw/data/v25_6/custom_objects/{object_type}/{key}
Authorization: Bearer {token}
Content-Type: application/json
{
"c_configValue": "updatedValue"
}
DELETE /s/-/dw/data/v25_6/custom_objects/{object_type}/{key}
Authorization: Bearer {token}
POST /s/-/dw/data/v25_6/custom_object_search/{object_type}
Authorization: Bearer {token}
Content-Type: application/json
{
"query": {
"bool_query": {
"must": [
{ "term_query": { "field": "c_isActive", "value": true } }
]
}
},
"select": "(**)",
"sorts": [{ "field": "creation_date", "sort_order": "desc" }],
"start": 0,
"count": 25
}
| Query Type | Description | Example |
|---|---|---|
term_query | Exact match | {"field": "c_status", "value": "active"} |
text_query | Full-text search | {"fields": ["c_name"], "search_phrase": "test"} |
range_query | Range comparison | {"field": "c_count", "from": 1, "to": 10} |
For read-only access from storefronts, use the Shopper Custom Objects API. This requires specific OAuth scopes.
GET https://{shortCode}.api.commercecloud.salesforce.com/custom-object/shopper-custom-objects/v1/organizations/{organizationId}/custom-objects/{objectType}/{key}?siteId={siteId}
Authorization: Bearer {shopper_token}
For the Shopper Custom Objects API, configure these scopes in your SLAS client:
sfcc.shopper-custom-objects - Global read access to all custom object typessfcc.shopper-custom-objects.{objectType} - Type-specific read accessNote: SLAS clients can have a maximum of 20 custom object scopes.
The custom object type must also be enabled for shopper access in Business Manager.
All custom objects have these system fields available for OCAPI search queries:
creation_date - When the object was created (Date)last_modified - When the object was last modified (Date)key_value_string - String key valuekey_value_integer - Integer key valuesite_id - Site identifier (for site-scoped objects)objects.close())getCustomObject()var CustomObjectMgr = require('dw/object/CustomObjectMgr');
var Site = require('dw/system/Site');
function getConfig(key, defaultValue) {
var configKey = Site.current.ID + '_' + key;
var obj = CustomObjectMgr.getCustomObject('SiteConfig', configKey);
if (obj && obj.custom.value !== null) {
return JSON.parse(obj.custom.value);
}
return defaultValue;
}
function setConfig(key, value) {
var Transaction = require('dw/system/Transaction');
var configKey = Site.current.ID + '_' + key;
Transaction.wrap(function() {
var obj = CustomObjectMgr.getCustomObject('SiteConfig', configKey);
if (!obj) {
obj = CustomObjectMgr.createCustomObject('SiteConfig', configKey);
}
obj.custom.value = JSON.stringify(value);
});
}
var CustomObjectMgr = require('dw/object/CustomObjectMgr');
var Transaction = require('dw/system/Transaction');
// Add to queue
function enqueue(data) {
var key = 'job_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
Transaction.wrap(function() {
var obj = CustomObjectMgr.createCustomObject('JobQueue', key);
obj.custom.data = JSON.stringify(data);
obj.custom.status = 'pending';
});
}
// Process queue
function processQueue() {
var pending = CustomObjectMgr.queryCustomObjects(
'JobQueue',
'custom.status = {0}',
'creationDate asc',
'pending'
);
while (pending.hasNext()) {
var job = pending.next();
Transaction.wrap(function() {
job.custom.status = 'processing';
});
try {
var data = JSON.parse(job.custom.data);
processJob(data);
Transaction.wrap(function() {
CustomObjectMgr.remove(job);
});
} catch (e) {
Transaction.wrap(function() {
job.custom.status = 'failed';
job.custom.error = e.message;
});
}
}
pending.close();
}
Weekly Installs
67
Repository
GitHub Stars
33
First Seen
Feb 17, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot61
codex58
cursor58
opencode57
gemini-cli56
amp56
Azure 升级评估与自动化工具 - 轻松迁移 Functions 计划、托管层级和 SKU
111,700 周安装
AI API响应测试固件生成指南 - Vercel AI SDK测试工具与最佳实践
513 周安装
科学头脑风暴技能:AI研究构思伙伴,生成创新假设与跨学科方法论
512 周安装
敏捷产品负责人工具包 - 自动生成用户故事、冲刺规划与优先级排序
514 周安装
Spring Data JPA 使用指南:CRUD 操作、实体关系、查询优化与审计功能
518 周安装
Spring Boot 3.x OpenAPI 文档生成指南 - SpringDoc集成与Swagger UI配置
520 周安装
React Native 移动端 UI 设计规范与无障碍开发指南 | 最佳实践
524 周安装
| Get metadata about the custom object type |
bool_query| Combine queries |
{"must": [...], "should": [...], "must_not": [...]} |
match_all_query | Match all records | {} |