File

feature-libs/product-configurator/rulebased/components/price/configurator-price.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-configurator-price
templateUrl ./configurator-price.component.html

Index

Properties
Methods
Inputs
Accessors

Inputs

formula
Type : ConfiguratorPriceComponentOptions

Methods

displayFormula
displayFormula()

Verifies whether the price formula should be displayed.

Returns : boolean
  • 'true' if price formula should be displayed, otherwise 'false'
displayPriceOnly
displayPriceOnly()

Verifies whether only price should be displayed.

Returns : boolean
  • 'true' if only price should be displayed, otherwise 'false'
displayQuantityAndPrice
displayQuantityAndPrice()

Verifies whether quantity with price should be displayed.

Returns : boolean
  • 'true' if quantity and price should be displayed, otherwise 'false'
isPriceLightedUp
isPriceLightedUp()

Verifies whether the price is lighted up.

Returns : boolean
  • 'true' if price should be lighted up, otherwise 'false'
quantityWithPrice
quantityWithPrice(formattedQuantity: string | null)

Retrieves formula for quantity with price.

Parameters :
Name Type Optional Description
formattedQuantity string | null No
  • formatted quantity
Returns : string
  • price formula

Properties

formula
Type : ConfiguratorPriceComponentOptions
Decorators :
@Input()

Accessors

price
getprice()

Retrieves price.

Returns : string
priceTotal
getpriceTotal()

Retrieves the total price.

Returns : string
styleClass
getstyleClass()

Retrieves the styling for the corresponding element.

Returns : string
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Configurator } from '../../core/model/configurator.model';

export interface ConfiguratorPriceComponentOptions {
  quantity?: number;
  price?: Configurator.PriceDetails;
  priceTotal?: Configurator.PriceDetails;
  isLightedUp?: boolean;
}

@Component({
  selector: 'cx-configurator-price',
  templateUrl: './configurator-price.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfiguratorPriceComponent {
  @Input() formula: ConfiguratorPriceComponentOptions;

  /**
   * Retrieves price.
   *
   * @return {string} - value price formula
   */
  get price(): string {
    if (this.formula.priceTotal) {
      return this.priceTotal;
    } else {
      return '+ ' + this.formula.price?.formattedValue;
    }
  }

  /**
   * Retrieves the total price.
   *
   * @return {string} - total price formula
   */
  get priceTotal(): string {
    return '+ ' + this.formula.priceTotal?.formattedValue;
  }

  /**
   * Verifies whether quantity with price should be displayed.
   *
   * @return {boolean} - 'true' if quantity and price should be displayed, otherwise 'false'
   */
  displayQuantityAndPrice(): boolean {
    const quantity = this.formula.quantity;
    return quantity ? this.formula.price?.value !== 0 && quantity >= 1 : false;
  }

  /**
   * Verifies whether only price should be displayed.
   *
   * @return {boolean} - 'true' if only price should be displayed, otherwise 'false'
   */
  displayPriceOnly(): boolean {
    const priceValue = this.formula.price?.value ?? 0;
    const priceTotalValue = this.formula.priceTotal?.value ?? 0;
    return (
      (priceValue !== 0 || priceTotalValue !== 0) &&
      !this.displayQuantityAndPrice()
    );
  }

  /**
   * Verifies whether the price formula should be displayed.
   *
   * @return {boolean} - 'true' if price formula should be displayed, otherwise 'false'
   */
  displayFormula(): boolean {
    const displayFormula =
      (this.formula.quantity && this.formula.quantity !== 0) ||
      (this.formula.price && this.formula.price?.value !== 0) ||
      (this.formula.priceTotal && this.formula.priceTotal?.value !== 0);
    return displayFormula ?? false;
  }

  /**
   * Retrieves formula for quantity with price.
   *
   * @param {string} formattedQuantity- formatted quantity
   * @return {string} - price formula
   */
  quantityWithPrice(formattedQuantity: string | null): string {
    return formattedQuantity + 'x(' + this.formula.price?.formattedValue + ')';
  }

  /**
   * Verifies whether the price is lighted up.
   *
   * @return {boolean} - 'true' if price should be lighted up, otherwise 'false'
   */
  isPriceLightedUp(): boolean {
    return this.formula.isLightedUp ?? false;
  }

  /**
   * Retrieves the styling for the corresponding element.
   *
   * @return {string} - corresponding style class
   */
  get styleClass(): string {
    let styleClass = 'cx-price';
    if (!this.isPriceLightedUp()) {
      styleClass += ' cx-greyed-out';
    }

    return styleClass;
  }
}
<ng-container *ngIf="displayFormula()">
  <ng-container *ngIf="displayPriceOnly()">
    <div [ngClass]="styleClass">{{ price }}</div>
  </ng-container>
  <ng-container *ngIf="displayQuantityAndPrice()">
    <div class="cx-quantity-price">
      {{ quantityWithPrice(formula?.quantity | cxNumeric) }}
    </div>
    <div class="cx-price-total">{{ priceTotal }}</div>
  </ng-container>
</ng-container>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""