SAP Commerce(SAP Hybris)学习资料汇总
版本號:v1.06 2020年11月24日
所有的架構圖在這個單獨的帖子里。
導航目錄
- SAP官方幫助文檔
- configuration
- 如何運行
- Filters
- 容器化支持
- Installer-Recipe
- Extension和Addon的概念
- 一步步創建一個新的addon
- 如何處理dependency
- localextensions.xml
- Internationalization-and-localization
- ant
- Hybris-initialization和update過程
- Model
- SAP-Commerce里的Spring框架
- AOP
- [一個向導]
- Accelerator
- API-registry
- search-and-navigation
- solr-server
- Module
- 開發環境相關
- Service-Layer
- Model
- Interceptor
- Hook
- event-system
- Hybris-Type-System
- Platform-Services-and-Utilities
- platform module feature
- platform module architecture
- platform module implementation
- Distribution-process
- cache
- Charon
- Cluster
- container-support
- filters
- Impex - 使用api導入導出數據
- Internationalization-and-Localization
- Jalo-Layer
- Jalo-session
- logging
- media
- oauth2
- order
- europe1
- Ordering-Process
- payment
- Processing
- Global Templates
- Product建模的兩種方式
- type-system
- 所有可用的類型列表
- items.xml詳述
- dynamic-attribute
- Enumerations
- script
- search
- Chinesepaymentservices
- backoffice
- 其他網友的資料
- SAP成都研究院Commerce開發人員Zhang Jonathan的三篇概述文章:
- Jerry Wang的文章:
- 其它文章:
SAP官方幫助文檔
configuration
配置文件和運行時在admin console里兩種方式
The HYBRIS_RUNTIME_PROPERTIES environment variable allows you to set a path that points to a custom properties file.
運行時動態更新配置:RuntimeConfigLoader,定期輪詢properties文件是否有變化。
配置文件的編碼問題:encoding
默認: ISO 8859-1
configuration template是一系列配置文件的集合,分devlelop和production兩種,結構如下:
- A local.properties file
- Configuration files for Apache Tomcat, such as wrapper.conf or wrapper-debug.conf
- A license file
兩種配置文件:project.properties and local.properties.
Project properties are the SAP Commerce defaults, while local properties is where you may define your own configuration for your extension.
- The project.properties file is located in the <HYBRIS_BIN_DIR>/platform directory, and provides factory default settings. It is not recommended to edit this file.
- The local.properties file is a working copy of the project.properties file, located in the <HYBRIS_CONFIG_DIR> directory. It allows you to override default settings from the project.properties file.
文件目錄,層級結構
- bin/platform: The core SAP Commerce platform extensions that are loaded on startup. This directory also has the build framework, and extension templates.
- data: Data files such as media files and LucerneSearch indexes. The directory also contains HSQLDB data files, if you are using the default database in a test or development environment.
- log: Log files, including Tomcat and JDBC logs.
NEVER change anything within the bin directory. Do not keep any custom data configuration in this directory or any of the subdirectories. The upgrade process may replace the bin directory and subdirectories with a newer version of SAP Commerce and remove your changes.
回到目錄
如何運行
系統最低需求
默認的數據庫:HSQLDB
第三方軟件需求
如何安裝
- SAP Commerce 1905 requires JDK 11 or later. It is fully compatible with SAP Machine 11.
- 如何下載安裝包
Navigate to the <${HYBRIS_BIN_DIR}> /platform directory, call ant clean all to build the entire SAP Commerce solution.
Filters
包含一些默認filters的功能介紹。清單在這里
容器化支持
images
Installer-Recipe
- 不能用于生產用途。文件夾位置:installer/recipes. 這個鏈接包含了所有recipe的說明。
License文件:<HYBRIS_HOME>/config/license/installedSaplicenses.properties
如何生成license file
也不能在一個目錄里重復安裝不同的recipe:
Don’t use the installer to run one recipe after another on the same SAP Commerce. The installer won’t uninstall previous configurations, and doesn’t restore your SAP Commerce file system to its original settings. To install a different recipe, use a clean environment.
回到目錄
Extension和Addon的概念
- 若干extensions組合在一起,以module的形式發布。
An extension can contain business logic, type definitions, a web application, or a Hybris Management Console configuration. That way, you link up in one place all of the functionality that covers a certain field of use, for example a webshop.
Addon是一種特殊的extension,擴展了Commerce Accelerator的功能。這種extension添加了UI頁面,但又沒有直接修改Storefront的實現。
AddOns extend the functionality of the SAP Commerce Accelerator. They are a type of extension that allow you to add front-end files such JSP, HTML, CSS, and JavaScript files, and images without modifying the storefront front-end files directly.
SAP Commerce Accelerator is built on an extensive framework that includes a template for storefront implementation. AddOns and extensions provide a well-defined infrastructure for third party developers to plug in their own functionality.
Using AddOns, you can extend the functionality of Commerce Accelerator without editing the core code base. The core code base in this context means the Commerce Platform, and all additional extensions delivered with Commerce Accelerator. An AddOn is a regular extension that may, or may not, provide additional front-end components to Commerce Accelerator.
Addon也是一種Extension,Storefront extension被addon擴展,在其extesnioninfo.xml里引用這個addon:
An AddOn is a regular SAP Commerce extension that is configured using the extensioninfo.xml file, located in the root folder of the AddOn. Additionally, the storefront extension that is extended by an AddOn has to reference this AddOn in the extensioninfo.xml file. The structure of this file is exactly the same as any regular extension.
Addon是accelerator Storefront的擴展技術。典型的文件夾層級結構:
the web folder contains both the src and the webroot subdirectories. After putting all the components you want to add into the proper folders, you need to run the following command on your system: ant build.
一旦build,會自動拷貝文件到Storefront Extension里,自動創建新的文件夾來容納拷貝的文件:
- web/addonsrc, which contains the source code for each installed AddOn. This gets compiled automatically.
- web/webroot/WEB-INF/addons, which contains all the front-end components, such as images, JSP files, HTML files, and TAG files.
acc一旦升級,也不會覆蓋掉我們的addon.
如果addon里直接添加jsp,css,圖片等,不需要build platform, 如果添加新的java code到target Extension,就需要build platform.
The front-end items are stored in the acceleratoraddon folder of an AddOn. The structure within the acceleratoraddon folder mirrors the folder structure within the web folder, which contains the front-end components of a regular extension.
Addon里的accelerator文件夾是如何拷貝到Storefront文件夾里的?規則在這個鏈接里。
source: <addon_name>/acceleratoraddon/web/webroot/_ui
target: /web/webroot/_ui/addons/<addon_name>
source: <addon_name>/acceleratoraddon/web/src
target: /web/addonsrc/<addon_name>, 裝的java代碼。文件copy由build callback實現:
- ${extension-path}/acceleratoraddon/web/webroot/_ui
- ${extension-path}/acceleratoraddon/web/webroot/WEB-INF
For each resource that is found in the acceleratoraddon folder, the system copies the contents to the target extension.
addoninstall工具的用法
使用addon定制化Storefront
在beans.xml里也可以給DTO增加新的屬性:
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="beans.xsd"><bean class="de.hybris.platform.commercefacades.product.data.ProductData"><property name="weight" type="int" /><property name="instruction" type="String" /><property name="additionalImage" type="de.hybris.platform.commercefacades.product.data.ImageData" /></bean><enum class="de.hybris.platform.commercefacades.product.ProductOption"><value>DIMENSIONS</value><value>MINIMAL</value></enum> </beans>Similarly to the item.xml file, the definitions in the beans.xml file are merged automatically. In the example above, the ProductData file is not part of our example extension, but it is extended from the commerceservices extension. That means that during this process, you extended the API because you modified the data model. You do not need to replace the facade in this instance. All you need to do is plug in the populator from your extension, and it can be done multiple times.
這個鏈接包含了一個表格,可以查詢Extension和Addon的ID和description.
一步步創建一個新的addon
- 總體架構
- Extension專題
An extension is an encapsulated piece of software that extends SAP Commerce functionality by either modifying existing features, or introduction new features.
Extension modules are structural elements of an extension.
Extension module是extension的一部分。
You can implement JUnit tests for the extension’s core extension module. The files for these JUnit tests must be located in the testsrc directory of the extension.
每個extension都有一個名叫core的 extension module,包含了該extension的type system definition,items.xml, 位于resources文件夾內。命名規范:
The name of this file is always defined accordingly: <extension>?items.xmlwhere<extension> -items.xml where <extension>?items.xmlwhere<extension> is the name of an extension.
與類型相關的Java source code文件也位于core extension module內。
Processing也是extension.
items.xml的鏈接.
- web extension module: 是extension的一部分,可以通過瀏覽器訪問:
To launch a web extension module via your web browser, go to the URL path to Platform on the server/name of extension/starting page. For example, if you are running myExtension locally on default settings, the URL would be http://localhost:9001/myExtension.
- Web application filter
- 如何創建新的extension
如何處理dependency
An extension that specifies an extension dependency will only be built once all the extensions specified in the list have been built.
Extension dependencies to the Platform extensions are very common. SAP Commerce therefore includes a special mechanism resolving such dependencies. This mechanism assumes that all extensions which are not located within the <HYBRIS_BIN_DIR> /platform/ext directory have extension dependencies on the Platform extensions.
his mechanism is enabled or disabled using the autoload attribute in the localextensions.xml file. By default the autoload attribute is set to true, and the extension dependency resolving mechanism is enabled. This means you do not need to add the Platform extensions to your extensioninfo.xml file to specify dependencies.
localextensions.xml
在config文件夾下:The localextensions.xml file overrides the extensions.xml file.
- extensions.xml: <HYBRIS_BIN_DIR>/platform, Do not modify this file.
This file is used as a template and a fallback for the localextensions.xml file. Use localextensions.xml instead.
Internationalization-and-localization
- 什么是extension的core module:
A core module consists of an items.xml file (and therefore allows to add new types to the system), a manager class, classes for the JaLo Layer and the ServiceLayer and JUnit test classes. The following directories are required: /src, /resources, /testsrc.
While the Commerce Platform can run without any package, no package can run without the Commerce Platform.
Commerce platform也是由extension組成的,稱為core extension. 在這些core extension之上才是build framework,和tomcat server.
ant
ant all和all clean all的區別:
If you run builds of SAP Commerce using ant all, the SAP Commerce build framework will have the compiled files from other extensions available. An extension dependency may then still exist, but will not be noticeable.
In contrast, if you run SAP Commerce builds using the ant clean all, the build framework will delete the compiled files prior to building extensions. A build failure to unmet extension dependencies is much more likely to occur this way.
回到目錄
Hybris-initialization和update過程
什么是Hybris的initialization:
Initialization drops existing type definitions from the database prior to rebuilding, so the entire type system is created from scratch. So during an initialization, type system definitions are created to match the type system definition in the items.xml files.
Initialization的過程generate the database schema and the type system, and import any essential system data.
Platform目錄下執行:ant initialize
Update: items.xml里定義的新類型,會施加到類型系統里。
upgrade
Model
- 非常詳細的講解CMS模型的網頁
- 基于items.xml的定義生成types. 通過core extension實現。
Technically, every extension that uses any SAP Commerce type depends on the core extension because the type system is part of the core extension.
An extension may depend on several other extensions. For example, if your extension allows running imports through Backoffice using a wizard, you have an extension dependency not only on the backoffice extension, but also on the impex extension.
Impex也是extension. Extension能使用其依賴的extension core module包含的resources和source,但web extension module的東西沒辦法訪問。
Impex modifier列表
Abbreviations語法
導入product的例子:腳本
flexible search里的!感嘆號的用法,exclude subtype
MediaDataTranslator負責導出media內容。
SAP-Commerce里的Spring框架
是Service Layer的foundation.
Dependent Injection: 組件的依賴不是其自身維護,而是配置在外部。
Dependency injection is a software architecture pattern in which a component’s dependencies are not managed by the component itself but are configured externally.
A so-called container (application context) reads the configuration file, resolves the dependencies, and puts together the objects. When the objects are ready, all the dependencies are already injected.
<bean class="de.hybris.platform.order.OrderService"><property name="stockService"><bean class="de.hybris.platform.stock.StockService"/></property> </bean>xml文件的位置:${HYBRIS_BIN_DIR}/platform/ext/core/resources
命名規范:
There you find files with the name pattern |component|-spring.xml, where is something like product, order, i18n, security, and so on. For the beans themselves, a name pattern such as xyzService is recommended, such as: productService, catalogService, and so on.
Service Layer的API通過interface暴露出來。interface的實現就是Spring beans,id name可以從SAP commerce API doc里找到。
AOP
[一個向導]
- 創建新extension
- eclipse里只導入剛創建好的extension:
<HYBRIS_BIN_DIR>/custom/training. - 手動添加the latest release of Spring MVC library?
- Put the Spring MVC library JAR into the web/webroot/WEB-INF/lib folder of the training extension.
If you use Eclipse, be sure to reference the Spring MVC library JAR in the project’s build path, too. You need the spring-webmvc.jar in version 3.2.8
- 在platform文件夾下,Call ant clean all to build the entire SAP Commerce software package.
- 以debug方式啟動服務器:hybrisserver.bat debug
- 創建新的controller和jsp view - hello world級別的
- Product練習
- Service extension
- Extensibility的奧秘:platform/ext/platformservices/resources/product-spring.xml
在我們自己的Extension里:
training/resources/training-spring.xml
Because your configuration file is loaded after the original configuration file, Spring uses your alias instead of the original one. Thus, wherever a reference to productService turns up, Spring uses your trainingProductService instead.
Eclipse里修改Extension的items.xml可以自動生成model?
- 新的model屬性詳解
- key service overview
- naming convention
- 什么是DTO - Data作為naming convention?
Data Transfer Objects (DTOs) are objects created to only contain values and have no business logic except for getter and setter methods. Using DTOs, you can “combine” SAP Commerce items - for example, this document adds price- and media-related data to a product object.
Strategy: nA solution is to have the Business Services delegate to finer-grained components if necessary. This approach is known as Strategies.
Autowiring的優缺點
Accelerator
SAP Commerce Accelerator is a ready-to-use web implementation template that enables you to jumpstart your implementation and easily build and maintain a feature-rich and flexible commerce solution.
主要模塊
Architecture討論
共有的一些Extension
responsive?
storefront
結構解析
technical design guide
Accelerator for China
為什么要用alias?Extensibility!
A use case maybe when you want to customize some beans that are already defined somewhere in a modular application (each module is a spring project for example), the bean maybe defined by a third-party framework/API or even your team. In that case you want that only inside your spring project call the customized version without altering other modules (projects), to do that just add the alias in your spring configuration which is indeed a powerful feature:
<alias alias="globalBeanService" name="customizedBeanService" />Hence, whenever spring find a call to the globalBeanService, it will inject customizedBeanService for you inside your specific module. Without this feature, you should go through all classes and modify the bean manually!!
yrequest scope:
may be used for binding beans to the application context for a single request. Upon session deactivation, the beans are no longer referenced from the application context, allowing them to be garbage collected. This is similar to a standard Spring request scope but is used outside of a web application context.
Bean被application context管理,所有extension的的配置文件形成core application context. 每個tenant都有自己的Application Context.
The construction process uses the classloader of the core extension. It has, as its parent, the (singleton) global application context.
how to Adding Bean Definitions to Core ApplicationContext
bean id一定要unique,否則最后load的extension bean會overwrite之前的。
Web Application Context - why we need it?
To define the beans part of the Web Module of an extension or with scopes not available to the global ApplicationContext or core application contexts, like session or request, you need to configure a web ApplicationContext in the web.xml file. You also need access to the core ApplicationContext to access beans of the Core Module, such as services.
For this access, SAP Commerce provides a HybrisContextLoaderListener for setting the core ApplicationContext automatically as parent of your web ApplicationContext. With that, you can use the core bean definitions, for example to inject them into your web ApplicationContext beans. If you make a getBean call to your web ApplicationContext, it is checked whether there is a definition available. If not, the parent ApplicationContext is used.
- Security
- from jalo to service layer - migration and transition
- after save event hook
- startup tuning
- disable JUnit tenant
- suspend and resume
- test with junit
- mockito
- China Accelerator
API-registry
也是由一系列Extension組成。
search-and-navigation
solr-server
Module
開發環境相關
- 用Eclipse搭環境
一定在build之后再導入import,否則報class找不到。
If this happens, it means that you probably imported the project before you first run the initial Ant in the platform directory. The eclipse errors occur, because some classes are initially copied during this Ant process. So make sure that you first run Ant and then setup eclipse.
- 如何update - 替換整個bin文件.
- 調試,使用debug模式和develop configuration template.
Service-Layer
是三層的統稱:ServiceLayer Framework (including the actual ServiceLayer, the Infrastructure Services, and the Business Services)
relies on so-called models, which are POJOs. Attributes on models have automatically generated getter and setter methods. Models are generated based on types.
- Service layer
- Service Layer Direct
- 實現細節討論
Service Layer的消費者為MVC controller,web service或者script.
A service holds the logic to perform business processes and provides this logic through a number of related public methods. These public methods usually are defined in a Java interface. Most often these methods operate on the same kind of model object, for example product, order, and so on.
和persistence layer是松耦合的。
所有功能都通過service暴露:
- Business Services implement business use cases, such as cart handling or back order.
- Infrastructure Services provide the underlying technical foundation, such as internationalization, import, export, and so on.
- System services provide functionality required by the ServiceLayer, such as model handling and session handling.
其實就是interface,通過models和其他service交互。
Strategy
A service may delegate parts of its tasks to smaller micro-services, called strategies. The service then serves as a kind of fa?ade to the strategies.
Clients still use the service and its stable API. But under the hood the functionality is split into multiple parts. Because these parts are smaller and very focused to their task, it is easier to adapt or replace them. Strategies therefore help to further encapsulate behavior and make it more adaptable.
其實就是策略模式。
Model
Models are a new way to represent SAP Commerce items. Each model contains all item attributes from all extensions thus unifying access to an item’s data. Models are generated from the type system of SAP Commerce.
Models are used by DAOs, services, strategies, converters, and facades.
During a SAP Commerce build, the build framework generates Model classes and configuration files for each item type. Models are generated across all extensions, no matter whether the extension is available in source code or in binary only. The Model generation process also ignores the value of the generated attribute of the element in the extensioninfo.xml file of the extension.
Models are generated into the bootstrap/gensrc directory.
You might ask why the generated Models end up in the platform and not in the extension where the type is defined? This is due to the way the SAP Commerce Build Framework operates.
naming convention: 以Model結尾。
As Models are generated during a early phase in the SAP Commerce build process - before actually building any extension - the Models are available by compile time.
- lifecycle
A Model represents a state in the database. The representation is not live, that means that modified Model values are not written to the database automatically. Instead, when you modify a Model, you must explicitly save it to the database to have its state reflected there.
Model可以從數據庫load,用構造函數或者工廠方法新建。
Model context
- ModelService
一個java bean:
The ModelService is a service that deals with all aspects of a Model’s life cycle. It is available in Spring under the ID modelService and implements the de.hybris.platform.servicelayer.model.
- Loading Models by pk
- Loading Models from items
- Creating Models
- Updating Models
- Deleting Models
增刪改查CRUD方法都有。
Interceptor
只for model:
Interceptors check whether constraints set for the behavior of life cycles of models are fulfilled. Use interceptors to make sure you delete or persist the correct data only, and that you handle data properly.
Hook
Hooks for Initialization and Update Process
Use the @SystemSetup annotation in any ServiceLayer class to hook ServiceLayer code into the SAP Commerce initialization and update life-cycle events. In this way, you can provide a means for creating essential and project data for any extension.
Java annotation的簡介
Annotate the classes whose methods are to be executed. In the following example, the method createImportantModelDuringInitProcess is executed during the initialization process when the essential data for extension myextension is created.
@SystemSetup(extension = MyExtension.EXTENSIONNAME) public class SomeClass ... {@SystemSetup(extension = MyExtension.EXTENSIONNAME, process = Process.INIT, type = Type.ESSENTIAL)public void createImportantModelDuringInitProcess(){//create the model here} ...event-system
接收和發送commerce的事件。
event-service基于Spring event系統。
DefaultEventService allows you to register event listeners and publish events.
There is a DefaultEventService that implements the EventService interface (de.hybris.platform.servicelayer.event package). To use this service, add a Spring resource to your class.
@Resource private EventService eventService;alias
In addition to the actual bean definition with an ID prefixed with default, there is an alias for the bean. The idea is that you should use the alias to override instead of using the actual bean ID in a hard-wired way. This is to ensure extensibility. You can override the alias ID and still have access to the original bean.
回到目錄
Hybris-Type-System
類型系統是對象的模板。platform里每個對象都是類型的實例。
Types定義了持久化對象:
- Attribute存儲對象的數據。
- Deployment定義數據庫表
- java class
A Type is the type definition in items.xml and its Java implementation.
An object instance of a type is called an item:
類型分兩種:System-related types and business-related types.
System-related types又由下列類型組成:
Infrastructure types: ComposedTypes (also referred to as ItemTypes) set up type definitions and may carry attributes to hold information. In the end, every persistent object in the SAP Commerce is an instance of ComposedType or of one of its subtypes.
Business-related types: (like Order, Discount, Shoe) allow you to manage product and / or customer information so that you can run your business.
every object stored in SAP Commerce is an instance of a type. Even type definitions are instances of the type Type. This means that there are two aspects of a type definition: it is an item and, at the same time, it defines other items.
To differentiate between normal object instances and type definitions, non-type objects in Platform are referred to as items. The lower case spelling item refers to an object in Platform; the upper case spelling Item refers to the type definition.
小寫的items代表platform里non-type對象, 大寫的代表類型定義。
The following code snippet defines an item called SpecialProduct that is a subtype of Product but its type is not defined as a ComposedType, but as a SpecialComposedType (via the metatype attribute). Instances of SpecialProduct are thus subtypes of Product, but the type definition is stored as a SpecialComposedType.
<item code="SpecialProduct" metatype="SpecialComposedType" extends="Product">類型定義attribute,如同Java 類定義fields, attribute可以是復合類型或者簡單Java類型。
Platform-Services-and-Utilities
三大module:
platform module feature
provides a range of features related to the main functionality of a SAP Commerce installation, that is, containerization, data management, synchronization, security, or localization.
- build framework:code generation, jRebel
- Caching, persistence layer的一部分,減少到db的query,詳細在這, 也緩存flexible search結果。
- Secure HTTP Transactions: Charon
- Cluster 多節點共享數據庫。
- 容器化 Platform, solr和data Hub需要打三個鏡像。
- data retension
- data validation - before save: a JSR 303-compliant validation engine
- digital asset management
- filter for web application 一些常用filter列表:SessionFilter, ProfileFilter, Log4jFilter, RedirectWhenSystemIsNotInitializedFilter.
- value change log
- log
- media - 文件系統上的文件。
A media item in SAP Commerce is not a physical file, but a reference to that file.
- Polyglot Persistence - 把cart的存儲放到external memory
- [Product classification](The classification functionality enables you to define product attributes in a way different to the typing method. Classification-based attributes are called category features; they can also sometimes referred to classification attributes. Through classification, you can flexibly allocate category features that may change frequently. You can easily define and modify them because you manage them independently of the product type.)
- classification - 另一套分類系統?
- scripting engine
- search
- security
- permission
- cors support
- SSO
- User UML
- strict mode嚴格模式
- Suspend and resume
- Workflow
回到目錄
platform module architecture
The core extensions are autoloaded and they are located in <HYBRIS_BIN_DIR>/platform/ext.
- extension列表:
- catalog
- commons: provides core helper methods for templates. These methods are used for media neutral handling of content to be exported.
- formatter: converting item content to PDF, for example for converting an order to PDF.
- Translator framework mainly used for converting of HTML documents to another format, for example to Adobe InDesign.
- core extension: handles basic functionality such as persistence handling, the ordering process and contains the service layer functionality.
- deliveryzone: ext下面。
- hac. 可以只啟動hac.
To do this, run adminserver.bat instead of hybrisserver.bat. As you can see, web contexts are loaded for Administration Console only. You can therefore use this node strictly for administration purposes
- payment standard
- platform services: forms a part of the SAP Commerce ServiceLayer and comprises the functional and business services.
- processing: The CronJob Service, The Task Service, and the Process Engine.
- tomcatembeddedserver : provides an API to run an embedded servlet container. The tomcatembeddedserver extension provides a Tomcat-based implementation of this API.
- validation
- ydocumentcart : template extension, allows you to store selected types in an alternative storage. It uses the polyglot persistence query language.
- yempty: a predefined extension to be duplicated. The copy serves as starting point for creating a new extension, typically used for customer specific implementations. 還有yvoid.
platform module implementation
- build framework
只要在config文件夾localextensions.xml下面的Extension,都會被build framework控制。
ant target
在哪個目錄下執行ant all決定了build scope:Platform-wide and extension-wide.
The SAP Commerce version is included in the build.number file located in the <HYBRIS_BIN_DIR>/platform directory.
build三大過程:
build過程中根據items.xml里的type definition創建java文件:
- ServiceLayer的Model文件
- Abstract Jalo Layer classes (carrying a prefix, such as Generated). These files are generated anew if you have modified the items.xml for the extension
- Non-abstract Jalo Layer classes. These are only generated when the file does not yet exist. If a file with the same name exists, the file is not generated anew.
基于javac ant task,比較.java和.class的timestamp.
SAP Commerce contains a process to include custom files in the <HYBRIS_BIN_DIR> directory. This process copies the content of the <HYBRIS_CONFIG_DIR>/customize directory to the <HYBRIS_BIN_DIR> directory.
Distribution-process
All extensions and the Commerce Platform are packaged according to filtersets. You can find the standard filtersets in hybris/bin/platform/resources/ant/dist/filtersets.xml. There are three predefined filters : platform.filter, extension.source.filter and extension.binary.filter.
A .classpath file specifies which Java source files and resource files in a project are considered by the Java IDE (Eclipse, Intellij IDEA), and specifies how to find types outside of the project. When some extension ( for example commerceservices) is released as a binary, a java library file is created ( for example commerceservicesserver.jar) and a path to this file needs to be inserted to a .classpath file, instead of paths to sources. When some extension is released as a source, a .classpath file contains a path to sources and libraries. That’s why we have separate .classpath and .classpath_binary files.
- Extension Library Management Using Maven
- JRebel
- gradle
cache
flexiblesearch也能被cache.
Charon
Cluster
container-support
filters
The PlatformFilterChain is triggered on every HTTP request. The default Spring bean of the PlatformFilterChain is registered in the Spring application context in the filter-spring.xml file. It instantiates filters that are necessary for every Web application.
However, every Web application can instantiate other filters in their own Spring application context file. In other words, any filter can be easily activated or deactivated in the Spring application context for every single Web application.
在core extension里有個文件:core-filter-spring.xml
It instantiates filters that are necessary for every Web application.
Impex - 使用api導入導出數據
Internationalization-and-Localization
Jalo-Layer
已經過時了,被Service layer取代。包含data model和用Java實現的business logic.
每次build都會根據items.xml生成abstract Java類和非abstract(只生成一次)
缺點是data model和Java類緊耦合,一旦data model變了,Java類也需要調整。所以被service layer取代了。很像gateway的SEGW里的DPC,DPC_EXT. 注意這兩個Java類的位置不一樣:
- gensrc/de/hybris/jalolayer/sample/GeneratedMyType.java
- src/de/hybris/jalolayer/sample/MyType.java
Jalo-session
包含當前用戶的數據和設置。
logging
media
oauth2
The oauth2 core extension has replaced the webservicescommons/oauthauthorizationserver extension. It exposes the HTTP endpoint as an authorization server.
- OAuth client的配置
order
Ordering, Payment and Pricing Standards
- order extensibility - interceptor
The Order Framework architecture is designed to provide two level separation in the framework - Separation of Concerns and Separation of AbstractOrder type.
- AbstractOrderService
The AbstractOrderService is the main component for the Order Framework extensibility. It delegates the particular method calls to the dedicated strategies, DAOs, and subservices.
位置:
C:\Code\commerce-suite-6.7.0\hybris\bin\platform\ext\platformservices\src\de\hybris\platform\order
order service
DefaultOrderService: 在附近的impl文件夾內。行為抽象成strategy.
回到目錄
interface CreateOrderFromCartStrategy
Default implementation EventPublishingSubmitOrderStrategy sends SubmitOrderEvent. If you wish to do something else, then you can implement the interface and inject it into the Order Service that provides the list of strategies fired one after another.
- CreateOrderFromCartStrategy
- SaveAbstractOrderStrategy
- DataAccessObjects
europe1
The europe1 extension handles all price, tax, and discount calculations in SAP Commerce.
- Extensible Cart Calculation
Ordering-Process
payment
Payment Transaction and Delivery Mode Handling
Processing
Processing in SAP Commerce extensively uses the task service, the cronjob service, and the process engine. Each of them are provided by the processing extension.
有一個BPM, task service, cronjob service.
不同的extension可以extend同一個bean:
Definitions of these Java Beans or Enums are merged across extensions. For example, if two extensions specify a bean and enum with the same, fully classified class, the generated class includes the attributes from these two extensions. This way, you can extend already existing beans and enums, and do not have to subclass them, or replace references to the former bean and enum.
build的時候,model生成完之后就是java bean的生成。
重要:
Generated java files are located in {HYBRIS_BIN_DIR} /platform/bootstrap/gensrc directory.
Generated classes are located in {HYBRIS_BIN_DIR} /platform/bootstrap/modelclasses directory.
通過velocity script,一個template生成source code.
Global Templates
There are two default global templates to render beans and enums. These templates are used if there is no custom template defined for a specific bean or enum in the beans.xml file, or if a given template does not exist. The default templates are:
global-beantemplate.vm - for each bean
global-enumtemplate.vm - for each enum
You can find them in the platform/bootstrap/resources/pojo folder.
bean的生成邏輯
Product建模的兩種方式
type-system
Configured Types vs Runtime Types
Runtime types: with no definition in items.xml ; they are only defined in runtime in Backoffice.
Runtime Types are as persistent as all other items, since type definitions are stored in the database as well. However, when SAP Commerce is initialized, the entire type system is discarded and re-created from the contents of the items.xml files of all extensions. As Runtime Types are not backed by a file, they are removed and not re-created during a system initialization. In other words: whenever you initialize SAP Commerce, all Runtime Types are gone.
- atomictypes
For details on a list of the AtomicTypes that are generated upon Platform initialization, please refer to the atomictypes section of the core-items.xml file in the <HYBRIS_HOME> /bin/platform/ext/core/resources directory.
Unlike the other types, an AtomicType definition does not have a code attribute to set the unique identifier. Instead, the AtomicType class attribute is used as its reference.
SAP Commerce stores AtomicType instances in the database as strings (VARCHAR) or numbers (NUMBER)
所有可用的類型列表
items.xml詳述
service layer和jalo layer都和items.xml有關。
items.xml在Eclipse里修改之后立即生效的問題:
SAP Commerce comes with preconfigured builders for the Eclipse IDEInformation published on non-SAP site that support working with the items.xml file. Using Eclipse, whenever you edit an items.xml file, SAP Commerce automatically:
Jalo Layer: Generates Generated*.java source files (item classes) for all item types of your extension to the gensrc directory of your extension.
Jalo Layer: Refreshes the gensrc directory of your extension.
ServiceLayer: Generates *Model.java source files (model classes) for all item types of configured extensions to the bootstrap/gensrc directory
ServiceLayer: Refreshes the bootstrap/gensrc directory
Null Value Decorators in Models:類型JDK8的optional
items.xml的schema
deployment
什么時候需要指定一個deployment?
The typecode attribute must specify a unique number to reference the type. The value of the typecode attribute must be a positive integer between 0 and 32767 (2^15-1) and must be unique throughout SAP Commerce as it is part of the PK generation mechanism. Typecode values between 0 and 10000 are reserved for SAP Commerce-internal use. Typecode values larger than 10000 are generally free for you to use but there are lots of exceptions to that rule.
<HYBRIS_BIN_DIR>/platform/ext/core/resources/core/unittest/reservedTypecodes.txt
To see how SAP Commerce types are mapped to different databases, see the file bin/platform/ext/core/resources/core-advanced-deployment.xml.
類型系統的清理cleanup
dynamic-attribute
沒有持久化存儲,就是calculated fields
Enumerations
script
Groovy, BeanShell, JavaScript
search
- flexible search: 執行過程分兩階段:
pre-parsing into an SQL-compliant statement and running that statement on the database
例子:編寫基于type syste的statement,和db無關。用大括號注明類型名稱。
select {pk}, {code}, {name[de]} from {Product}編譯成SQL:
SELECT item_t0.PK , item_t0.Code , lp_t0.p_nameFROM products item_t0 JOIN productslp lp_t0 ON item_t0.PK = lp_t0.ITEMPK AND lp_t0.LANGPK= 9013632135395968WHERE (item_t0.TypePkString IN ( 23087380955301264 , 23087380955663520 , 23087380955662768 , 23087380955661760 ,23087385363574432 , 23087380955568768 , 23087380955206016 ) )執行權限問題:
By default, the user account assigned to a session is anonymous, so any FlexibleSearch query returns the search results matching the anonymous account by default. To run FlexibleSearch queries in the context of a user account different from anonymous, the session needs to be assigned to a different user account.
用代碼的方式消費
paging分頁機制
restriction限制條件
一些例子
tips and trips,技巧,最佳實踐
Query and JDBC Hints
- generic search
similar to Hibernate Criteria Queries. Hibernate is a collection of related projects, enabling developers to utilize POJO-style domain models in their applications in ways extending well beyond Object and Relational Mapping.
syntax語法
回到目錄
Chinesepaymentservices
- sample store
backoffice
- 一個實際的例子:2455449 - How-to: Hide Backoffice explorer-tree nodes based on user access rights
回到目錄
其他網友的資料
SAP成都研究院Commerce開發人員Zhang Jonathan的三篇概述文章:
- 從產品展示頁面談談Hybris的特有概念和設計結構
- 從產品展示頁面談談Hybris系列之二: DTO, Converter和Populator
- 從產品展示頁面談談Hybris系列之三:Hybris Service層介紹
Jerry Wang的文章:
- 淺談SAP CRM和Hybris Commerce里的價格架構折扣
其它文章:
- 安裝和目錄介紹
- stackoverflow上jalo layer和service layer的區別
總結
以上是生活随笔為你收集整理的SAP Commerce(SAP Hybris)学习资料汇总的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 99元睡大厅沙发?酒店回应:会免费升房
- 下一篇: SAP云平台 Document Info