File

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

Description

A Cart contains the product and custom cart items that a user may wish to purchase.

Usage

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

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

Extends

AObjectService

Index

Properties
Methods

Methods

abandonCart
abandonCart(cartId: string)

This method is responsbile to abandon the cart.

Parameters :
Name Type Optional Description
cartId string No

identifier of the cart to abandon.

Returns : Observable<boolean>

a cold boolean observable representing the success state of the abandon operation

activateCart
activateCart(cartId: string)

The method activates the cart by updating the activation date on the cart record with current timestamp.

Example:

Example :
import { CartService, Cart } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private cartService: CartService){}

activate(cartId: string){
this.cartService.activateCart(cartId).subscribe(success => {...});
}
}
Parameters :
Name Type Optional Description
cartId string No

string identifier of the cart to be activated.

Returns : Observable<Cart>

Observable returns a cold observable of the activated cart.

addOptionToBundle
addOptionToBundle(payload: CartRequest)

Adds an option product to a bundle product that is already in the current active cart.

Example:

Example :
import { CartService, CartItem, Product } from '@congarevenuecloud/ecommerce';
export class MyComponent {
constructor(private cartService: CartService) {}
addOption(cartItem: CartItem, option: Product, quantity: number) {
this.cartService.addOptionToBundle(cartItem.Id, {
ProductId: option.Id,
Quantity: quantity;
}).subscribe(
cartItems => {...},
err => {...}
);
}
}
Parameters :
Name Type Optional Description
payload CartRequest No

CartRequest object that has the productId of the option product and the quantity to add to the bundle.

Returns : Observable<Array<CartItem>>

observable containing list of cart items added.

addProductToCart
addProductToCart(product: Product, quantity: number, cartItems?: Array, skipDefaultOptions: boolean, targetCartId?: string)

Adding a Product to Cart is the most common Cart action. Will trigger a price operation synchronously.

Example:

Example :
import { CartService, Product } from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{

constructor(private cartService: CartService){}

addProductToCart(product: Product, quantity: number): void{
this.cartService.addProductToCart(product, quantity, null, true).subscribe(
() => {...},
err => {...}
)
}
}
Parameters :
Name Type Optional Default value Description
product Product No

Product object for method.

quantity number No 1

number value for quantity.

cartItems Array<CartItem> Yes

an array of cart items associated with products.

skipDefaultOptions boolean No false

to skip default options on add to cart.

targetCartId string Yes

string identifier of the cart to add the product to. Defaulted to user's active cart.

an observable of type CartActionResponse when the operation is complete.

bulkAddProducts
bulkAddProducts(items: Array<ItemRequest>)

Adding a Product to Cart in bulk. Will trigger a price operation synchronously.

Example:

Example :
import { CartService, Product } from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{

constructor(private cartService: CartService){}

bulkAddProducts(items: Array<ItemRequest>): void{
this.cartService.bulkAddProducts(items).subscribe(
() => {...},
err => {...}
)
}
}
Parameters :
Name Type Optional Description
items Array<ItemRequest> No

is a list of ItemRequest for add products in bulk

an observable of type CartActionResponse when the operation is complete.

bulkDeleteProducts
bulkDeleteProducts(items: Array)

Deleting Products from Cart in bulk. Will trigger a price operation synchronously.

Example:

Example :
import { CartService, Product } from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{

constructor(private cartService: CartService){}

bulkDeleteProducts(items: Array<ItemRequest>): void{
this.cartService.bulkDeleteProducts(items).subscribe(
() => {...},
err => {...}
)
}
}
Parameters :
Name Type Optional Description
items Array<CartItem> No

is a list of CartItem for delete products in bulk

Returns : Observable<string>

an observable of type CartActionResponse when the operation is complete.

cloneCart
cloneCart(cartId: string, payload?: Cart, price: boolean, isChildObjectToClone: boolean, relatedRecords: string)
Parameters :
Name Type Optional Default value Description
cartId string No this.getCurrentCartId()

Cart identifier of the cart to be cloned. If the param is not specified, it creates a clone of active cart in the application.

payload Cart Yes

Product configuration instance with details to be copied to the cloned cart.

price boolean No false

Optional param to specify if the cloned cart needs to be priced. Defaulted to false.

isChildObjectToClone boolean No false

Optional param to specify if child objects on the parent cart needs to be cloned. Defaulted to false.

relatedRecords string No null

related records(items, prices etc.) to be fetched on the cloned cart. Takes in cart related fields as comma separated string.

Returns : Observable<Cart>

Observable of the cloned cart when clone operation completes.

clonePrimaryLines
clonePrimaryLines(lineItems: Array)

This method clones a list of primary cart lines. The cloned items get added to the active cart.

Parameters :
Name Type Optional Description
lineItems Array<CartItem> No

list of cart items to be cloned on the active cart.

observable of cloned cart items.

createCart
createCart(cartData: Cart)

Creates a new cart. Will set the account id, price list id, effective price list id on the cart and set the status to 'New'.

Example:

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

export class MyComponent{

constructor(private cartService: CartService){}

createCart(){
const cart = new Cart();
this.cartService.createCart(cart).subscribe(c => {...});
}
}
Parameters :
Name Type Optional Default value Description
cartData Cart No new Cart()

represents the cart instance to create new cart with. By default a fresh cart instance is set when no value is passed.

Returns : Observable<Cart>

a cold cart observable with the populated cart after inserting into the database

createCartFromQuote
createCartFromQuote(quoteId: string)

Launches a cart based on a given quote ID.

Parameters :
Name Type Optional Description
quoteId string No
  • The ID of the quote to create the cart from.
Returns : Observable<Cart>

An observable representing the created cart.

createNewCart
createNewCart(cartData: Cart, skipActivation: boolean)

Creates a new cart. Will set the account id, price list id, effective price list id on the cart and set the status to 'New' and activates the cart.

Example:

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

export class MyComponent{

constructor(private cartService: CartService){}

createNewCart(){
const cart = new Cart();
this.cartService.createNewCart(cart).subscribe(c => {...});
}
}
Parameters :
Name Type Optional Default value Description
cartData Cart No new Cart()

an instance of a cart with any prepopulated parameters.

skipActivation boolean No false

boolean if set to true skips activating the newly created cart. Defaulted to false.

Returns : Observable<Cart>

a cold cart observable with the populated cart after inserting into the database

deleteCart
deleteCart(cart: Cart | Array<Cart>)

Deletes a specified cart instance or list of carts from the database

Example:

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

export class MyComponent{
private cart: Cart;
constructor(private cartService: CartService){}

deleteCart(){
this.cartService.deleteCart(cart).subscribe(c => {...});
}
}
Parameters :
Name Type Optional Description
cart Cart | Array<Cart> No

the cart instance or list of cart instances to delete

Returns : Observable<boolean>

a cold boolean observable representing the success state of the delete operation

deleteLocalCart
deleteLocalCart()

The static method removes the cart from the local storage.

Example:

Example :
import { CartService, Cart} from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{

deleteCart(){
CartService.deleteLocalCart();
}
}
Returns : void
getActiveCart
getActiveCart(filters: Array<FieldFilter>)

The getActiveCart method returns the product configuration record activated with most recent activation date.

Example:

Example :
import { CartService, Cart} from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
activeCart$: Observable<Cart>;

constructor(private cartService: CartService){}

getActiveCart(){
this.activeCart$ = this.cartService.getActiveCart();
}
}
Parameters :
Name Type Optional Default value Description
filters Array<FieldFilter> No null

list of FieldFilter records to filter active cart based on filter condition.

Returns : Observable<Cart>

observable instance of the active cart.

getCartList
getCartList(filters?: Array<FieldFilter>, relatedRecords: string, pageSize: number, limit: number, sortBy: string, sortDirection: "ASC" | "DESC")

Fetches the list of carts.

Example:

Example :
import { CartService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private cartService: CartService){}

getCartList(){
this.cartService.getCartList().subscribe(
cartResult => {...},
err => {...}
);
}
}
Parameters :
Name Type Optional Default value
filters Array<FieldFilter> Yes
relatedRecords string No ''
pageSize number No 1
limit number No 50
sortBy string No null
sortDirection "ASC" | "DESC" No null

Array of Cart records and its total count..

getCartWithId
getCartWithId(cartId: string)

This method fetches cart details based on the cart id passed.

Parameters :
Name Type Optional Description
cartId string No

string indentfier of cart.

Returns : Observable<Cart>

observable of cart response.

getConfigStatus
getConfigStatus()

This method is responsbile to fetch cart details excluding the pricing results.

Returns : Observable<Cart>

Observable of cart

getCurrentCartId
getCurrentCartId()

The static method fetches the current cart's Id stored in local storage.

Example:

Example :
import { CartService, Cart} from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
cartId: string;
constructor(cartService: CartService){}
getCurrentCart(){
this.cartId = this.cartService.getCurrentCartId();
}
}
Returns : string
getMyCart
getMyCart()

The primary method to get the user's current cart. This is a hot observable that will be updated when the state of the cart changes.

Example:

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

export class MyComponent implements OnInit{
cart: Cart;
cart$: Observable<Cart>; // can be used in the template with {{(cart$ | async)?.Name}}

constructor(private cartService: CartService){}

ngOnInit(){
this.cartService.getMyCart().subscribe(cart => this.cart = cart);
// or
this.cart$ = this.cartService.getMyCart();
}
}
Returns : Observable<Cart>

