新建一个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的原创文章,尽在:"汪子熙":

网友评论