File

feature-libs/product-configurator/rulebased/components/overview-bundle-attribute/configurator-overview-bundle-attribute.component.ts

Implements

OnInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-configurator-cpq-overview-attribute
templateUrl ./configurator-overview-bundle-attribute.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(productService: ProductService)
Parameters :
Name Type Optional
productService ProductService No

Inputs

attributeOverview
Type : Configurator.AttributeOverview

Methods

displayPrice
displayPrice()

Verifies whether the item price should be displayed.

Returns : boolean
  • 'true' if the item price price should be displayed, otherwise 'false'
displayQuantity
displayQuantity()

Verifies whether the quantity should be displayed.

Returns : boolean
  • 'true' if the quantity should be displayed, otherwise 'false'
extractPriceFormulaParameters
extractPriceFormulaParameters()

Extract corresponding price formula parameters

  • New price formula
getProductPrimaryImage
getProductPrimaryImage(product: Product)

Returns primary image from product object

Parameters :
Name Type Optional
product Product No
  • primary image. View can handle an undefined image
ngOnInit
ngOnInit()
Returns : void

Properties

attributeOverview
Type : Configurator.AttributeOverview
Decorators :
@Input()
product$
Type : Observable<Product>
import {
  ChangeDetectionStrategy,
  Component,
  Input,
  OnInit,
} from '@angular/core';
import {
  ImageGroup,
  Product,
  ProductScope,
  ProductService,
} from '@spartacus/core';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { Configurator } from '../../core/model/configurator.model';
import { ConfiguratorPriceComponentOptions } from '../price/configurator-price.component';

@Component({
  selector: 'cx-configurator-cpq-overview-attribute',
  templateUrl: './configurator-overview-bundle-attribute.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfiguratorOverviewBundleAttributeComponent implements OnInit {
  product$: Observable<Product>;

  @Input() attributeOverview: Configurator.AttributeOverview;

  constructor(protected productService: ProductService) {}

  ngOnInit() {
    const noCommerceProduct: Product = { images: {} };
    if (this.attributeOverview.productCode) {
      this.product$ = this.productService
        .get(this.attributeOverview.productCode, ProductScope.LIST)
        .pipe(
          map((respProduct) => {
            return respProduct ? respProduct : noCommerceProduct;
          })
        );
    } else {
      this.product$ = of(noCommerceProduct);
    }
  }

  /**
   * Returns primary image from product object
   *
   * @param {Product} product
   * @returns {(ImageGroup | ImageGroup[] | undefined)} - primary image. View can handle an undefined image
   */
  getProductPrimaryImage(
    product: Product
  ): ImageGroup | ImageGroup[] | undefined {
    return product?.images?.PRIMARY;
  }

  /**
   * Extract corresponding price formula parameters
   *
   * @return {ConfiguratorPriceComponentOptions} - New price formula
   */
  extractPriceFormulaParameters(): ConfiguratorPriceComponentOptions {
    return {
      quantity: this.attributeOverview.quantity,
      price: this.attributeOverview.valuePrice,
      priceTotal: this.attributeOverview.valuePriceTotal,
      isLightedUp: true,
    };
  }

  /**
   * Verifies whether the quantity should be displayed.
   *
   * @return {boolean} - 'true' if the quantity should be displayed, otherwise 'false'
   */
  displayQuantity(): boolean {
    const quantity = this.attributeOverview.quantity;
    return quantity !== undefined && quantity > 0;
  }

  /**
   * Verifies whether the item price should be displayed.
   *
   * @return {boolean} - 'true' if the item price price should be displayed, otherwise 'false'
   */
  displayPrice(): boolean {
    return (
      this.attributeOverview.valuePrice?.value !== undefined &&
      this.attributeOverview.valuePrice?.value > 0
    );
  }
}
<ng-container *ngIf="product$ | async as product">
  <div class="cx-value-container">
    <div class="cx-thumbnail">
      <cx-media
        [container]="getProductPrimaryImage(product)"
        format="product"
      ></cx-media>
    </div>
    <div class="cx-value-info">
      <div>
        {{ attributeOverview.value }}
      </div>
      <span class="cx-code" *ngIf="attributeOverview?.productCode">
        {{ 'configurator.attribute.id' | cxTranslate }}:
        {{ attributeOverview.productCode }}</span
      >
      <div *ngIf="displayQuantity()" class="cx-quantity">
        <span class="cx-identifier">{{
          'configurator.attribute.quantity' | cxTranslate
        }}</span>
        <span class="cx-item">{{
          attributeOverview.quantity | cxNumeric
        }}</span>
      </div>
      <div *ngIf="displayPrice()" class="cx-price">
        <span class="cx-identifier">{{
          'configurator.overviewForm.itemPrice' | cxTranslate
        }}</span>
        <span class="cx-item">{{
          attributeOverview.valuePrice?.formattedValue
        }}</span>
      </div>
    </div>
  </div>

  <div class="cx-attribute-price-container">
    <span class="cx-attribute-label">{{ attributeOverview.attribute }}</span>
    <cx-configurator-price
      [formula]="extractPriceFormulaParameters()"
    ></cx-configurator-price>
  </div>
</ng-container>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""