File

projects/congarevenuecloud/ecommerce/src/lib/modules/catalog/services/product.service.ts

Description

Products are the goods for buy/sell with its detailed information. The service provides methods for interacting with the products.

Usage

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

constructor(private productService: ProductService) {}

// or

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

Extends

AObjectService

Index

Properties
Methods

Methods

fetch
fetch(id: string, memoizeOptions: MemoizeOptions, relatedRecords: string, additionalQueryParams: QueryParams)
Decorators :
@MemoizeWithHash()

This method can be used to get the fetch the product details for a given product identifier. It will return all the configurations of a bundle including option and attribute groups. For bundle products it will return upto 6 level option group configurations.

Example:

Example :
import { Product, ProductService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
product: Product;
product$: Observable<Product>;
constructor(private productService: ProductService){}
ngOnInit(){
this.productService.fetch(id: string).subscribe(product => {...});
// or
this.product$ = this.productService.fetch(id: string);
}
}
Parameters :
Name Type Optional Default value Description
id string No

represents the product identifier.

memoizeOptions MemoizeOptions No null

an optional parameter to specify memoization options using MemoizeOptions interface. Defaults to null.

relatedRecords string No 'categories, prices, attributes, options'

related records(summary groups, prices etc.) to be fetched for the cart(s). Takes in related fields to product configuration as comma separated string.

additionalQueryParams QueryParams No { depth: 6 }

Additional query parameters for the fetch operation. By default, it includes relatedRecords with a default value of 'categories, prices, attributes, options' and a depth of 6.

Returns : Observable<AObject>

Observable returns an observable of product record.

getFieldPickList
getFieldPickList(fieldName: string)

This method returns the picklist values for a given field from product object.

Example:

Example :
import { Product, ProductService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
product: Array<string>;
product$: Observable<Array<string>>;
constructor(private productService: ProductService){}
ngOnInit(){
this.productService.getFieldPickList(fieldName).subscribe(product => {...});
// or
this.product$ = this.productService.getFieldPickList(fieldName);
}
}
Parameters :
Name Type Optional Default value Description
fieldName string No null

Product field name to fetch picklist values for.

Returns : Observable<Array<string>>

observable containing list of string picklist values.

getProductAggregate
getProductAggregate(aggregateFields?: Array<AggregateFields>, queryFields: Array, groupByFields: Array, filterList: Array<FieldFilter>)
Parameters :
Name Type Optional Default value
aggregateFields Array<AggregateFields> Yes
queryFields Array<string> No []
groupByFields Array<string> No []
filterList Array<FieldFilter> No []
getProducts
getProducts(categories: Array, pageSize: number, pageNumber: number, orderBy: string, orderDirection: "ASC" | "DESC", searchString: null, fetchProductFeatures: boolean, fetchTranslations: boolean, filters: Array<FieldFilter>, facetFilters?: FacetFilterPayload, fetchAssets: boolean, memoizeOptions: MemoizeOptions)
Decorators :
@MemoizeWithHash()

This method can be used to get the fetch the list of ProductResults including total product count, for a given price list and category.

Example:

Example :
import { Product, ProductService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
products: Array<Product>;
products$: Observable<Array<Product>>;
constructor(private productService: ProductService){}
ngOnInit(){
this.productService.getProducts(categories: Array<string>,
pageSize: number,
pageNumber: number,
orderBy: string,
orderDirection: 'ASC' | 'DESC',
searchString: string,
adtlConditions: Array<ACondition>
).subscribe(products => {...});
// or
this.products$ = this.productService.getProducts(categories: Array<string>,
pageSize: number,
pageNumber: number,
orderBy: string,
orderDirection: 'ASC' | 'DESC',
searchString: string,
adtlConditions: Array<ACondition>
);
}
}
Parameters :
Name Type Optional Default value Description
categories Array<string> No

List of categories the products belong to.

pageSize number No 10

number representing the number of product records to be fetched.

pageNumber number No 1

number representing the pagination.

orderBy string No null

string representing the sort field on result set.

orderDirection "ASC" | "DESC" No null

to sort the result sets. Default value is Ascending.

searchString null No null

to search products matching the string.

fetchProductFeatures boolean No true

boolean to fetch product feature values. Defaulted to true.(Work in progress)

fetchTranslations boolean No true

boolean to fetch product translations. Default value is true.(Work in progress)

filters Array<FieldFilter> No null
facetFilters FacetFilterPayload Yes

list of facet filters to filter the product results.

fetchAssets boolean No true

boolean to fetch asset line items for products. Defaulted to true.

memoizeOptions MemoizeOptions No null

an optional parameter to specify memoization options using MemoizeOptions interface. Defaults to null.

Observable<Array> returns an observable list of ProductResult.

getProductsByCode
getProductsByCode(productCodeList: Array)

This method can be used to fetch the list of products by product code.

Example:

Example :
import { Product, ProductService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
products: Array<Product>;
products$: Observable<Array<Product>>;
constructor(private productService: ProductService){}
ngOnInit(){
this.productService.getProductsByCode(productCodeList: Array<string>).subscribe(products => {...});
// or
this.products$ = this.productService.getProductsByCode(productCodeList: Array<string>);
}
}
Parameters :
Name Type Optional Description
productCodeList Array<string> No

