美文网首页SAPSAP 修行SAP 实用篇
SAP Spartacus产品页面的normalizer

SAP Spartacus产品页面的normalizer

作者: 华山令狐冲 | 来源:发表于2020-11-29 13:38 被阅读0次

新建一个product-name-normalizer.ts文件,源代码如下:

import { Injectable } from '@angular/core';
import { Converter, Occ, Product } from '@spartacus/core';

@Injectable()
export class ProductNameNormalizer implements Converter<Occ.Product, Product>{
    convert(source: Occ.Product, target?: Product): Product {
        if (!!source.name) {
            target.name = source.name.replace(/ /g, '--').toLocaleLowerCase();
        }
        return target;
    }
}

在module里,注入这个ProductNameNormalizer:

providers: [{
    provide: PRODUCT_NORMALIZER, useClass: ProductNameNormalizer,
    multi: true
  }
  ]

最后的产品明细页面,无论是url还是页面本身的product.name, 都已经被这个Normalizer处理过了:

相关文章

网友评论

    本文标题:SAP Spartacus产品页面的normalizer

    本文链接:https://www.haomeiwen.com/subject/ahhmektx.html