File

projects/congarevenuecloud/ecommerce/src/lib/modules/constraint-rules/services/constraint-rule.service.ts

Description

This service is work in progress Constraint rules are a powerful feature when configuring products. They allow you to include, excludes, recommend, validate and replace products based on business logic.

Extends

AObjectService

Index

Properties
Methods

Methods

getConstraintRuleByIds
getConstraintRuleByIds(ruleIds: Array, memoizeOptions: MemoizeOptions)
Decorators :
@MemoizeWithHash()

The method fetches all the constraint rules based on the constraint rule Id's passed.

Example:

import { ConstraintRule, ConstraintRuleService } from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{
obs$: Observable<boolean>;

constructor(private crService: ConstraintRuleService){}

ngOnInit(){
this.crService.getConstraintRuleByIds(ruleIds: Array<string>, memoizeOptions: MemoizeOptions = null).subscribe(err => {haserror = err;});
// or
this.obs$ = this.crService.getConstraintRuleByIds(ruleIds: Array<string>, memoizeOptions: MemoizeOptions = null);
}
}
Parameters :
Name Type Optional Default value Description
ruleIds Array<string> No

An array of strings representing the constraint rule IDs.

memoizeOptions MemoizeOptions No null

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

an Observable containing a list of constraint rules.

getConstraintRulesForProducts
getConstraintRulesForProducts(productList: Array<string> | Array<Product>, matchInPrimaryLines: boolean, matchInOptions: boolean)
Decorators :
@MemoizeAll()

This method can be used to fetch the list of constraint rules for the given list of productIds. It will return all the configurations of a constraint rules with constraint rule conditon and constraint rule action.

Example:

import { ConstraintRule, ConstraintRuleService } from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{
rule: Array<ConstraintRule>;
rule$: Observable<Array<ConstraintRule>>;

constructor(private crService: ConstraintRuleService){}

ngOnInit(){
this.crService.getConstraintRulesForProducts(productList: Array<string> | Array<Product>).subscribe(rulesList => {rule = rulesList;});
// or
this.rule$ = this.crService.getConstraintRulesForProducts(productList: Array<string> | Array<Product>);
}
}

This method is a work in progress.

Parameters :
Name Type Optional Default value Description
productList Array<string> | Array<Product> No

represnting the list of product Id as string or list of product instance of product object.

matchInPrimaryLines boolean No true

represnting the matchInPrimaryLines flag is a boolean value for a rule.

matchInOptions boolean No false

represnting the matchInOptions flag is a boolean value for a rule.

Observable<Array> returns an observable of Array records. This method is a work in progress.

getProductsWithAssetLineItems
getProductsWithAssetLineItems(productIds: Array)
Decorators :
@MemoizeWithHash()

This method retrieves products along with their associated asset line items.

Parameters :
Name Type Optional Description
productIds Array<string> No

list of string product identifiers to fetch the product with assetlineitem record.

observable containing a list of products with assetlineitems.

getRecommendationsForCart
getRecommendationsForCart()

This method can be used to fetch the list of product for the given cart which has recommended rules set.

Example:

import { ConstraintRule, ConstraintRuleService } from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{
products: Array<Product>;
products$: Observable<Array<Product>>;

constructor(private crService: ConstraintRuleService){}

ngOnInit(){
this.crService.getRecommendationsForCart().subscribe(products => {products = products;});
// or
this.products$ = this.crService.getRecommendationsForCart();
}
}

observable containing a list of products that match the recommended rule sets.

getRecommendationsForProduct
getRecommendationsForProduct(productId: string)

This method can be used to fetch the list of product which has recommended rules set for the list of product passed as argument.

Example:

import { ConstraintRule, ConstraintRuleService } from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{
products: Array<Product>;
products$: Observable<Array<Product>>;

constructor(private crService: ConstraintRuleService){}

ngOnInit(){
this.crService.getRecommendationsForProduct().subscribe(products => {products = products;});
// or
this.products$ = this.crService.getRecommendationsForProduct();
}
}
Parameters :
Name Type Optional Description
productId string No

Product Id for which recommended products need to be fetched

observable containing a list of products that match the recommended rule sets.

getRuleByProductId
getRuleByProductId(productId: string)

This method can be used to fetch the list of ConstraintRule records for given product identifier. It do not fetch the constraint rule record if SkipRule flag is true.

Example:

import { ConstraintRule, ConstraintRuleService } from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{
rule: Array<ConstraintRule>;
rule$: Observable<Array<ConstraintRule>>;

constructor(private crService: ConstraintRuleService){}

ngOnInit(){
this.crService.getRuleByProductId(productId: string).subscribe(rule => {rule = rule;});
// or
this.rule$ = this.crService.getRuleByProductId(productId: string);
}
}

This method is a work in progress.

Parameters :
Name Type Optional Description
productId string No

represnting the product identifier.

Observable<Array> returns an observable of Array records. This method is a work in progress.

hasPendingErrors
hasPendingErrors(cart?: Cart)

This method returns boolean value for active cart's applied rule action record based on pending flag.

Example:

import { ConstraintRule, ConstraintRuleService } from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{
haserror: boolean;
haserror: Observable<boolean>;

constructor(private crService: ConstraintRuleService){}

ngOnInit(){
this.crService.hasPendingErrors().subscribe(err => {haserror = err;});
// or
this.haserror$ = this.crService.hasPendingErrors();
}
}
Parameters :
Name Type Optional Description
cart Cart Yes

representing the cart record is an optional parameter, fetches the active cart if cart record is not passed.

Returns : Observable<boolean>

Observable returns an observable of boolean value.

Properties

Protected araiService
Type : AppliedRuleActionInfoService
Default value : this.injector.get(AppliedRuleActionInfoService)
Protected assetService
Default value : this.injector.get(AssetService)
Protected cartService
Type : CartService
Default value : this.injector.get(CartService)
Protected configService
Default value : this.injector.get(ConfigurationService)
Protected constraintRuleActionService
Default value : this.injector.get(ConstraintRuleActionService)
onConstraintRuleError
Type : EventEmitter<string>
Default value : new EventEmitter<string>()
Protected pliService
Type : PriceListItemService
Default value : this.injector.get(PriceListItemService)
Protected productOptionService
Type : ProductOptionService
Default value : this.injector.get(ProductOptionService)
Protected productService
Type : ProductService
Default value : this.injector.get(ProductService)
Protected secondaryCartService
Type : SecondaryCartService
Default value : this.injector.get(SecondaryCartService)
Protected storefrontService
Default value : this.injector.get(StorefrontService)
type
Default value : ConstraintRule
Protected userService
Type : UserService
Default value : this.injector.get(UserService)

results matching ""

    No results matching ""