zl程序教程

您现在的位置是:首页 >  其他

当前栏目

SAP Spartacus如何使用自定义的Cart Service

SAP 如何 自定义 Service Spartacus 使用 Cart
2023-09-14 09:02:52 时间

新建一个CartService,将AcmtiveCartService设置成父类:

import { Injectable } from '@angular/core';
import { ActiveCartService } from '@spartacus/core';

@Injectable()
export class CustomerCartService extends ActiveCartService {
    addEntry(productCode: string, quantity: number): void {
        super.addEntry(productCode, quantity);
        console.log('20201122 add entry to cart: ' +
            productCode + ' quantity: ' + quantity);
    }
}

在app.module.ts里,将CustomerCartService注入:

最后运行时,将product添加到购物车后,能观察到我们自定义Cart Service里的打印信息:

更多Jerry的原创文章,尽在:“汪子熙”: