feature-libs/cart/saved-cart/components/details/saved-cart-details-overview/saved-cart-details-overview.component.ts
| selector | cx-saved-cart-details-overview |
| templateUrl | ./saved-cart-details-overview.component.html |
Properties |
|
Methods |
constructor(savedCartDetailsService: SavedCartDetailsService, translation: TranslationService, vcr: ViewContainerRef, launchDialogService: LaunchDialogService)
|
|||||||||||||||
|
Parameters :
|
| getCartDescription | ||||||
getCartDescription(cartDescription: string)
|
||||||
|
Parameters :
Returns :
Observable<Card>
|
| getCartId | ||||||
getCartId(cartId: string)
|
||||||
|
Parameters :
Returns :
Observable<Card>
|
| getCartItems | ||||||
getCartItems(totalItems: number)
|
||||||
|
Parameters :
Returns :
Observable<Card>
|
| getCartName | ||||||
getCartName(cartName: string)
|
||||||
|
Parameters :
Returns :
Observable<Card>
|
| getCartQuantity | ||||||
getCartQuantity(totalUnitCount: number)
|
||||||
|
Parameters :
Returns :
Observable<Card>
|
| getCartTotal | ||||||
getCartTotal(totalPriceWithTax: string)
|
||||||
|
Parameters :
Returns :
Observable<Card>
|
| getDateSaved | ||||||
getDateSaved(saveTime: string | null)
|
||||||
|
Parameters :
Returns :
Observable<Card>
|
| ngOnDestroy |
ngOnDestroy()
|
|
Returns :
void
|
| openDialog | ||||||
openDialog(cart: Cart)
|
||||||
|
Parameters :
Returns :
void
|
| element |
Type : ElementRef
|
Decorators :
@ViewChild('element')
|
| iconTypes |
Default value : ICON_TYPE
|
| savedCart$ |
Type : Observable<Cart | undefined>
|
Default value : this.savedCartDetailsService.getCartDetails()
|
| Private subscription |
Default value : new Subscription()
|
import {
Component,
ElementRef,
OnDestroy,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { Cart, TranslationService } from '@spartacus/core';
import {
Card,
ICON_TYPE,
LaunchDialogService,
LAUNCH_CALLER,
} from '@spartacus/storefront';
import { Observable, Subscription } from 'rxjs';
import { filter, map, take } from 'rxjs/operators';
import { SavedCartDetailsService } from '../saved-cart-details.service';
@Component({
selector: 'cx-saved-cart-details-overview',
templateUrl: './saved-cart-details-overview.component.html',
})
export class SavedCartDetailsOverviewComponent implements OnDestroy {
private subscription = new Subscription();
@ViewChild('element') element: ElementRef;
iconTypes = ICON_TYPE;
savedCart$: Observable<Cart | undefined> =
this.savedCartDetailsService.getCartDetails();
constructor(
protected savedCartDetailsService: SavedCartDetailsService,
protected translation: TranslationService,
protected vcr: ViewContainerRef,
protected launchDialogService: LaunchDialogService
) {}
getCartName(cartName: string): Observable<Card> {
return this.translation.translate('savedCartDetails.cartName').pipe(
filter(() => Boolean(cartName)),
map((textTitle) => ({
title: textTitle,
text: [cartName],
}))
);
}
getCartDescription(cartDescription: string): Observable<Card> {
return this.translation.translate('savedCartDetails.cartDescription').pipe(
filter(() => Boolean(cartDescription)),
map((textTitle) => ({
title: textTitle,
text: [cartDescription],
}))
);
}
getCartId(cartId: string): Observable<Card> {
return this.translation.translate('savedCartDetails.cartId').pipe(
filter(() => Boolean(cartId)),
map((textTitle) => ({
title: textTitle,
text: [cartId],
}))
);
}
getDateSaved(saveTime: string | null): Observable<Card> {
return this.translation.translate('savedCartDetails.dateSaved').pipe(
filter(() => Boolean(saveTime)),
map((textTitle) => {
return {
title: textTitle,
text: [saveTime ?? ''],
};
})
);
}
getCartItems(totalItems: number): Observable<Card> {
return this.translation.translate('savedCartDetails.items').pipe(
filter(() => Boolean(totalItems)),
map((textTitle) => ({
title: textTitle,
text: [totalItems.toString()],
}))
);
}
getCartQuantity(totalUnitCount: number): Observable<Card> {
return this.translation.translate('savedCartDetails.quantity').pipe(
filter(() => Boolean(totalUnitCount)),
map((textTitle) => ({
title: textTitle,
text: [totalUnitCount.toString()],
}))
);
}
getCartTotal(totalPriceWithTax: string): Observable<Card> {
return this.translation.translate('savedCartDetails.total').pipe(
filter(() => Boolean(totalPriceWithTax)),
map((textTitle) => ({
title: textTitle,
text: [totalPriceWithTax],
}))
);
}
openDialog(cart: Cart): void {
const dialog = this.launchDialogService.openDialog(
LAUNCH_CALLER.SAVED_CART,
this.element,
this.vcr,
{ cart, layoutOption: 'edit' }
);
if (dialog) {
this.subscription.add(dialog.pipe(take(1)).subscribe());
}
}
ngOnDestroy(): void {
this.subscription?.unsubscribe();
}
}
<ng-container *ngIf="savedCart$ | async as cart">
<div class="cx-cart-summary">
<div class="container">
<div class="cx-summary-card">
<div class="cx-edit-container">
<cx-card [content]="getCartName(cart?.name) | async"></cx-card>
<button class="cx-edit-cart" #element (click)="openDialog(cart)">
<cx-icon [type]="iconTypes.PENCIL"></cx-icon>
</button>
</div>
<div class="cx-card-description">
<cx-card
[content]="getCartDescription(cart?.description) | async"
[truncateText]="true"
[charactersLimit]="30"
></cx-card>
</div>
</div>
<div class="cx-summary-card">
<cx-card [content]="getCartId(cart?.code) | async"></cx-card>
</div>
<div class="cx-summary-card">
<cx-card
[content]="getDateSaved(cart?.saveTime | cxDate) | async"
></cx-card>
<cx-card [content]="getCartItems(cart?.totalItems) | async"></cx-card>
</div>
<div class="cx-summary-card">
<cx-card
[content]="getCartQuantity(cart?.totalUnitCount) | async"
></cx-card>
<cx-card
[content]="
getCartTotal(cart?.totalPriceWithTax?.formattedValue) | async
"
></cx-card>
</div>
</div>
</div>
</ng-container>