A hot observable containing the single cart instance

getOverrideCartId
getOverrideCartId()

The static method gets the identifier of the cart overriden.

Example:

Example :
import { CartService, Cart} from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
constructor(cartService: CartService){}
GetCart(){
this.cartService.getOverrideCartId();
}
}
Returns : string
isCartActive
isCartActive(cartId: string)

Method determines if a given cart is user's active cart in the application.

Parameters :
Name Type Optional Description
cartId string No
  • string identifier of the cart record passed.
Returns : boolean

true if the cart is active, false otherwise.

isCartProcessing
isCartProcessing(cart: Cart)

The method returns a boolean which indicates the product is added as line item to cart and pricing on the cart is complete.

Example:

Example :
import { CartService, Cart} from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';
export class MyComponent implements OnInit{
isCartProcessing: Boolean;
constructor(private cartService: CartService){}
isCartProcessing(cart: Cart ){
this.isCartProcessing = this.cartService.isCartProcessing(cart);
}
}
Parameters :
Name Type Optional Description
cart Cart No

instance of cart

Returns : boolean

boolean value once cart processing is completed.

isPricePending
isPricePending(cart: Cart)

The method checks IsPricePending flag on the cart and returns a boolean.

Example:

Example :
import { CartService, Cart} from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
isPricePending: Boolean;

constructor(private cartService: CartService){}

isPricePending(cart: Cart ){
this.isPricePending = this.cartService.isPricePending(cart);
}
}
Parameters :
Name Type Optional Description
cart Cart No

instance of cart

Returns : boolean

boolean value representing IsPricePending flag on the cart.

onInit
onInit()
Returns : void
priceCart
priceCart(pageNumber: number)

priceCart method triggers the pricing engine for the cart.

Example:

Example :
import { CartService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private cartService: CartService){}

priceCart(): void{
this.cartService.priceCart().subscribe(
() => {...},
err => {...}
);
}
}

Price active cart and publishing its state to all subscribing components. When set to false, the method will directly fetch the cart status instead.

Parameters :
Name Type Optional Default value Description
pageNumber number No 1

defines the server side pageNumber to fetch the data. By default value is 1. When set to false, the method will directly fetch the cart status instead.

Returns : Observable<Cart>

Observable of cart

Public publish
publish(cart: Cart)

Publish method is used to emit the state of the cart.

Example:

Example :
import { CartService, Cart } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private cartService: CartService){}

publishCart(cart: Cart){
this.cartService.publish(cart);
}
}
Parameters :
Name Type Optional Description
cart Cart No

instance of cart.

Returns : void
removeCartItem
removeCartItem(cartItem: CartItem)

Removes the specified cart item from the cart. Will trigger a reprice cart operation.

Example:

Example :
import { CartService, CartItem } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{

constructor(private cartService: CartService){}
removeCartItem(cartItem: CartItem): void{
cartItem.Apttus_Config2__Quantity__c = quantity;
this.cartService.removeCartItem(cartItem).subscribe(
() => {...},
err => {...}
);
}
}
Parameters :
Name Type Optional Description
cartItem CartItem No

the instance of the cart item to remove.

Returns : Observable<string>

observable containing string message based on successful delete operation.

removeCartItems
removeCartItems(cartItems: Array)

Deletes multiple cart items from the cart.

Parameters :
Name Type Optional Description
cartItems Array<CartItem> No

Array of cart items to be deleted from the cart.

Returns : Observable<string>

observable containing string message based on successful delete operation.

setCartActive
setCartActive(cart: Cart, priceCart: boolean)

setActiveCart: Method sets the selected cart as active and deactivates any other carts

Example:

Example :
import { CartService, Cart } from '@congarevenuecloud/ecommerce';

export class MyComponent implements OnInit{

constructor(private cartService: CartService){}

setActive(cart: Cart){
this.cartService.setCartActive(cart).subscribe(success => {...});
}
}
Parameters :
Name Type Optional Default value Description
cart Cart No

instance of the cart to be set active.

priceCart boolean No false

determines whether to run pricing engine for the cart or skip pricing.

Returns : Observable<Cart>

Observable returns a cold observable of the activated cart.

setCurrentCartId
setCurrentCartId(cartId: string)

The static method sets the current cart in the local storage.

Example:

Example :
import { CartService, Cart} from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
SetCart(cartId: string){
CartService.setCurrentCartId(cartId);
}
}
Parameters :
Name Type Optional
cartId string No
Returns : void
setEffectiveDate
setEffectiveDate(cart: Cart)

Sets effective date on a given cart based on the cart payload passed.

Example:

