File

projects/congarevenuecloud/ecommerce/src/lib/modules/cart/services/cart-item.service.ts

Description

Cart Item service returns the selling term and the end date of a recurring product.

Usage

Example :
import { CartItemService, AObjectService} from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{
constructor( private cartItemService: CartItemService)
}
// or
export class MyService extends AObjectService {
private cartItemService: CartItemService = this.injector.get(CartItemService);
}

Extends

LineItemService

Index

Properties
Methods

Methods

getCartItemsForProduct
getCartItemsForProduct(product: Product, quantity: number, cart?: Cart, cartItems?: Array, productOptionComponent?: ProductOptionComponent, parentBundleNumber?: number, lineNumber?: number, lineStatus?: LineStatus)

Method gets the cart items for a given product. A bundle product with option groups populated must be passed in to retrieve related option cart items.

Example:

Example :
import { CartItemService, CartItem } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
cartItemList: Array<CartItem>;
cartItemList$: Observable<Array<CartItem>>;

constructor(private cartItemService: CartItemService){}

getCartItems(product: Product){
this.cartItemService.getCartItemsForProduct(product).subscribe(a => this.cartItemList = a);
// or
this.cartItemList$ = this.cartItemService.getCartItemsForProduct(product);
}
}
Parameters :
Name Type Optional Default value Description
product Product No

the product or bundle product record to generate the cart items for

quantity number No 1

the quantity to use for the cart item(s)

cart Cart Yes

the related cart that the cart items will be added to. Must be passed in or the line number that is used will start at 1

cartItems Array<CartItem> Yes

optional list of related cart items to determine the starting primary line number

productOptionComponent ProductOptionComponent Yes

The related ProductOptionComponent record for generating option line items

parentBundleNumber number Yes

the default parent bundle number to use

lineNumber number Yes

the default line number to use.

lineStatus LineStatus Yes

the default line status to use.

Returns : Observable<Array<CartItem>>

an Obseravable containing the array of CartItem associated with Product

getEndDate
getEndDate(purchaseDate: Date, term: number, frequency: "Hourly" | "Daily" | "Weekly" | "Monthly" | "Quarterly" | "Half Yearly" | "Yearly" | "--None--")

This method returns the end date of a recurring product based on its start date and the selling frequency.

Example:

Example :
import { CartItemService, CartItem } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
endDate: Date;

constructor(private cartItemService: CartItemService){}

getEndDateForProduct(startDate: Date, term: number, frequency: 'Hourly' | 'Daily' | 'Weekly' | 'Monthly' | 'Quarterly' | 'Half Yearly' | 'Yearly' | '--None--' ){
this.endDate = this.cartItemService.getEndDateForProduct(startDate, term, frequency);
}
}
Parameters :
Name Type Optional Description
purchaseDate Date No

the day of purchase of the product.

term number No

number representing the selling term of the product.

frequency "Hourly" | "Daily" | "Weekly" | "Monthly" | "Quarterly" | "Half Yearly" | "Yearly" | "--None--" No

the selling frequency for the product. Selling frequency may take values like hourly, daily, weekly, monthly, quarterly, half yearly and yearly.

Returns : Date

a date value representing the day of end of service of the product.

getTerm
getTerm(startDate: moment.Moment, endDate: moment.Moment, frequency: "Hourly" | "Daily" | "Weekly" | "Monthly" | "Quarterly" | "Half Yearly" | "Yearly" | "--None--")

This method is used to calculate selling term of the recurring product based on its start date, end date and the selling frequency.

Example:

Example :
import { CartItemService, CartItem } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
term: number;

constructor(private cartItemService: CartItemService){}

getTermForProduct(startDate: Date, endDate: Date, frequency: 'Hourly' | 'Daily' | 'Weekly' | 'Monthly' | 'Quarterly' | 'Half Yearly' | 'Yearly' | '--None--' ){
this.term = this.cartItemService.getTermForProduct(startDate, endDate, frequency);
}
}
Parameters :
Name Type Optional Description
startDate moment.Moment No

the day of purchase of the product.

endDate moment.Moment No

the day of end of service for the product.

frequency "Hourly" | "Daily" | "Weekly" | "Monthly" | "Quarterly" | "Half Yearly" | "Yearly" | "--None--" No

the selling frequency of the product.

Returns : number

number representing the selling term of the recurring product.

Static groupItems
groupItems(items: Array)

The method takes a line item and returns the categorized line item.

Example:

Example :
import { LineItemService, ItemGroup, CartItem, QuoteLineItem, OrderLineItem } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
lineItemList: ItemGroup;
lineItemList$: Array<ItemGroup>;

groupItems(items: Array<CartItem | QuoteLineItem | OrderLineItem>){
LineItemService.groupItems(items).subscribe(a => this.lineItemList = a);
// or
this.lineItemList$ = LineItemService.groupItems(items);
}
}
Parameters :
Name Type Optional Description
items Array<CartItem | QuoteLineItem | OrderLineItem> No

Array of type Cart item, Quote line item or Order line item

Returns : Array<ItemGroup>

Properties

Protected accountService
Type : AccountService
Default value : this.injector.get(AccountService)
Protected categoryService
Type : CategoryService
Default value : this.injector.get(CategoryService)
frequencyMap
Type : object
Default value : { 'Hourly': 'hours', 'Monthly': 'months', 'Daily': 'days', 'Weekly': 'weeks', 'Quarterly': 'years', 'Half Yearly': 'years', 'Yearly': 'years', '--None--': '--None--' }
metadataService
Type : MetadataService
Default value : this.injector.get(MetadataService)
Protected priceListService
Type : PriceListService
Default value : this.injector.get(PriceListService)
Protected productAttributeService
Type : ProductAttributeService
Default value : this.injector.get(ProductAttributeService)
Protected storefrontService
Type : StorefrontService
Default value : this.injector.get(StorefrontService)
type
Default value : CartItem
apiService
Type : ApiService
Default value : this.injector.get(ApiService)

results matching ""

    No results matching ""