File

projects/storefrontlib/shared/components/order-overview/order-overview.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-order-overview
templateUrl ./order-overview.component.html

Index

Properties
Methods
Inputs
Accessors

Constructor

constructor(translation: TranslationService)
Parameters :
Name Type Optional
translation TranslationService No

Inputs

order
Type : any

Methods

getAddressCardContent
getAddressCardContent(deliveryAddress: Address)
Parameters :
Name Type Optional
deliveryAddress Address No
Returns : Observable<Card>
getBillingAddressCardContent
getBillingAddressCardContent(billingAddress: Address)
Parameters :
Name Type Optional
billingAddress Address No
Returns : Observable<Card>
getCostCenterCardContent
getCostCenterCardContent(costCenter: CostCenter)
Parameters :
Name Type Optional
costCenter CostCenter No
Returns : Observable<Card>
getDeliveryModeCardContent
getDeliveryModeCardContent(deliveryMode: DeliveryMode)
Parameters :
Name Type Optional
deliveryMode DeliveryMode No
Returns : Observable<Card>
getMethodOfPaymentCardContent
getMethodOfPaymentCardContent(hasPaymentInfo: PaymentDetails)
Parameters :
Name Type Optional
hasPaymentInfo PaymentDetails No
Returns : Observable<Card>
getOrderCodeCardContent
getOrderCodeCardContent(orderCode: string)
Parameters :
Name Type Optional
orderCode string No
Returns : Observable<Card>
getOrderCurrentDateCardContent
getOrderCurrentDateCardContent(isoDate: string)
Parameters :
Name Type Optional
isoDate string No
Returns : Observable<Card>
getOrderStatusCardContent
getOrderStatusCardContent(status: string)
Parameters :
Name Type Optional
status string No
Returns : Observable<Card>
getPaymentInfoCardContent
getPaymentInfoCardContent(payment: PaymentDetails)
Parameters :
Name Type Optional
payment PaymentDetails No
Returns : Observable<Card>
getPurchaseOrderNumber
getPurchaseOrderNumber(poNumber: string)
Parameters :
Name Type Optional
poNumber string No
Returns : Observable<Card>
getReplenishmentActiveCardContent
getReplenishmentActiveCardContent(active: boolean)
Parameters :
Name Type Optional
active boolean No
Returns : Observable<Card>
getReplenishmentCodeCardContent
getReplenishmentCodeCardContent(orderCode: string)
Parameters :
Name Type Optional
orderCode string No
Returns : Observable<Card>
getReplenishmentFrequencyCardContent
getReplenishmentFrequencyCardContent(frequency: string)
Parameters :
Name Type Optional
frequency string No
Returns : Observable<Card>
getReplenishmentNextDateCardContent
getReplenishmentNextDateCardContent(isoDate: string)
Parameters :
Name Type Optional
isoDate string No
Returns : Observable<Card>
getReplenishmentStartOnCardContent
getReplenishmentStartOnCardContent(isoDate: string)
Parameters :
Name Type Optional
isoDate string No
Returns : Observable<Card>
Private normalizeFormattedAddress
normalizeFormattedAddress(formattedAddress: string)
Parameters :
Name Type Optional
formattedAddress string No
Returns : string

Properties

order
Type : any

Accessors

setOrder
setsetOrder(order: any)
Parameters :
Name Type Optional
order any No
Returns : void
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import {
  Address,
  CostCenter,
  DeliveryMode,
  PaymentDetails,
  TranslationService,
} from '@spartacus/core';
import { combineLatest, Observable } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { Card } from '../card/card.component';

