Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

b2c-querying-dataB2C 查询数据

Agent Skill

用于辅助数据整理、表格处理、CSV/Excel 分析、指标计算和图表准备。它适合让 Agent 清洗字段、汇总数据、发现异常、生成统计口径或把分析结果转成可读说明。使用时需要确认数据来源、字段含义和时间范围,避免把样本数据当全量事实;涉及敏感数据、导出文件或批量写回时,应先确认权限和脱敏边界。

总安装

1,763

周安装

72

GitHub Stars

38

下载量

564
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:b2c-querying-data(B2C 查询数据)
来源仓库:https://github.com/salesforcecommercecloud/b2c-developer-tooling
仓库路径:skills/b2c-querying-data
安装命令:
npx skills add https://github.com/salesforcecommercecloud/b2c-developer-tooling --skill b2c-querying-data
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/salesforcecommercecloud/b2c-developer-tooling --skill b2c-querying-data

简介

用于高效查询 B2C Commerce 中的产品、订单和客户数据。

  • 推荐使用 ProductSearchModel 进行索引 backed 搜索,保障高并发性能。
  • 支持分类筛选、排序规则和可订购商品过滤等常用操作。
  • 安装需使用 npx skills add 命令从指定 GitHub 仓库添加技能。
  • 复杂查询应考虑分页机制,防止单次请求负载过高。

SKILL.md

Querying Data in B2C Commerce

Efficient data querying is critical for storefront performance and job stability. B2C Commerce provides index-backed search APIs and database query APIs—choosing the right one for each use case avoids performance problems.

Product Search (Storefront)

Use ProductSearchModel for all storefront product searches. It is index-backed and designed for high-traffic pages.

Basic Product Search

var ProductSearchModel = require('dw/catalog/ProductSearchModel');

var psm = new ProductSearchModel();
psm.setCategoryID('electronics');
psm.setOrderableProductsOnly(true); // Only in-stock products
psm.setSearchPhrase('laptop');
psm.search();

var hits = psm.getProductSearchHits();
while (hits.hasNext()) {
    var hit = hits.next();
    var productID = hit.productID;
    var minPrice = hit.minPrice;
    var maxPrice = hit.maxPrice;
}
hits.close();

Paging Search Results

Always page results—never load the full result set:

var ProductSearchModel = require('dw/catalog/ProductSearchModel');
var PagingModel = require('dw/web/PagingModel');

var psm = new ProductSearchModel();
psm.setCategoryID('mens-clothing');
psm.setOrderableProductsOnly(true);
psm.search();

var pagingModel = new PagingModel(psm.getProductSearchHits(), psm.count);
pagingModel.setPageSize(12);
pagingModel.setStart(0); // page offset

var pageElements = pagingModel.pageElements;
while (pageElements.hasNext()) {
    var hit = pageElements.next();
    // Render product tile
}

Getting Variation Data from Search Hits

Use ProductSearchHit methods instead of loading full product objects:

// GOOD: Get variation info from the search hit (index-backed)
var representedColors = hit.getRepresentedVariationValues('color');
var representedIDs = hit.getRepresentedProductIDs();
var minPrice = hit.getMinPrice();
var maxPrice = hit.getMaxPrice();

// BAD: Loading the full product and iterating variants (database-intensive)
var product = hit.product;
var variants = product.getVariants(); // Expensive!
var priceModel = product.getPriceModel(); // Expensive!

Search Refinements

var psm = new ProductSearchModel();
psm.setCategoryID('shoes');
psm.addRefinementValues('color', 'blue');
psm.addRefinementValues('size', '10');
psm.setPriceMin(50);
psm.setPriceMax(200);
psm.search();

// Get available refinement values for the current result set
var refinements = psm.getRefinements();
var colorValues = refinements.getNextLevelRefinementValues(
    refinements.getRefinementDefinitionByName('color')
);

ProductSearchModel API Summary

MethodDescription
search()Execute the search
setCategoryID(id)Filter by category
setSearchPhrase(phrase)Set search keywords
setOrderableProductsOnly(flag)Exclude out-of-stock
addRefinementValues(name, value)Add refinement filter
setPriceMin(price) / setPriceMax(price)Price range filter
setSortingRule(rule)Set sorting rule
getProductSearchHits()Get result iterator
getRefinements()Get available refinements
countTotal result count

Order Queries

OrderMgr.searchOrders / queryOrders

Use searchOrders for index-backed order lookups and queryOrders for database queries:

var OrderMgr = require('dw/order/OrderMgr');
var Order = require('dw/order/Order');

// Index-backed search (preferred for common lookups)
var orders = OrderMgr.searchOrders(
    'customerEmail = {0} AND status != {1}',
    'creationDate desc',
    'customer@example.com',
    Order.ORDER_STATUS_FAILED
);

while (orders.hasNext()) {
    var order = orders.next();
    // Process order
}
orders.close(); // Always close iterators

Query by Date Range

var OrderMgr = require('dw/order/OrderMgr');
var Calendar = require('dw/util/Calendar');
var Order = require('dw/order/Order');

