File

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

Extends

AObjectService

Index

Properties
Methods

Methods

abandonCart
abandonCart(cartId: string)
Parameters :
Name Type Optional
cartId string No
Returns : Observable<boolean>
addOptionToBundle
addOptionToBundle(bundleId: string, payload: CartRequest)

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

Example:

import { CartService, CartItem, Product } from '@apttus/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
bundleId string No

Id of the CartLineItem object for the bundle product which is getting the option added to it.

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>>
addProductToCart
addProductToCart(product: Product, quantity: number, cartItems?: Array, bundle: boolean)

Adding a Product to Cart is the most common Cart action. Will trigger a reprice operation asynchronously.

Example:

import { CartService, Product, ProductAttributeValue } from '@apttus/ecommerce';

export class MyComponent implements OnInit{

    constructor(private cartService: CartService){}

    addProductToCart(product: Product, quantity: number, productAttributeValueList: Array<ProductAttributeValue>): void{
        this.cartService.addProductToCart(product, quantity, productAttributeValueList, null, true, 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
bundle boolean No false
Returns : Observable<Array<CartItem>>

a void observable when the operation is complete

childCart
childCart()

To render the iFrame, a business object Id must be determined by the client. The Business Object Id can be retrieved from a child cart associated with the primary cart. To retrieve this child cart, this method will be invoked.

Returns : Observable<Cart>
createNewCart
createNewCart(cartData: Cart, insert: boolean, active: 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'

Example:

import { CartService } from '@apttus/ecommerce';

export class MyComponent{

    constructor(private cartService: CartService){}

    createNewCart(){
        const cart = new Cart();
        cart.Apttus_Config2__Status__c = 'Finalized';
        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

insert boolean No true
active boolean No true
Returns : Observable<Cart>

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

deleteCart
deleteCart(cart: Cart | Array)

Deletes a specified cart instance from the database

Example:

import { CartService } from '@apttus/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 to delete

Returns : Observable<boolean>

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

getCartWithId
getCartWithId(cartId: string)
Parameters :
Name Type Optional
cartId string No
Returns : Observable<Cart>
getMyCart
getMyCart(pending: boolean)

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:

import { CartService } from '@apttus/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();
    }
}
Parameters :
Name Type Optional Default value
pending boolean No false
Returns : Observable<Cart>

A hot observable containing the single cart instance

isPricePending
isPricePending(cart: Cart)

The isPricepending method checks the cart is pricepending flag and return the boolean value.

Parameters :
Name Type Optional Description
cart Cart No

instance of cart

Returns : boolean

boolean value of cart is Pricepending flag.

priceCart
priceCart(pricingMode: string)

priceCart method triggers the server-side pricing engine for the cart

Example:

import { CartService } from '@apttus/ecommerce';

export class MyComponent implements OnInit{

    constructor(private cartService: CartService){}

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

Price active cart and publishing its state to all subscribing components.

Parameters :
Name Type Optional Default value Description
pricingMode string No this.configurationService.get('pricingMode')

Pass the pricing mode you want to run pricing with. It can be turbo OR default pricing.

Returns : void
refreshCart
refreshCart()

Price active cart and publishing its state to all subscribing components.

Returns : void
removeCartItem
removeCartItem(cartItem: CartItem, async: boolean, trigger: boolean)

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

Example:

import { CartService, CartItem } from '@apttus/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 Default value Description
cartItem CartItem No

the instance of the cart item to remove

async boolean No true
trigger boolean No true

when set to false, will not notify other components that a product has been added to the cart

Returns : Observable<void>

a void observable when the operation completes

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<void>
setCartActive
setCartActive(cart: Cart)

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

Example:

import { CartService, Cart } from '@apttus/ecommerce';

export class MyComponent implements OnInit{

    constructor(private cartService: CartService){}

    setActive(cart: Cart){
        this.cartService.setCartActive(cart).subscribe(success => {...});
    }
}
Parameters :
Name Type Optional
cart Cart No
Returns : Observable<Cart>

Observable returns a boolean observable containing true if the cart was successfully set active.

updateCartItems
updateCartItems(cartItemList: Array)

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

Example:

import { CartService, CartItem } from '@apttus/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 => {...}
        );
    }
}
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.

Returns : Observable<Array<CartItem>>

a void observable when the operation has completed.

Properties

onCartError
Type : EventEmitter<CartError>
Default value : new EventEmitter<CartError>()
type
Default value : Cart

result-matching ""

    No results matching ""