Example :
import { CartService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{

constructor(private cartService: CartService){}
setEffectiveDate(cart: Cart): Observable<Cart> {
this.cartService.setEffectiveDate(cart).subscribe(
() => {...},
err => {...}
);
}
}
Parameters :
Name Type Optional Description
cart Cart No

instance of cart with effective date to be updated.

Returns : Observable<Cart>

observable instance of the updated cart.

setOverrideCartId
setOverrideCartId(cartId: string)

The static method overrides the current cart with the cart id passed.

Example:

Example :
import { CartService, Cart} from '@congarevenuecloud/ecommerce';
import { Observable } from 'rxjs/Observable';

export class MyComponent implements OnInit{
constructor(cartService: CartService){}
SetCart(cartId: string){
this.cartservice.setOverrideCartId(cartId);
}
}
Parameters :
Name Type Optional
cartId string No
Returns : void
updateCart
updateCart(cart: Cart)

Updates a given cart based on the cart object passed.

Example:

Example :
import { CartService } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{

constructor(private cartService: CartService){}
updateCart(cart: Cart): Observable<Cart> {
this.cartService.updateCart(cart).subscribe(
() => {...},
err => {...}
);
}
}
Parameters :
Name Type Optional Description
cart Cart No

instance of cart to be updated.

An Observable that emits arrays containing Cart objects.

updateCartById
updateCartById(cartId: string, payload: any)

This method updates the cart object based on the cart id and payload passed.

Parameters :
Name Type Optional Description
cartId string No

string identifier of the cart record.

payload any No

cart data to be updated.

Returns : Observable<Cart>

observable containing the updated cart.

updateCartItems
updateCartItems(cartItemList: Array)

Updates fields on the items specified in the cart item array. Will trigger a reprice cart operation.

Example:

Example :
import { CartService, CartItem } from '@congarevenuecloud/ecommerce';
export class MyComponent implements OnInit{
constructor(private cartService: CartService){}
updateCartItems(cartItem: CartItem, quantity: number): void{
cartItem.Quantity = quantity;
this.cartService.updateCartItems([cartItem]).subscribe(
() => {...},
err => {...}
);
}
}

We must ensure valid fields from cart line item object schema are passed, failure to which may result in an error thrown by the API.

Parameters :
Name Type Optional Description
cartItemList Array<CartItem> No

an array of cart items. Matches based on the id and updates the related cart items with the new fields. We must ensure valid fields from cart line item object schema are passed, failure to which may result in an error thrown by the API.

observable of cart response with updated lineitems.

updateConfigStatusDetails
updateConfigStatusDetails(lineItem: CartItem)

This method updates the status details of a given cart item, particularly the 'MUST_CONFIG' flag to 0. Updates the 'MUST_CONFIG' flag for bundle products if the 'IsCustomizable' flag is true. Additionally, sets the 'MUST_CONFIG' flag to 0 for the bundle product itself and all associated options.

Parameters :
Name Type Optional Description
lineItem CartItem No

The cart item to be updated.

An observable of CartActionResponse representing the result of the update operation.

updateSummaryGroups
updateSummaryGroups(summaryGroups: Array<SummaryGroup>)

This method updates the summary groups on active cart.

Parameters :
Name Type Optional Description
summaryGroups Array<SummaryGroup> No

list of cart summary groups to be updated on the active cart.

observable list of updated cart summary groups.

Properties

Protected actionQueue
Type : ActionQueue
Default value : this.injector.get(ActionQueue)
apiService
Type : ApiService
Default value : this.injector.get(ApiService)
Protected categoryService
Type : CategoryService
Default value : this.injector.get(CategoryService)
Protected configService
Type : ConfigurationService
Default value : this.injector.get(ConfigurationService)
fetchRevalidation
Type : EventEmitter<boolean>
Default value : new EventEmitter<boolean>()
fetchRevalidationFlag
Type : BehaviorSubject<boolean>
Default value : new BehaviorSubject(null)
Protected ngZone
Type : NgZone
Default value : this.injector.get(NgZone)
onCartError
Type : EventEmitter<CartError>
Default value : new EventEmitter<CartError>()
Protected Optional overrideCartId
Type : string
Default value : undefined
Protected pagination
Type : number
Default value : 0
Protected priceListService
Type : PriceListService
Default value : this.injector.get(PriceListService)
primaryCartInfo
Type : Cart
Default value : null
Protected state
Type : BehaviorSubject<Cart>
Default value : new BehaviorSubject(null)
Protected storefrontService
Type : StorefrontService
Default value : this.injector.get(StorefrontService)
subscription
Type : Subscription[]
Default value : []
Protected totalLines
Type : number
Default value : 0
type
Default value : Cart
Protected userService
Type : UserService
Default value : this.injector.get(UserService)

results matching ""

    No results matching ""