File

projects/storefrontlib/cms-components/cart/validation/cart-warnings/cart-validation-warnings.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-cart-validation-warnings
templateUrl ./cart-validation-warnings.component.html

Index

Properties
Methods

Constructor

constructor(cartValidationStateService: CartValidationStateService)
Parameters :
Name Type Optional
cartValidationStateService CartValidationStateService No

Methods

removeMessage
removeMessage(cartModification: CartModification)
Parameters :
Name Type Optional
cartModification CartModification No
Returns : void

Properties

cartModifications$
Default value : this.cartValidationStateService.cartValidationResult$.pipe( map((modificationList) => { const result = modificationList.filter( (modification) => modification.statusCode === CartValidationStatusCode.NO_STOCK ); result.forEach((modification) => { if (modification.entry?.product?.code) { this.visibleWarnings[modification.entry.product.code] = true; } }); return result; }) )
iconTypes
Default value : ICON_TYPE
visibleWarnings
Type : Record<string | boolean>
Default value : {}
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { map } from 'rxjs/operators';
import { CartModification, CartValidationStatusCode } from '@spartacus/core';
import { CartValidationStateService } from '../cart-validation-state.service';
import { ICON_TYPE } from '../../../misc/icon/index';

@Component({
  selector: 'cx-cart-validation-warnings',
  templateUrl: './cart-validation-warnings.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CartValidationWarningsComponent {
  iconTypes = ICON_TYPE;
  visibleWarnings: Record<string, boolean> = {};

  cartModifications$ =
    this.cartValidationStateService.cartValidationResult$.pipe(
      map((modificationList) => {
        const result = modificationList.filter(
          (modification) =>
            modification.statusCode === CartValidationStatusCode.NO_STOCK
        );

        result.forEach((modification) => {
          if (modification.entry?.product?.code) {
            this.visibleWarnings[modification.entry.product.code] = true;
          }
        });
        return result;
      })
    );

  constructor(
    protected cartValidationStateService: CartValidationStateService
  ) {}

  removeMessage(cartModification: CartModification) {
    if (cartModification.entry?.product?.code) {
      this.visibleWarnings[cartModification.entry.product.code] = false;
    }
  }
}
<ng-container *ngFor="let cartModification of cartModifications$ | async">
  <div
    class="alert alert-danger"
    *ngIf="visibleWarnings[cartModification.entry.product.code]"
  >
    <span class="alert-icon">
      <cx-icon [type]="iconTypes.ERROR"></cx-icon>
    </span>
    <span>
      <a
        [routerLink]="
          { cxRoute: 'product', params: cartModification.entry.product } | cxUrl
        "
      >
        {{ cartModification.entry.product.name }}
      </a>
      {{ 'validation.productOutOfStock' | cxTranslate }}
    </span>

    <button
      class="close"
      type="button"
      (click)="removeMessage(cartModification)"
    >
      <cx-icon [type]="iconTypes.CLOSE"></cx-icon>
    </button>
  </div>
</ng-container>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""