File

feature-libs/product-configurator/common/components/configure-product/configure-product.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-configure-product
templateUrl ./configure-product.component.html

Index

Properties

Constructor

constructor(productListItemContext: ProductListItemContext, currentProductService: CurrentProductService)
Parameters :
Name Type Optional
productListItemContext ProductListItemContext No
currentProductService CurrentProductService No

Properties

nonConfigurable
Type : Product
Default value : { configurable: false }
ownerTypeProduct
Type : CommonConfigurator.OwnerType
Default value : CommonConfigurator.OwnerType.PRODUCT
product$
Type : Observable<Product>
Default value : (this.productListItemContext ? this.productListItemContext.product$ : this.currentProductService ? this.currentProductService.getProduct( ConfiguratorProductScope.CONFIGURATOR ) : of(null) ).pipe( //needed because also currentProductService might return null map((product) => (product ? product : this.nonConfigurable)) )
import { ChangeDetectionStrategy, Component, Optional } from '@angular/core';
import { Product } from '@spartacus/core';
import {
  CurrentProductService,
  ProductListItemContext,
} from '@spartacus/storefront';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { CommonConfigurator } from '../../core/model/common-configurator.model';
import { ConfiguratorProductScope } from '../../core/model/configurator-product-scope';

@Component({
  selector: 'cx-configure-product',
  templateUrl: './configure-product.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfigureProductComponent {
  nonConfigurable: Product = { configurable: false };
  product$: Observable<Product> = (this.productListItemContext
    ? this.productListItemContext.product$
    : this.currentProductService
    ? this.currentProductService.getProduct(
        ConfiguratorProductScope.CONFIGURATOR
      )
    : of(null)
  ).pipe(
    //needed because also currentProductService might return null
    map((product) => (product ? product : this.nonConfigurable))
  );

  ownerTypeProduct: CommonConfigurator.OwnerType =
    CommonConfigurator.OwnerType.PRODUCT;

  constructor(
    @Optional() protected productListItemContext: ProductListItemContext, // when on PLP
    @Optional() protected currentProductService: CurrentProductService // when on PDP
  ) {}
}
<ng-container *ngIf="product$ | async as product">
  <ng-container *ngIf="product.configurable">
    <a
      [routerLink]="
        {
          cxRoute: 'configure' + product.configuratorType,
          params: {
            ownerType: ownerTypeProduct,
            entityKey: product.code
          }
        } | cxUrl
      "
      class="btn btn-primary btn-block"
      cxAutoFocus
      >{{ 'configurator.header.toconfig' | cxTranslate }}</a
    >
  </ng-container>
</ng-container>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""