SAP Spartacus和product相关的标准normalizer

时间:2022-07-24
本文章向大家介绍SAP Spartacus和product相关的标准normalizer,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

以product name normalizer为例:

路径:C:CodeSPAspartacusprojectscoresrcoccadaptersproductconvertersproduct-name-normalizer.ts

拷贝下类的名称: ProductNameNormalizer

如果想运行时调试,在Spartacus-core.js里,根据这个名称搜索,找到对应的JavaScript function:ProductNameNormalizer_Factory:

/**
 * Construct an `InjectableDef` which defines how a token will be constructed by the DI system, and
 * in which injectors (if any) it will be available.
 *
 * This should be assigned to a static `ɵprov` field on a type, which will then be an
 * `InjectableType`.
 *
 * Options:
 * * `providedIn` determines which injectors will include the injectable, by either associating it
 *   with an `@NgModule` or other `InjectorType`, or by specifying that this injectable should be
 *   provided in the `'root'` injector, which will be the application-level injector in most apps.
 * * `factory` gives the zero argument function which will create an instance of the injectable.
 *   The factory can call `inject` to access the `Injector` and request injection of dependencies.
 *
 * @codeGenApi
 */
function ɵɵdefineInjectable(opts) {
    return {
        token: opts.token,
        providedIn: opts.providedIn || null,
        factory: opts.factory,
        value: undefined,
    };
}

随着构造函数一起传进来的配置对象:

这个配置对象的赋值是通过eeinject(OccConfig)进行的:

converter调用的地方:Pipeable operator to apply converter logic in a observable stream

 convertSource(source, injectionToken) {
        return this.getConverters(injectionToken).reduce((target, converter) => {
            return converter.convert(source, target);
        }, undefined);
    }

向Commerce Cloud后台发起请求:

得到完整的occ地址: