File

projects/congarevenuecloud/ecommerce/src/lib/modules/promotion/services/promotion.service.ts

Description

Promotion Service defines a way to add/remove promotions to/from the cart.

Usage

Example :
import { PromotionService } from '@congarevenuecloud/ecommerce';

constructor(private promotionService: PromotionService) {}

// or

export class MyService extends AObjectService {
private promotionService: PromotionService = this.injector.get(PromotionService);
}

Extends

AObjectService

Index

Properties
Methods

Methods

applyPromotions
applyPromotions(promocodes: string | Array, lineItems: Array)

Method applies promotion to the current cart based on the promo code passed.

Example:

Example :
import { PromotionService } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
constructor(private promotionService: PromotionService){}

applyPromotions(promocodes: string | string[], lineItems: Array<string>){
this.promotionService.applyPromotions(promocodes, lineItems).subscribe({...});
}
}
Parameters :
Name Type Optional Description
promocodes string | Array<string> No

a string or array of string value representing the promotion code to be applied to the cart.

lineItems Array<string> No

a string or array of string value representing the lineitem ids of the cart.

Returns : Observable<boolean | HttpErrorResponse>

a observable<boolean | HttpErrorResponse> when the operation has completed.

getAppliedPromotionForCart
getAppliedPromotionForCart(incentiveCode: string, cart: Cart)

Method returns an observable containing an array of adjustment line items for the current cart.

Example:

Example :
import { PromotionService } from '@congarevenuecloud/ecommerce';
import { AdjustmentItem } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
adjustmentLineItems$: Observable<Array<AdjustmentLineItem>>;
adjustmentLineItems; Array<AdjustmentLineItem>;
constructor(private promotionService: PromotionService){}

getAppliedPromotionForCart(){
this.promotionService.getAppliedPromotionForCart().subscribe(res => this.adjustmentLineItems = res);
or
this.adjustmentLineItems$ = this.promotionService.getAppliedPromotionForCart();
}
}
Parameters :
Name Type Optional Description
incentiveCode string No

is the valid incentive code value.

cart Cart No

is the active cart instance.

an observable containing an array of adjustment line items for the current cart.

getAppliedPromotionForLineItem
getAppliedPromotionForLineItem(lineNumber: number)

Method returns an observable containing an array of adjustment line items for the lineItem based on the LineNumber.

Example:

Example :
import { PromotionService } from '@congarevenuecloud/ecommerce';
import { AdjustmentItem } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
adjustmentLineItems$: Observable<Array<AdjustmentLineItem>>;
adjustmentLineItems; Array<AdjustmentLineItem>;
constructor(private promotionService: PromotionService){}

getAppliedPromotionForLineItem(lineNumber: number){
this.promotionService.getAppliedPromotionForLineItem(lineNumber).subscribe(res => this.adjustmentLineItems = res);
or
this.adjustmentLineItems$ = this.promotionService.getAppliedPromotionForLineItem(lineNumber);
}
}
Parameters :
Name Type Optional Description
lineNumber number No

is of type number, which accepts the LineNumber of the lineItem.

Example:

Example :
import { PromotionService } from '@congarevenuecloud/ecommerce';
import { AdjustmentItem } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
adjustmentLineItems$: Observable<Array<AdjustmentLineItem>>;
adjustmentLineItems; Array<AdjustmentLineItem>;
constructor(private promotionService: PromotionService){}

getAppliedPromotionForLineItem(lineNumber: number){
this.promotionService.getAppliedPromotionForLineItem(lineNumber).subscribe(res => this.adjustmentLineItems = res);
or
this.adjustmentLineItems$ = this.promotionService.getAppliedPromotionForLineItem(lineNumber);
}
}

an observable containing an array of adjustment line items for the lineItem based on the lineNumber.

removeAppliedPromotion
removeAppliedPromotion(promocodes: string | string[], lineItems: Array)

Method removes the promotion from the current cart if it is already applied.

Example:

Example :
import { PromotionService } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
constructor(private promotionService: PromotionService){}

removeAppliedPromotion(promocodes: string | string[], lineItems: Array<string>){
this.promotionService.removeAppliedPromotion(promocodes, lineItems).subscribe({...});
}
}
Parameters :
Name Type Optional Description
promocodes string | string[] No

a string or array of string value representing the promotion code to be removed from the the cart.

lineItems Array<string> No

a string or array of string value representing the lineitem ids of the cart.

Returns : Observable<boolean | HttpErrorResponse>

a observable<boolean | HttpErrorResponse> when the operation has completed.

Properties

apiService
Type : ApiService
Default value : this.injector.get(ApiService)
cartService
Type : CartService
Default value : this.injector.get(CartService)
type
Default value : AdjustmentItem

results matching ""

    No results matching ""