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);
}If the customer intends to extend this service, they must ensure that the refreshCart() method is invoked either during the service initialization or within the onInit(). This is necessary to ensure that the CartService is properly initialized and the cart data is rendered as expected.
import { CartService } from '@congarevenuecloud/ecommerce';
export class CustomCartService extends CartService {
onInit()
{
this.refreshCart();
}
}
AObjectService
| 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:
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:
Parameters :
Returns :
Observable<Array<CartItem>>
observable containing list of cart items added. |
| addProductToCart | ||||||||||||||||||||||||||||||
addProductToCart(product: Product, quantity: number, cartItems?: Array
|
||||||||||||||||||||||||||||||
|
Adds a Product to Cart ,whiich is a common cart action. This Will trigger a price operation synchronously. Example:
Parameters :
Returns :
Observable<CartActionResponse>
an observable of type 'CartActionResponse' when the operation is complete. |
| bulkAddProducts | ||||||||
bulkAddProducts(items: Array<ItemRequest>)
|
||||||||
|
Adds products to the cart in bulk, triggering a price operation synchronously. 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)
|
||||||||||||||||||||||||||||||
Example:
Parameters :
Returns :
Observable<Cart>
Observable of the cloned cart when the 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. Sets the account ID, price list ID, effective price list ID on the cart and set the status to 'New'. 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. Sets the account ID, price list ID, effective price list ID on the cart and set the status to 'New' and activates the cart. If no cart name is provided, a new cart name is generated. 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:
Parameters :
Returns :
Observable<boolean>
a cold boolean observable representing the success state of the delete operation |
| deleteLocalCart |
deleteLocalCart()
|
|
The static method clears cart id from the local storage. Example:
Returns :
void
|
| fetchCartInfo | ||||||||||||
fetchCartInfo(cartId: string, relatedRecords?: string)
|
||||||||||||
|
Fetches cart details based on the given cart ID and optional related records. Example:
Parameters :
Returns :
Observable<Cart>
Observable of the cart response. |
| generateCartName |
generateCartName()
|
|
Generates a unique cart name from the user initials and current timestamp.
For example: For a user named
Returns :
Observable<string>
An observable that emits the generated cart name as a string. |
| getActiveCart | ||||||||||
getActiveCart(filters: Array<FieldFilter>)
|
||||||||||
|
The getActiveCart method returns the product configuration record that is activated with the most recent activation date. Example:
Parameters :
Returns :
Observable<Cart>
observable instance of the active cart. |
| getActiveCartFilters |
getActiveCartFilters()
|
|
Generates an array of filters to retrieve the active cart for the user. These filters help narrow down the search for the active cart and fetch entries as needed. This method applies a set of default filters while fetching user's active cart. However, implementors can choose to pass their own filters by extending this method. The method applies different filters based on the presence of a local cart. The filters defined by this method are as follows:
(Note: The
Returns :
Array<FieldFilter>
An array of filters based on whether the local cart exists in the local storage. |
| getCart |
getCart()
|
Returns :
Cart
|
| getCartList | ||||||||||||||||||||||||||||
getCartList(filters?: Array<FieldFilter>, relatedRecords: string, pageSize: number, limit: number, sortBy: string, sortDirection: "ASC" | "DESC")
|
||||||||||||||||||||||||||||
|
Fetches the list of carts. Example:
Parameters :
Returns :
Observable<CartResult>
Array of Cart records and its total count.. |
| getCartPriceStatus |
getCartPriceStatus()
|
|
This method retrieves the current pricing state of the cart.. Example:
Returns :
Observable<boolean>
boolean returns if pricing on cart is pending or recent attempt to price the cart has failed. |
| getCartWithId | |||||||||||||||
getCartWithId(cartId: string, relatedRecords: string)
|
|||||||||||||||
|
This method fetches cart details based on the cart ID passed.
Parameters :
Returns :
Observable<Cart>
observable of the 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 an identifier of user's active cart from local storage. 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:
Returns :
Observable<Cart>
A hot observable containing the single cart instance |
| getOverrideCartId |
getOverrideCartId()
|
|
The static method gets the identifier of the cart overridden. 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 if the pricing on the cart is complete or not. Example:
Parameters :
Returns :
boolean
boolean value indicating whether cart processing is complete or not.. |
| isPricePending | ||||||||
isPricePending(cart: Cart)
|
||||||||
|
The method checks 'IsPricePending' flag on the cart and returns a boolean value. Example:
Parameters :
Returns :
boolean
boolean value representing 'IsPricePending' flag on the cart. |
| onInit |
onInit()
|
|
Returns :
void
|
| priceCart | |||||||||||||||
priceCart(pageNumber: number, maxPollingRetries?: number)
|
|||||||||||||||
|
Triggers the pricing engine for the active cart and publishes its state. 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 the updated cart |
| Public publish | ||||||||
publish(cart: Cart)
|
||||||||
|
Publish method is used to emit the current state of the cart. Example:
Parameters :
Returns :
void
|
| removeCartItem | ||||||||
removeCartItem(cartItem: CartItem)
|
||||||||
|
Removes the specified cart item from the cart. Will trigger a reprice cart operation. 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. |
| repriceBOCart | ||||||
repriceBOCart(cart?: Cart)
|
||||||
|
This method performs pricing of the cart associated to the business objects
Parameters :
Returns :
Observable<Cart>
|
| setCartActive | |||||||||||||||
setCartActive(cart: Cart, priceCart: boolean)
|
|||||||||||||||
|
setActiveCart: Method sets the selected cart as active and deactivates any other carts Example:
Parameters :
Returns :
Observable<Cart>
Observable |
| setCurrentCartId | ||||||
setCurrentCartId(cartId: string)
|
||||||
|
The static method sets the current cart in the local storage. Example:
Parameters :
Returns :
void
|
| setEffectiveDate | ||||||||
setEffectiveDate(cart: Cart)
|
||||||||
|
Sets effective date on a given cart based on the cart payload passed. 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:
Parameters :
Returns :
void
|
| updateCart | ||||||||
updateCart(cart: Cart)
|
||||||||
|
Updates a given cart based on the cart object passed. 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: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 : BehaviorSubject<boolean>
|
Default value : new BehaviorSubject(false)
|
| 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
|
| Public showInfo |
Type : EventEmitter<literal type>
|
Default value : new EventEmitter<{ title: string, message: string, timeout: number }>()
|
| Protected state |
Type : BehaviorSubject<Cart>
|
Default value : new BehaviorSubject(null)
|
| Protected STORAGE_KEY |
Default value : PlatformConstants.LOCAL_CART
|
| 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)
|
| Protected userViewService |
Type : UserViewService
|
Default value : this.injector.get(UserViewService)
|