sap-hybris-commerce-best-practices
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSAP Hybris Commerce Best Practices
SAP Hybris Commerce 最佳实践
Comprehensive development guidelines and best practices for SAP Commerce Cloud (formerly Hybris).
This skill covers the complete development lifecycle from data modeling to frontend and backoffice configuration.
SAP Commerce Cloud(原Hybris)的全面开发指南与最佳实践。
本技能涵盖从数据建模到前端和Backoffice配置的完整开发生命周期。
Version Context
版本上下文
- SAP Commerce Cloud: 2211+ (September 2025 update)
- JDK: 21
- Spring Framework: 6.2
- Architecture: Service Layer (Jalo layer deprecated)
- SAP Commerce Cloud:2211+(2025年9月更新)
- JDK:21
- Spring Framework:6.2
- 架构:Service Layer(Jalo层已废弃)
Quick Reference
快速参考
Core Concepts
核心概念
- Extension-based architecture: modular design with custom extensions
- Type System: metadata-driven data model defined in items.xml
- Service Layer: primary API for business logic (ModelService, FlexibleSearchService)
- ImpEx: CSV-based data import/export tool
- Spring Integration: DI, AOP, and bean management
- 基于扩展的架构:采用自定义扩展的模块化设计
- 类型系统:在items.xml中定义的元数据驱动型数据模型
- Service Layer:业务逻辑的主API(ModelService、FlexibleSearchService)
- ImpEx:基于CSV的数据导入/导出工具
- Spring集成:依赖注入(DI)、面向切面编程(AOP)和Bean管理
Development Workflow
开发工作流
- Define data model in
*-items.xml - Run to generate model classes
ant clean all - Perform system update to apply schema changes
- Implement services with Spring DI
- Create facades with DTOs for frontend
- Build controllers for web/REST APIs
- Create JSP views or use headless APIs
- Configure Solr for search functionality
- Write automated tests (unit + integration)
- 在中定义数据模型
*-items.xml - 运行生成模型类
ant clean all - 执行系统更新以应用数据库架构变更
- 使用Spring DI实现服务
- 创建带DTO的Facade供前端使用
- 为Web/REST API构建控制器
- 创建JSP视图或使用无头API
- 配置Solr实现搜索功能
- 编写自动化测试(单元测试+集成测试)
Topics
主题
Backend Development
后端开发
- Code Conventions - SAP Commerce coding style and formatting rules
- Java Development Guidelines - Coding standards, Spring patterns, service layer
- Create Extensions - Extension structure, types, and configuration
- Define Data Types - items.xml structure, types, relations
- Using ImpEx - Data import/export syntax and patterns
- Dynamic Attributes - Computed attributes without DB storage
- Services - Business logic implementation with Spring
- Properties Configuration - Externalize configuration
- Events - Event-driven architecture patterns
- Interceptors - Model lifecycle hooks
- Validation Framework - Declarative validation constraints
- Automated Testing - Unit and integration testing
- Code Quality - SOLID principles, extensibility, upgradability
- 代码规范 - SAP Commerce编码风格与格式化规则
- Java开发指南 - 编码标准、Spring模式、Service Layer
- 创建扩展 - 扩展结构、类型与配置
- 定义数据类型 - items.xml结构、类型、关联关系
- 使用ImpEx - 数据导入/导出语法与模式
- 动态属性 - 无需数据库存储的计算属性
- 服务 - 使用Spring实现业务逻辑
- 属性配置 - 外部化配置
- 事件 - 事件驱动架构模式
- 拦截器 - 模型生命周期钩子
- 验证框架 - 声明式验证约束
- 自动化测试 - 单元测试与集成测试
- 代码质量 - SOLID原则、可扩展性、可升级性
Frontend Development
前端开发
- Facades - Facade pattern, DTOs, converters
- Controllers - Spring MVC and REST controllers
- WCMS Components - CMS content management
- JSP Tags - Custom tag libraries
- JSP Views - View templates with JSTL
- Facade - Facade模式、DTO、转换器
- 控制器 - Spring MVC与REST控制器
- WCMS组件 - CMS内容管理
- JSP标签 - 自定义标签库
- JSP视图 - 使用JSTL的视图模板
Search & Indexing
搜索与索引
- Solr Integration - Search configuration, indexing, facets
- Solr集成 - 搜索配置、索引、分面
Background Processing
后台处理
- Tasks and CronJobs - Background task scheduling and execution
- 任务与CronJob - 后台任务调度与执行
Backoffice
Backoffice
- Backoffice Configuration - cockpitng/backoffice config patterns (editor area, list view, search, wizards)
- Backoffice配置 - cockpitng/backoffice配置模式(编辑区域、列表视图、搜索、向导)
Common Patterns
常见模式
Service + Facade Pattern
Service + Facade模式
java
// Service (backend logic)
public interface ProductService {
ProductModel findByCode(String code);
}
@Service
public class DefaultProductService implements ProductService {
private final FlexibleSearchService flexibleSearchService;
public DefaultProductService(final FlexibleSearchService flexibleSearchService) {
this.flexibleSearchService = flexibleSearchService;
}
@Override
public ProductModel findByCode(final String code) {
// ...
return null;
}
}
// Facade (frontend API)
public interface ProductFacade {
ProductData getProduct(String code);
}
@Service
public class DefaultProductFacade implements ProductFacade {
private final ProductService productService;
private final Converter<ProductModel, ProductData> converter;
public DefaultProductFacade(final ProductService productService,
final Converter<ProductModel, ProductData> converter) {
this.productService = productService;
this.converter = converter;
}
@Override
public ProductData getProduct(final String code) {
return converter.convert(productService.findByCode(code));
}
}java
// Service (backend logic)
public interface ProductService {
ProductModel findByCode(String code);
}
@Service
public class DefaultProductService implements ProductService {
private final FlexibleSearchService flexibleSearchService;
public DefaultProductService(final FlexibleSearchService flexibleSearchService) {
this.flexibleSearchService = flexibleSearchService;
}
@Override
public ProductModel findByCode(final String code) {
// ...
return null;
}
}
// Facade (frontend API)
public interface ProductFacade {
ProductData getProduct(String code);
}
@Service
public class DefaultProductFacade implements ProductFacade {
private final ProductService productService;
private final Converter<ProductModel, ProductData> converter;
public DefaultProductFacade(final ProductService productService,
final Converter<ProductModel, ProductData> converter) {
this.productService = productService;
this.converter = converter;
}
@Override
public ProductData getProduct(final String code) {
return converter.convert(productService.findByCode(code));
}
}Model Lifecycle
模型生命周期
Create -> InitDefaults -> Prepare -> Validate -> Save
Load -> LoadInterceptor
Delete -> RemoveInterceptorCreate -> InitDefaults -> Prepare -> Validate -> Save
Load -> LoadInterceptor
Delete -> RemoveInterceptorExtension Dependencies
扩展依赖
core -> facades -> storefront
-> backoffice
-> occ (REST API)core -> facades -> storefront
-> backoffice
-> occ (REST API)Best Practices Summary
最佳实践总结
DO
建议做法
- Use Service Layer APIs (ModelService, FlexibleSearchService)
- Follow interface + implementation pattern
- Prefer constructor injection (Spring 6)
- Externalize configuration to properties files
- Write unit and integration tests
- Use facades with DTOs for frontend
- Validate input with interceptors or the validation framework
- Use ImpEx for data management
- Configure Solr for search functionality
- Follow SOLID principles
- 使用Service Layer API(ModelService、FlexibleSearchService)
- 遵循“接口+实现”模式
- 优先使用构造函数注入(Spring 6)
- 将配置外部化到属性文件中
- 编写单元测试与集成测试
- 为前端使用带DTO的Facade
- 使用拦截器或验证框架验证输入
- 使用ImpEx进行数据管理
- 配置Solr实现搜索功能
- 遵循SOLID原则
DON'T
不建议做法
- Use Jalo layer directly (deprecated)
- Use field injection (on fields)
@Autowired - Hardcode configuration values
- Expose models directly to frontend
- Modify generated model classes
- Skip system update after items.xml changes
- Perform heavy operations in interceptors
- Use embedded Solr in production
- 直接使用Jalo层(已废弃)
- 使用字段注入(在字段上使用)
@Autowired - 硬编码配置值
- 直接向前端暴露模型
- 修改生成的模型类
- 在items.xml变更后跳过系统更新
- 在拦截器中执行繁重操作
- 在生产环境中使用嵌入式Solr
Quick Commands
快速命令
bash
undefinedbash
undefinedBuild and generate models
构建并生成模型
ant clean all
ant clean all
Run tests
运行测试
ant alltests
ant unittests
ant integrationtests
ant alltests
ant unittests
ant integrationtests
Solr management
Solr管理
ant startSolrServer
ant stopSolrServer
ant startSolrServer
ant stopSolrServer
Initialize/update system
初始化/更新系统
ant initialize
ant updatesystem
undefinedant initialize
ant updatesystem
undefinedResources
资源
- SAP Help Portal (requires authentication)
- SAP Community (forums and blogs)
- Local HAC:
http://localhost:9001/hac
Note: this skill is based on SAP Commerce Cloud 2211+ (September 2025). For earlier versions, some features and APIs may differ.
- SAP帮助门户(需要身份验证)
- SAP社区(论坛与博客)
- 本地HAC:
http://localhost:9001/hac
注意:本技能基于SAP Commerce Cloud 2211+(2025年9月)。对于更早的版本,部分功能与API可能有所不同。