File

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

Description

The service provides methods for interacting with the products and returns option components configured for the bundle product.

Usage

Example :
import { ProductOptionService, AObjectService } from '@congarevenuecloud/ecommerce';
constructor(private productOptionService: ProductOptionService) {}
// or
export class MyService extends AObjectService {
private productOptionService: ProductOptionService = this.injector.get(ProductOptionService);
}

Extends

ProductService

Index

Properties
Methods

Methods

getProductOptions
getProductOptions(product: Product)
Decorators :
@MemoizeAll()

This method returns a list of product options components configured for the bundle product. Uses '@MemoizeAll()' decorator imported from 'lodash-decorators', only caches items that you actually use -- but holds on to all the cached items forever.

Example:

Example :
import { ProductOptionService, ProductOptionComponent } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
product$: Array<ProductOptionComponent>;
constructor(private productOptionService: ProductOptionService){}
ngOnInit(){
this.product$ = this.productOptionService.getProductOptions(product);
}
}
Parameters :
Name Type Optional Description
product Product No

instance of product object.

Returns : Array<ProductOptionComponent>

an Array of ProductOptionComponent.

getProductOptionsForGroup
getProductOptionsForGroup(product: Product, group: ProductOptionGroup)

This method returns list of ProductOptionComponent filters out ProductOptionComponent which is not associated with the group parameter.

Example:

Example :
import { ProductOptionService } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
productOptionGroup$: Array<ProductOptionComponent>;
constructor(private productOptionService: ProductOptionService){}
ngOnInit(){
this.productOptionGroup$ = this.productOptionService.getProductOptionsForGroup(product, group);
}
}
Parameters :
Name Type Optional Description
product Product No

Instance of a product to process

group ProductOptionGroup No

Instance of a product option group

Returns : Array<ProductOptionComponent>

an array of ProductOptionComponent.

getProductOptionTree
getProductOptionTree(product: string | Product, relatedTo?: CartItem | QuoteLineItem | OrderLineItem | AssetLineItem, applyFilter: "none" | "items" | "changes", changes?: Array)

Method takes a bundle product record and organizes the attributes and options into it's tree structure. Will filter out any attributes or option groups that are empty and associate related cart items with each option

Example:

Example :
import { ProductOptionService, Product } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
product$: Observable<Product>;
constructor(private productOptionService: ProductOptionService){}
ngOnInit(){
this.product$ = this.productOptionService.getProductOptionTree(productId);
}
}

options are selected. If the applyFilter is 'changes' it returns the attributes/options that are changed, required for helper method 'groupOptionGroups'

Parameters :
Name Type Optional Default value Description
product string | Product No

Id of the product is of type string

relatedTo CartItem | QuoteLineItem | OrderLineItem | AssetLineItem Yes

Related primary line item

applyFilter "none" | "items" | "changes" No 'none'

accepts 'none' | 'items' | 'changes', By default the value is set as 'none', i.e no filter is applied. If the applyFilter is 'items' it returns options are selected. If the applyFilter is 'changes' it returns the attributes/options that are changed, required for helper method 'groupOptionGroups'

changes Array<CartItem> Yes

changes accepts list of cartItems.

returns an observable of Product.

getRequiredOptions
getRequiredOptions(productOptionComponents: Array, cartItems: Array)

This method returns a list of product options components that must be checked to add a bundle configuration to the cart.

Example:

Example :
import { ProductOptionService, ProductOptionComponent } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
productOption$: ProductOptionComponent;
constructor(private productOptionService: ProductOptionService){}
ngOnInit(){
this.productOption$ = this.productOptionService.getRequiredOptions(productOptionComponents, cartItems);
}
}
Parameters :
Name Type Optional Description
productOptionComponents Array<ProductOptionComponent> No

List of all product option components in a bundle.

cartItems Array<CartItem> No

List of selected line items in the configuration.

Returns : Array<ProductOptionComponent>

an Array of required product options.

getRequiredUncheckedOptions
getRequiredUncheckedOptions(allOptions: Array)

This method is a work in progress. Function that returns all the options that are Required but selected from UI.

Example:

Example :
import { ProductOptionService, ProductOptionComponent } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
productOption$: ProductOptionComponent;
constructor(private productOptionService: ProductOptionService){}
ngOnInit(){
this.productOption$ = this.productOptionService.getRequiredUncheckedOptions(allOptions);
}
}
Parameters :
Name Type Optional Description
allOptions Array<ProductOptionComponent> No

an array of all product options.

Returns : Array<ProductOptionComponent>

an Array of Product option Component.

groupOptionGroups
groupOptionGroups(p: Product, attributeValue: AttributeValue | OrderAttributeValue, relatedItems: Array, applyFilter: "none" | "items" | "changes", parentItem?: CartItem | QuoteLineItem | OrderLineItem | AssetLineItem, cart?: Cart)

This method is responsible for creating the tree structure by looping through attribute groups and option groups in recursive fashion and generate tree structure keeping the primary bundle product as the root.

Example:

Example :
import { ProductOptionService, Product, CartItem, QuoteLineItem, OrderLineItem } from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
Product$: Product;
constructor(private productOptionService: ProductOptionService){}
ngOnInit(){
this.Product$ = this.productOptionService.groupOptionGroups(product, relatedItems, applyFilter);
}
}

options are selected. If the applyFilter is 'changes' it returns the attributes/options that are changed.

Parameters :
Name Type Optional Default value Description
p Product No

is an instance of product object.

attributeValue AttributeValue | OrderAttributeValue No

is an instance of AttributeValue | OrderAttributeValue object.

relatedItems Array<CartItem | QuoteLineItem | OrderLineItem | AssetLineItem> No

is a list of CartItem | QuoteLineItem | OrderLineItem object.

applyFilter "none" | "items" | "changes" No 'none'

accepts 'none' | 'items' | 'changes', By default the value is set as 'none', i.e no filter is applied. If the applyFilter is 'items' it returns options are selected. If the applyFilter is 'changes' it returns the attributes/options that are changed.

parentItem CartItem | QuoteLineItem | OrderLineItem | AssetLineItem Yes

is an instance of CartItem | QuoteLineItem | OrderLineItem object.

cart Cart Yes

is an instance of Cart object.

Returns : Product

product object.

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 assetService
Type : AssetService
Default value : this.injector.get(AssetService)
Protected cartItemService
Type : CartItemService
Default value : this.injector.get(CartItemService)
Protected cartService
Type : CartService
Default value : this.injector.get(CartService)
deletedItems
Type : Array<SelectedOption>
Default value : []
disabledItems
Type : Array<SelectedOption>
Default value : []
Protected plService
Type : PriceListService
Default value : this.injector.get(PriceListService)
Protected productService
Type : ProductService
Default value : this.injector.get(ProductService)
Protected secondaryCartService
Type : SecondaryCartService
Default value : this.injector.get(SecondaryCartService)
Protected accountService
Default value : this.injector.get(AccountService)
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 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 ""