File

feature-libs/product/bulk-pricing/components/bulk-pricing-table/bulk-pricing-table.component.ts

Implements

OnInit

Metadata

selector cx-bulk-pricing-table
templateUrl ./bulk-pricing-table.component.html

Index

Properties
Methods

Constructor

constructor(routingService: RoutingService, bulkPricingService: BulkPricingService)
Parameters :
Name Type Optional
routingService RoutingService No
bulkPricingService BulkPricingService No

Methods

formatQuantity
formatQuantity(tier: BulkPrice)
Parameters :
Name Type Optional
tier BulkPrice No
Returns : string
getPrices
getPrices()
ngOnInit
ngOnInit()
Returns : void

Properties

priceTiers$
Type : Observable<[] | undefined>
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
Component
Html element with directive

result-matching ""

    No results matching ""