File

projects/storefrontlib/cms-components/cart/save-for-later/save-for-later.component.ts

Implements

OnInit

Metadata

selector cx-save-for-later
templateUrl ./save-for-later.component.html

Index

Properties
Methods

Constructor

constructor(cmsService: CmsService, cartService: ActiveCartService, selectiveCartService: SelectiveCartService)
Parameters :
Name Type Optional
cmsService CmsService No
cartService ActiveCartService No
selectiveCartService SelectiveCartService No

Methods

moveToCart
moveToCart(item: OrderEntry)
Parameters :
Name Type Optional
item OrderEntry No
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

cart$
Type : Observable<Cart>
cartLoaded$
Type : Observable<boolean>
CartLocation
Default value : PromotionLocation
data$
Type : Observable<CmsParagraphComponent>
entries$
Type : Observable<OrderEntry[]>
isCartEmpty$
Type : Observable<boolean>
saveForLater$
Type : Observable<Cart>
import { Component, OnInit } from '@angular/core';
import {
  ActiveCartService,
  Cart,
  CmsParagraphComponent,
  CmsService,
  OrderEntry,
  PromotionLocation,
  SelectiveCartService,
} from '@spartacus/core';
import { combineLatest, Observable } from 'rxjs';
import { filter, map } from 'rxjs/operators';

@Component({
  selector: 'cx-save-for-later',
  templateUrl: './save-for-later.component.html',
})
export class SaveForLaterComponent implements OnInit {
  saveForLater$: Observable<Cart>;
  cart$: Observable<Cart>;
  entries$: Observable<OrderEntry[]>;
  cartLoaded$: Observable<boolean>;
  data$: Observable<CmsParagraphComponent>;
  isCartEmpty$: Observable<boolean>;
  CartLocation = PromotionLocation;

  constructor(
    protected cmsService: CmsService,
    protected cartService: ActiveCartService,
    protected selectiveCartService: SelectiveCartService
  ) {}

  ngOnInit() {
    this.isCartEmpty$ = this.cartService
      .getActive()
      .pipe(map((cart) => !(cart && cart.totalItems && cart.totalItems > 0)));
    this.saveForLater$ = this.selectiveCartService.getCart();
    this.entries$ = this.selectiveCartService
      .getEntries()
      .pipe(filter((entries) => entries.length > 0));
    this.cartLoaded$ = combineLatest([
      this.cartService.isStable(),
      this.selectiveCartService.isStable(),
    ]).pipe(map(([cartLoaded, sflLoaded]) => cartLoaded && sflLoaded));
    this.data$ = this.cmsService.getComponentData(
      'EmptyCartParagraphComponent'
    );
  }

  moveToCart(item: OrderEntry) {
    this.selectiveCartService.removeEntry(item);
    this.cartService.addEntry(item.product.code, item.quantity);
  }
}
<ng-container *ngIf="isCartEmpty$ | async">
  <p
    *ngIf="data$ | async as data"
    [innerHTML]="data.content"
    class="cx-empty-cart-info"
  ></p>
</ng-container>

<ng-container *ngIf="saveForLater$ | async as saveForLater">
  <ng-container *ngIf="entries$ | async as entries">
    <div *ngIf="saveForLater.totalItems > 0" class="cart-details-wrapper">
      <div class="cx-total">
        {{
          'saveForLaterItems.itemTotal'
            | cxTranslate: { count: saveForLater.totalItems }
        }}
      </div>
      <cx-cart-item-list
        [items]="entries"
        [readonly]="false"
        [cartIsLoading]="!(cartLoaded$ | async)"
        [promotionLocation]="CartLocation.SaveForLater"
        [options]="{
          isSaveForLater: true,
          optionalBtn: moveToCartBtn
        }"
      ></cx-cart-item-list>
    </div>
  </ng-container>
</ng-container>

<ng-template let-ctx #moveToCartBtn>
  <div class="col-md-3 col-lg-3 col-xl-3 cx-sfl-btn">
    <button
      class="link cx-action-link"
      [disabled]="ctx.loading"
      (click)="moveToCart(ctx.item)"
      type="button"
    >
      {{ 'saveForLaterItems.moveToCart' | cxTranslate }}
    </button>
  </div>
</ng-template>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""