@Component({
  selector: 'cx-order-overview',
  templateUrl: './order-overview.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class OrderOverviewComponent {
  order: any;

  @Input('order')
  set setOrder(order: any) {
    this.order = order;
  }

  constructor(protected translation: TranslationService) {}

  getReplenishmentCodeCardContent(orderCode: string): Observable<Card> {
    return this.translation.translate('orderDetails.replenishmentId').pipe(
      filter(() => Boolean(orderCode)),
      map((textTitle) => ({
        title: textTitle,
        text: [orderCode],
      }))
    );
  }

  getReplenishmentActiveCardContent(active: boolean): Observable<Card> {
    return combineLatest([
      this.translation.translate('orderDetails.status'),
      this.translation.translate('orderDetails.active'),
      this.translation.translate('orderDetails.cancelled'),
    ]).pipe(
      map(([textTitle, textActive, textCancelled]) => ({
        title: textTitle,
        text: [active ? textActive : textCancelled],
      }))
    );
  }

  getReplenishmentStartOnCardContent(isoDate: string): Observable<Card> {
    return this.translation.translate('orderDetails.startOn').pipe(
      filter(() => Boolean(isoDate)),
      map((textTitle) => {
        return {
          title: textTitle,
          text: [isoDate],
        };
      })
    );
  }

  getReplenishmentFrequencyCardContent(frequency: string): Observable<Card> {
    return this.translation.translate('orderDetails.frequency').pipe(
      filter(() => Boolean(frequency)),
      map((textTitle) => ({
        title: textTitle,
        text: [frequency],
      }))
    );
  }

  getReplenishmentNextDateCardContent(isoDate: string): Observable<Card> {
    return this.translation.translate('orderDetails.nextOrderDate').pipe(
      filter(() => Boolean(isoDate)),
      map((textTitle) => {
        return {
          title: textTitle,
          text: [isoDate],
        };
      })
    );
  }

  getOrderCodeCardContent(orderCode: string): Observable<Card> {
    return this.translation.translate('orderDetails.orderNumber').pipe(
      filter(() => Boolean(orderCode)),
      map((textTitle) => ({
        title: textTitle,
        text: [orderCode],
      }))
    );
  }

  getOrderCurrentDateCardContent(isoDate: string): Observable<Card> {
    return this.translation.translate('orderDetails.placedOn').pipe(
      filter(() => Boolean(isoDate)),
      map((textTitle) => {
        return {
          title: textTitle,
          text: [isoDate],
        };
      })
    );
  }

  getOrderStatusCardContent(status: string): Observable<Card> {
    return combineLatest([
      this.translation.translate('orderDetails.status'),
      this.translation.translate('orderDetails.statusDisplay_' + status),
    ]).pipe(
      map(([textTitle, textStatus]) => ({
        title: textTitle,
        text: [textStatus],
      }))
    );
  }

  getPurchaseOrderNumber(poNumber: string): Observable<Card> {
    return combineLatest([
      this.translation.translate('orderDetails.purchaseOrderNumber'),
      this.translation.translate('orderDetails.emptyPurchaseOrderId'),
    ]).pipe(
      map(([textTitle, noneTextTitle]) => ({
        title: textTitle,
        text: [poNumber ? poNumber : noneTextTitle],
      }))
    );
  }

  getMethodOfPaymentCardContent(
    hasPaymentInfo: PaymentDetails
  ): Observable<Card> {
    return combineLatest([
      this.translation.translate('orderDetails.methodOfPayment'),
      this.translation.translate('paymentTypes.paymentType_ACCOUNT'),
      this.translation.translate('paymentTypes.paymentType_CARD'),
    ]).pipe(
      map(([textTitle, textAccount, textCard]) => ({
        title: textTitle,
        text: [Boolean(hasPaymentInfo) ? textCard : textAccount],
      }))
    );
  }

  getCostCenterCardContent(costCenter: CostCenter): Observable<Card> {
    return this.translation.translate('orderDetails.costCenter').pipe(
      filter(() => Boolean(costCenter)),
      map((textTitle) => ({
        title: textTitle,
        textBold: costCenter?.name,
        text: ['(' + costCenter?.unit?.name + ')'],
      }))
    );
  }

  getAddressCardContent(deliveryAddress: Address): Observable<Card> {
    return this.translation.translate('addressCard.shipTo').pipe(
      filter(() => Boolean(deliveryAddress)),
      map((textTitle) => {
        const formattedAddress = this.normalizeFormattedAddress(
          deliveryAddress.formattedAddress
        );

        return {
          title: textTitle,
          textBold: `${deliveryAddress.firstName} ${deliveryAddress.lastName}`,
          text: [formattedAddress, deliveryAddress.country.name],
        };
      })
    );
  }

  getDeliveryModeCardContent(deliveryMode: DeliveryMode): Observable<Card> {
    return this.translation.translate('orderDetails.shippingMethod').pipe(
      filter(() => Boolean(deliveryMode)),
      map((textTitle) => ({
        title: textTitle,
        textBold: deliveryMode.name,
        text: [
          deliveryMode.description,
          deliveryMode.deliveryCost?.formattedValue
            ? deliveryMode.deliveryCost?.formattedValue
            : '',
        ],
      }))
    );
  }

  getPaymentInfoCardContent(payment: PaymentDetails): Observable<Card> {
    return combineLatest([
      this.translation.translate('paymentForm.payment'),
      this.translation.translate('paymentCard.expires', {
        month: Boolean(payment) ? payment.expiryMonth : '',
        year: Boolean(payment) ? payment.expiryYear : '',
      }),
    ]).pipe(
      filter(() => Boolean(payment)),
      map(([textTitle, textExpires]) => ({
        title: textTitle,
        textBold: payment.accountHolderName,
        text: [payment.cardNumber, textExpires],
      }))
    );
  }

  getBillingAddressCardContent(billingAddress: Address): Observable<Card> {
    return this.translation.translate('paymentForm.billingAddress').pipe(
      filter(() => Boolean(billingAddress)),
      map((textTitle) => ({
        title: textTitle,
        textBold: `${billingAddress.firstName} ${billingAddress.lastName}`,
        text: [billingAddress.formattedAddress, billingAddress.country.name],
      }))
    );
  }

  private normalizeFormattedAddress(formattedAddress: string): string {
    const addresses = formattedAddress
      .split(',')
      .map((address) => address.trim());

    const newFormattedAddress = addresses.filter(Boolean).join(', ');

    return newFormattedAddress;
  }
}
<div class="cx-order-summary">
  <div class="container">
    <ng-container *ngIf="order.replenishmentOrderCode; else otherOrder">
      <div class="cx-summary-card">
        <cx-card
          [content]="
            getReplenishmentCodeCardContent(order?.replenishmentOrderCode)
              | async
          "
        ></cx-card>

        <cx-card
          [content]="getReplenishmentActiveCardContent(order?.active) | async"
        ></cx-card>
      </div>

      <div class="cx-summary-card">
        <cx-card
          [content]="
            getReplenishmentStartOnCardContent(order?.firstDate | cxDate)
              | async
          "
        ></cx-card>

        <cx-card
          [content]="
            getReplenishmentFrequencyCardContent(
              order?.trigger?.displayTimeTable
            ) | async
          "
        ></cx-card>

        <cx-card
          [content]="
            getReplenishmentNextDateCardContent(
              order?.trigger?.activationTime | cxDate
            ) | async
          "
        ></cx-card>
      </div>
    </ng-container>

    <ng-template #otherOrder>
      <div class="cx-summary-card">
        <cx-card
          [content]="getOrderCodeCardContent(order?.code) | async"
        ></cx-card>

        <cx-card
          [content]="
            getOrderCurrentDateCardContent(order?.created | cxDate) | async
          "
        ></cx-card>

        <cx-card
          [content]="getOrderStatusCardContent(order.statusDisplay) | async"
        ></cx-card>
      </div>
    </ng-template>

    <ng-container
      *ngIf="order.purchaseOrderNumber || order.purchaseOrderNumber === ''"
    >
      <div class="cx-summary-card">
        <cx-card
          [content]="getPurchaseOrderNumber(order?.purchaseOrderNumber) | async"
        ></cx-card>

        <cx-card
          [content]="getMethodOfPaymentCardContent(order.paymentInfo) | async"
        ></cx-card>

        <ng-container *ngIf="order.costCenter">
          <cx-card
            [content]="getCostCenterCardContent(order?.costCenter) | async"
          ></cx-card>
        </ng-container>
      </div>
    </ng-container>

    <div class="cx-summary-card">
      <ng-container *ngIf="order.deliveryAddress">
        <cx-card
          [content]="getAddressCardContent(order?.deliveryAddress) | async"
        ></cx-card>
      </ng-container>

      <ng-container *ngIf="order.deliveryMode">
        <cx-card
          [content]="getDeliveryModeCardContent(order?.deliveryMode) | async"
        ></cx-card>
      </ng-container>
    </div>

    <ng-container *ngIf="order.paymentInfo">
      <div class="cx-summary-card">
        <cx-card
          [content]="getPaymentInfoCardContent(order?.paymentInfo) | async"
        ></cx-card>

        <cx-card
          [content]="
            getBillingAddressCardContent(order?.paymentInfo?.billingAddress)
              | async
          "
        ></cx-card>
      </div>
    </ng-container>
  </div>
</div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""