var startDate = new Calendar();
startDate.add(Calendar.DAY_OF_YEAR, -7);

var orders = OrderMgr.searchOrders(
    'creationDate >= {0} AND status = {1}',
    'creationDate desc',
    startDate.time,
    Order.ORDER_STATUS_NEW
);

while (orders.hasNext()) {
    var order = orders.next();
    // Process
}
orders.close();

searchOrders vs queryOrders

AspectsearchOrdersqueryOrders
BackingSearch indexDatabase
PerformanceFast for indexed fieldsSlower, full table scan possible
Use whenQuerying indexed attributes (status, email, dates)Querying non-indexed or custom attributes
Result limitUp to 1000 hitsNo hard limit (but use paging)

Prefer searchOrders for storefront and high-traffic code paths. Use queryOrders only when you need to query attributes not available in the search index.

Customer / Profile Queries

CustomerMgr (Preferred)

Use searchProfiles for index-backed searches and processProfiles for batch processing in jobs:

var CustomerMgr = require('dw/customer/CustomerMgr');

// Index-backed search (storefront use)
var profiles = CustomerMgr.searchProfiles(
    'email = {0}',
    'lastLoginTime desc',
    'customer@example.com'
);

while (profiles.hasNext()) {
    var profile = profiles.next();
    // Process profile
}
profiles.close();

Batch Processing (Jobs)

Use processProfiles for jobs that need to iterate over many profiles—it has optimized memory management:

var CustomerMgr = require('dw/customer/CustomerMgr');

function processProfile(profile) {
    // Process each profile individually
    // Memory is managed automatically
}

// Process all profiles matching the query
CustomerMgr.processProfiles('gender = {0}', processProfile, 1);

Important: processProfiles replaces the older queryProfiles and SystemObjectMgr.querySystemObjects for customer data. It uses the full-text search service with better performance and memory characteristics.

Customer Query Behaviors

  • Wildcards (*, %, +) are filtered from queries and replaced by spaces
  • LIKE and ILIKE execute as full-text queries (match whole words, not substrings)
  • LIKE is case-insensitive
  • Combining AND and OR in the same query degrades performance
  • Range queries (e.g., a > b) impact performance
  • Results are limited to the first 1000 hits

System Object Queries (SystemObjectMgr)

For querying system objects other than customers (e.g., SitePreferences, catalogs):

var SystemObjectMgr = require('dw/object/SystemObjectMgr');

// Query system objects
var results = SystemObjectMgr.querySystemObjects(
    'Profile',
    'custom.loyaltyTier = {0}',
    'lastLoginTime desc',
    'Gold'
);

while (results.hasNext()) {
    var obj = results.next();
    // Process
}
results.close();

Note: For customer profiles specifically, prefer CustomerMgr.searchProfiles or CustomerMgr.processProfiles over SystemObjectMgr.querySystemObjects—they use the search index and perform significantly better.

Database-Intensive APIs to Avoid

These APIs hit the database directly and are expensive on high-traffic pages. Replace them with index-friendly alternatives. See Performance-Critical APIs for the complete list with impact details.

Avoid (Database-Intensive)Use Instead (Index-Friendly)
Category.getProducts() / getOnlineProducts()ProductSearchModel.setCategoryID()
ProductMgr.queryAllSiteProducts()ProductSearchModel.search()
Product.getVariants() / getVariationModel()ProductSearchHit methods
Product.getPriceModel() (in loops)ProductSearchHit.getMinPrice() / getMaxPrice()
CustomerMgr.queryProfiles()CustomerMgr.searchProfiles() or processProfiles()

Related Skills

Best Practices

Do

  • Always close iterators — unclosed iterators leak resources (results.close())
  • Page results — use PagingModel or limit result counts; never load unbounded result sets
  • Put all filtering in the query — don't post-process or filter results in custom code
  • Use index-backed APIsProductSearchModel, searchOrders, searchProfiles for storefront pages
  • Use processProfiles for batch customer operations in jobs (optimized memory)
  • Limit page size — maximum ~120 products per page for search result pages
  • Use setOrderableProductsOnly(true) — to filter unavailable products at the search level

Don't

  • Don't iterate over product variants on search result pages — use ProductSearchHit methods instead
  • Don't post-process search results — all criteria must go into the query for efficient execution
  • Don't use queryAllSiteProducts() on storefront pages — it bypasses the search index
  • Don't combine AND + OR in customer queries — it degrades performance
  • Don't rely on getting more than 1000 results — search APIs cap at 1000 hits
  • Don't call database-intensive APIs on high-traffic pages — category pages, search results, PDPs, and homepage

Job-Specific Guidelines

  • Use processProfiles over queryProfiles for large customer data sets
  • Design loop logic so memory consumption doesn't grow with result set size
  • Keep only the currently processed object in memory; don't retain references
  • Stream data to files regularly; don't build large structures in memory
  • Limit transaction size to under 1000 modified business objects

Detailed References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

32.31%
按下载量换算182

Claude

31.04%
按下载量换算175

Cursor

20.77%
按下载量换算117

Gemini CLI

10.06%
按下载量换算57

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills