SAP Commerce(SAP Hybris)学习资料汇总

版本号:v1.05 2020年4月13日

<span id="toc"></span>
@TOC

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<Enter>.

一旦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: <yacceleratorstorefront>/web/webroot/_ui/addons/<addon_name>


source: <addon_name>/acceleratoraddon/web/src
target: <yacceleratorstorefront>/web/addonsrc/<addon_name>, 装的java代码。文件copy由build callback实现:

  1. The system scans for every extension that has a specific acceleratoraddon folder. Marker folders are defined as follows:
  • ${extension-path}/acceleratoraddon/web/webroot/_ui
  • ${extension-path}/acceleratoraddon/web/webroot/WEB-INF
  1. For each AddOn that is found, the system identifies the target extension.

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

  1. ant extgen
  2. 自定义Storefront
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.xml where <$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.

如何处理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

基于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 <component> 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里找到。
在这里插入图片描述

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.

Module

开发环境相关

一定在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.

回到目录

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.

A media item in SAP Commerce is not a physical file, but a reference to that file.
SELECT * FROM table WHERE PK=X

回到目录

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](https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/8c272b17866910149ebec2c6a065acfa.html)
   * [platform services](https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/8c2aa81c86691014b5a7ac327f4d2133.html): forms a part of the SAP Commerce ServiceLayer and comprises the functional and business services.
   * [processing](https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/8c31214d866910149dc3d1ccb5ff99d8.html): The CronJob Service, The Task Service, and the Process Engine.
   * [tomcatembeddedserver](https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/8c7334bc86691014a31086ee85989802.html) : provides an API to run an embedded servlet container. The tomcatembeddedserver extension provides a Tomcat-based implementation of this API.
   * [validation](https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/8c7d417d866910148908e5b4b0bcd860.html)
  • 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

只要在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三大过程:

  1. preparation: 检查环境变量的文件夹是否存在。然后解析dependency,如果A depends B,那么B一定先于A build. Build framework进行初始化操作,将build.xml拷贝到每个Extension的文件夹下。生成extenson的源代码。为Service layer生成model。不管是哪种build scope,这一步都会执行。
  2. dependency update
  3. extension building:before_build callback target, 运行validation,生成源代码文件,编译Extension的core和web module. 运行after build callback.

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.

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.

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.
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:Codecommerce-suite-6.7.0hybrisbinplatformextplatformservicessrcdehybrisplatformorder

order service

DefaultOrderService: 在附近的impl文件夹内。行为抽象成strategy.

一些common功能

回到目录

backoffice

回到目录

其他网友的资料

SAP成都研究院Commerce开发人员Zhang Jonathan的三篇概述文章:

Jerry Wang的文章:

其它文章:

评论

暂无评论