File
Implements
Metadata
| selector |
cx-save-for-later |
| templateUrl |
./save-for-later.component.html |
|
cart$
|
Type : Observable<Cart>
|
|
|
|
cartLoaded$
|
Type : Observable<boolean>
|
|
|
|
CartLocation
|
Default value : PromotionLocation
|
|
|
|
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 with directive