list of string values representing product codes.

observable list of product records macthing the product codes.

getProductsById
getProductsById(productIds: Array)

This method can be used to fetch the list of products by product Ids.

Example:

Example :
import { Product, ProductService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
products: Array<Product>;
products$: Observable<Array<Product>>;
constructor(private productService: ProductService){}
ngOnInit(){
this.productService.getProductsById(productIds: Array<string>).subscribe(products => {...});
// or
this.products$ = this.productService.getProductsById(productIds: Array<string>);
}
}
Parameters :
Name Type Optional Description
productIds Array<string> No

List of string product identifiers to fetch the product records.

returns an observable list of product records matching the product identifiers.

getProductsWithFeatureValues
getProductsWithFeatureValues(productList: Array<Product> | Array<string>, memoizeOptions: MemoizeOptions)
Decorators :
@MemoizeWithHash()

This method is responsible for fetching the product details with feature values for a given set of products.

Example:

Example :
import { Product, ProductService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
product: Product;
product$: Observable<Product>;
constructor(private productService: ProductService){}
ngOnInit(){
this.productService.getProductsWithFeatureValues(productList: Array<Product> | Array<string>).subscribe(products => {...});
// or
this.products$ = this.productService.getProductsWithFeatureValues(productList: Array<Product> | Array<string>);
}
}
Parameters :
Name Type Optional Default value Description
productList Array<Product> | Array<string> No

list of product objects or string identifiers representing products ids.

memoizeOptions MemoizeOptions No null

an optional parameter to specify memoization options using MemoizeOptions interface. Defaults to null.

Observable<Array> returns an observable list of product records with product features.

getState
getState()

This method returns the previous state of the catalog page containing sortfield and page number.

Example:

Example :
import { PreviousState, ProductService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
state: PreviousState;
constructor(private productService: ProductService){}
ngOnInit(){
this.state = this.productService.getState();
}
}
Returns : PreviousState

PreviousState objcet containing the sort order and page number values

Static getValue
getValue(key)

The Static method fetches the values from the local storage.

Example:

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

export class MyComponent implements OnInit{
value: string;

getValue(key){
this.value = ProductService.getValue(key);
}
}
Parameters :
Name Optional
key No
Returns : string
publish
publish(pagestates: PreviousState)

This method records the prevoius state of the catalog page and updates the state.

Example:

Example :
import { PreviousState, ProductService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private productService: ProductService){}
updateState(pagestates: PreviousState){
this.productService.publish(pagestates);
}
}
Parameters :
Name Type Optional
pagestates PreviousState No
Returns : void
searchProducts
searchProducts(searchString: string, limit: number, fetchTranslations: boolean, memoizeOptions: MemoizeOptions)
Decorators :
@MemoizeWithHash()

This method is used to search products by search string ###Example :

Example :
import { ProductService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
products: Array<Product>;
products$: Observable<Array<Product>>;
constructor(private productService: ProductService){}
ngOnInit(){
this.productService.searchProducts(searchString: string).subscribe(products => {...});
// or
this.products$ = this.productService.searchProducts(searchString: string);
}
}
Parameters :
Name Type Optional Default value Description
searchString string No

string to search the products with. Minimum characters in the search string must be 3.

limit number No 5

a number representing the number of product records expected in the result set.

fetchTranslations boolean No true

boolean to fetch translations for the records searched. Default value is true.(Work in progress))

memoizeOptions MemoizeOptions No null

an optional parameter to specify memoization options using MemoizeOptions interface. Defaults to null.

returns an observable list of product records matching the search string.

Static setValue
setValue(key: string, pageValue: string)

The Static method updates the values such as page size, view etc in local storage.

Example:

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

export class MyComponent implements OnInit{
cartId: string;

setValue(key: string, pageValue: string){
ProductService.setValue(key, pageValue);
}
}
Parameters :
Name Type Optional
key string No
pageValue string No
Returns : void

Properties

Protected accountService
Default value : this.injector.get(AccountService)
Protected assetService
Type : AssetService
Default value : this.injector.get(AssetService)
Protected categoryService
Type : CategoryService
Default value : this.injector.get(CategoryService)
eventback
Type : BehaviorSubject<boolean>
Default value : new BehaviorSubject(false)
isDetailsPage
Type : BehaviorSubject<boolean>
Default value : new BehaviorSubject<boolean>(false)
Protected pliService
Type : PriceListItemService
Default value : this.injector.get(PriceListItemService)
Protected plService
Type : PriceListService
Default value : this.injector.get(PriceListService)
Protected productCategoryService
Default value : this.injector.get(ProductCategoryService, 'productCategoryService')
Protected queryParamsHandlerService
Default value : this.injector.get(QueryParamsHandlerService)
state
Type : BehaviorSubject<PreviousState>
Default value : new BehaviorSubject<PreviousState>(null)
Protected translatorService
Type : TranslatorLoaderService
Default value : this.injector.get(TranslatorLoaderService)
type
Default value : Product
Protected userService
Type : UserService
Default value : this.injector.get(UserService)

results matching ""

    No results matching ""