projects/congarevenuecloud/ecommerce/src/lib/modules/cart/services/cart.service.ts
A Cart contains the product and custom cart items that a user may wish to purchase.
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);
}
AObjectService
Properties |
|
Methods |
|
abandonCart | ||||||||
abandonCart(cartId: string)
|
||||||||
This method is responsbile to abandon the cart.
Parameters :
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 :
Parameters :
Returns :
Observable<Cart>
Observable |
addOptionToBundle | ||||||||
addOptionToBundle(payload: CartRequest)
|
||||||||
Adds an option product to a bundle product that is already in the current active cart. Example:Example :
Parameters :
Returns :
Observable<Array<CartItem>>
observable containing list of cart items added. |
addProductToCart | ||||||||||||||||||||||||||||||
addProductToCart(product: Product, quantity: number, cartItems?: Array
|
||||||||||||||||||||||||||||||
Adding a Product to Cart is the most common Cart action. Will trigger a price operation synchronously. Example:Example :
Parameters :
Returns :
Observable<CartActionResponse>
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 :
Parameters :
Returns :
Observable<CartActionResponse>
an observable of type CartActionResponse when the operation is complete. |
cloneCart | ||||||||||||||||||||||||||||||
cloneCart(cartId: string, payload?: Cart, price: boolean, isChildObjectToClone: boolean, relatedRecords: string)
|
||||||||||||||||||||||||||||||
Parameters :
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 :
Returns :
Observable<CartActionResponse>
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 :
Parameters :
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 :
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 :
Parameters :
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 :
Parameters :
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 :
Returns :
void
|
getActiveCart | ||||||||||
getActiveCart(filters: Array<FieldFilter>)
|
||||||||||
The getActiveCart method returns the product configuration record activated with most recent activation date. Example:Example :
Parameters :
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 :
Parameters :
Returns :
Observable<CartResult>
Array of Cart records and its total count.. |
getCartWithId | ||||||||
getCartWithId(cartId: string)
|
||||||||
This method fetches cart details based on the cart id passed.
Parameters :
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 :
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 :
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 :
Returns :
string
|
isCartActive | ||||||||
isCartActive(cartId: string)
|
||||||||
Method determines if a given cart is user's active cart in the application.
Parameters :
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 :
Parameters :
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 :
Parameters :
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 :
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 :
Returns :
Observable<Cart>
Observable of cart |
Public publish | ||||||||
publish(cart: Cart)
|
||||||||
Publish method is used to emit the state of the cart. Example:Example :
Parameters :
Returns :
void
|
removeCartItem | ||||||||
removeCartItem(cartItem: CartItem)
|
||||||||
Removes the specified cart item from the cart. Will trigger a reprice cart operation. Example:Example :
Parameters :
Returns :
Observable<string>
observable containing string message based on successful delete operation. |
removeCartItems | ||||||||
removeCartItems(cartItems: Array
|
||||||||
Deletes multiple cart items from the cart.
Parameters :
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 :
Parameters :
Returns :
Observable<Cart>
Observable |
setCurrentCartId | ||||||
setCurrentCartId(cartId: string)
|
||||||
The static method sets the current cart in the local storage. Example:Example :
Parameters :
Returns :
void
|
setEffectiveDate | ||||||||
setEffectiveDate(cart: Cart)
|
||||||||
Sets effective date on a given cart based on the cart payload passed. Example:Example :
Parameters :
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 :
Parameters :
Returns :
void
|
updateCart | ||||||||
updateCart(cart: Cart)
|
||||||||
Updates a given cart based on the cart object passed. Example:Example :
Parameters :
Returns :
Observable<Array<Cart>>
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 :
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 :
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 :
Returns :
Observable<CartActionResponse>
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 :
Returns :
Observable<CartActionResponse>
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 :
Returns :
Observable<Array<SummaryGroup>>
observable list of updated cart summary groups. |
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)
|