SAP Spartacus 的基于outlet 的页面扩展
2023-09-14 09:02:52 时间
outlet 是 SAP Spartacus 提供 partners 一种将 custom UI 插入 Spartacus 标准 DOM 的一种手段。
outlets get added for each slot when page templates, slots or components are dynamically rendered.
outlet的label和被包裹的element name属性一致。
需求:在Spartacus product明细页面(Product detail page, 缩写PDP)里增添逻辑:如果一个产品的库存小于300,显示“Limited offer”的提示信息,如下图所示:
下面是具体实现方法:
新建一个Outlet Component:
import { Component, OnInit } from '@angular/core';
import { Product, ProductService } from '@spartacus/core';
import { CurrentProductService } from '@spartacus/storefront';
import { Observable } from 'rxjs';
@Component({
selector: 'app-outlets',
templateUrl: './outlets.component.html',
})
export class OutletsComponent implements OnInit {
hotProduct$: Observable<Product> = this.productService.get('816780');
currentProduct$: Observable<Product> = this.currentProductService.getProduct();
constructor(private productService: ProductService, private currentProductService: CurrentProductService) { }
ngOnInit() {
}
}
页面模板:
<ng-template cxOutletRef="Section1" cxOutletPos="before">
<h1>Hot sale</h1>
<cx-product-list-item
*ngIf="hotProduct$ | async as product"
[product]="product"
></cx-product-list-item>
</ng-template>
<ng-template cxOutletRef="PDP.PRICE" cxOutletPos="before">
<h3
class="text-danger"
*ngIf="(currentProduct$ | async)?.stock.stockLevel < 300"
>
Limited offer!
</h3>
</ng-template>
在NgModule里,将outlet Component加入到exports区域里:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { OutletsComponent } from './outlets.component';
import { OutletRefModule, ProductListModule } from '@spartacus/storefront';
@NgModule({
declarations: [OutletsComponent],
imports: [
CommonModule,
OutletRefModule,
ProductListModule
],
exports: [OutletsComponent]
})
export class OutletsModule { }
相关文章
- 73. 如何手动通过增强的方式,给 SAP ABAP 数据库表增添新的字段
- 不借助 Fiori client,直接在手机浏览器里调用 SAP UI5 BarcodeScanner 实现条形码扫描的可能性?
- SAP S/4HANA Cloud 上 in-app 和 side-by-side 两种扩展方式的介绍
- SAP UI5 OData谣言粉碎机:极短时间内发送两个Odata request,前一个会自动被cancel掉吗
- 一个有用的Chrome扩展应用:SAP UI5 Inspector
- sap.ca.ui.utils.busydialog - scenario1 - opportunity opened
- SAP CRM扩展字段的元数据仓库
- 如何在SAP S/4HANA Fiori UI上创建新的扩展字段
- 如何在 SAP Spartacus 产品明细页面添加自定义 UI
- SAP 电商云 Spartacus UI 页面的 page guard 是从什么地方解析的
- SAP 电商云 UI 服务器端渲染的建议架构
- SAP 电商云 Spartacus UI 回归测试 b2b-replenishment-checkout-flow.core-e2e-spec.ts
- SAP 电商云 Spartacus Schematics 开发环境搭建
- SAP Cloud for Customer 2102版本如何使用Key User Tool创建扩展字段 - extension field
- SAP CRM content management中文件下载的调试
- 关于SAP Fiori Smart Template开发的一些实际例子
- 使用 Visual Studio Code SQLite 扩展来浏览 SAP Cloud Application Programming 数据库
- SAP云平台上的Fiori Launchpad tile数据是如何从后台取出来的
- 如何使用Key User Tool扩展SAP S/4HANA Fiori UI
- SAP fiori backend determine cache setting
- SAP OData 开发从入门到提高教程的目录