File

projects/storefrontlib/cms-components/myaccount/my-coupons/my-coupons.component.service.ts

Index

Properties
Methods

Constructor

constructor(routingService: RoutingService, translation: TranslationService)
Parameters :
Name Type Optional
routingService RoutingService No
translation TranslationService No

Methods

Private buildSearchParam
buildSearchParam(coupon: CustomerCoupon)
Parameters :
Name Type Optional
coupon CustomerCoupon No
Returns : string
getSortLabels
getSortLabels()
Returns : Observable<literal type>
launchSearchPage
launchSearchPage(coupon: CustomerCoupon)
Parameters :
Name Type Optional
coupon CustomerCoupon No
Returns : void

Properties

Protected Readonly CUSTOMER_COUPON_CODE
Type : string
Default value : ':customerCouponCode:'
Protected Readonly RELEVANCE
Type : string
Default value : ':relevance'
sortLabels
Type : Observable<literal type>
import { Injectable } from '@angular/core';
import {
  CustomerCoupon,
  RoutingService,
  TranslationService,
} from '@spartacus/core';
import { map } from 'rxjs/operators';
import { combineLatest, Observable } from 'rxjs';

@Injectable({
  providedIn: 'root',
})
export class MyCouponsComponentService {
  sortLabels: Observable<{
    byStartDateAsc: string;
    byStartDateDesc: string;
    byEndDateAsc: string;
    byEndDateDesc: string;
  }>;

  protected readonly RELEVANCE = ':relevance';
  protected readonly CUSTOMER_COUPON_CODE = ':customerCouponCode:';

  constructor(
    protected routingService: RoutingService,
    protected translation: TranslationService
  ) {}

  launchSearchPage(coupon: CustomerCoupon): void {
    this.routingService.go(
      {
        cxRoute: 'search',
        params: { query: this.buildSearchParam(coupon) },
      },
      {
        queryParams: {
          couponcode: coupon.couponId,
        },
      }
    );
  }

  private buildSearchParam(coupon: CustomerCoupon): string {
    return coupon.allProductsApplicable
      ? this.RELEVANCE
      : this.RELEVANCE + this.CUSTOMER_COUPON_CODE + coupon.couponId;
  }

  getSortLabels(): Observable<{
    byStartDateAsc: string;
    byStartDateDesc: string;
    byEndDateAsc: string;
    byEndDateDesc: string;
  }> {
    return combineLatest([
      this.translation.translate('myCoupons.startDateAsc'),
      this.translation.translate('myCoupons.startDateDesc'),
      this.translation.translate('myCoupons.endDateAsc'),
      this.translation.translate('myCoupons.endDateDesc'),
    ]).pipe(
      map(
        ([
          textByStartDateAsc,
          textByStartDateDesc,
          textByEndDateAsc,
          textByEndDateDesc,
        ]) => {
          return {
            byStartDateAsc: textByStartDateAsc,
            byStartDateDesc: textByStartDateDesc,
            byEndDateAsc: textByEndDateAsc,
            byEndDateDesc: textByEndDateDesc,
          };
        }
      )
    );
  }
}

result-matching ""

    No results matching ""