File
Implements
Metadata
| selector |
cx-bulk-pricing-table |
| templateUrl |
./bulk-pricing-table.component.html |
Methods
|
formatQuantity
|
formatQuantity(tier: BulkPrice)
|
|
|
|
|
|
Protected
Readonly
PRODUCT_KEY
|
Type : string
|
Default value : 'productCode'
|
|
|
import { Component, OnInit } from '@angular/core';
import { BulkPricingService } from '@spartacus/product/bulk-pricing/core';
import { RoutingService } from '@spartacus/core';
import { BulkPrice } from '@spartacus/product/bulk-pricing/core';
import { Observable } from 'rxjs';
import { switchMap } from 'rxjs/operators';
@Component({
selector: 'cx-bulk-pricing-table',
templateUrl: './bulk-pricing-table.component.html',
})
export class BulkPricingTableComponent implements OnInit {
protected readonly PRODUCT_KEY = 'productCode';
priceTiers$: Observable<BulkPrice[] | undefined>;
constructor(
protected routingService: RoutingService,
protected bulkPricingService: BulkPricingService
) {}
ngOnInit() {
this.priceTiers$ = this.getPrices();
}
formatQuantity(tier: BulkPrice): string {
let formattedQuantityRange = '';
if (!tier.maxQuantity) {
formattedQuantityRange = tier.minQuantity + '+';
} else {
formattedQuantityRange = tier.minQuantity + ' - ' + tier.maxQuantity;
}
return formattedQuantityRange;
}
getPrices(): Observable<BulkPrice[] | undefined> {
return this.routingService.getRouterState().pipe(
switchMap((state) => {
const productCode = state.state.params[this.PRODUCT_KEY];
return this.bulkPricingService.getBulkPrices(productCode);
})
);
}
}
<ng-container *ngIf="priceTiers$ | async as priceTiers">
<div class="container" *ngIf="priceTiers.length > 0">
<table class="table">
<thead class="thead-light">
<tr>
<th scope="col">{{ 'bulkPricingTable.quantity' | cxTranslate }}</th>
<th scope="col">{{ 'bulkPricingTable.price' | cxTranslate }}</th>
<th scope="col">{{ 'bulkPricingTable.discount' | cxTranslate }}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let tier of priceTiers">
<td>{{ formatQuantity(tier) }}</td>
<td>{{ tier.formattedValue }}</td>
<td>{{ tier.formattedDiscount }}</td>
</tr>
</tbody>
</table>
</div>
</ng-container>
Legend
Html element with directive