The CXACartContext service
The CXACartContext service handles cart related methods and manages the cart count caching.
The CXACartContext service, introduced in Sitecore XC 10, replaces the CartContext service. Events previously performed by CartContext such as TriggerCartUpdateEvent and SubscribeHandler have been moved to consume CXAObservable instead.
The CXACartContext service performs the following methods. It interacts with CXAObservable and uses various shared events.
|
Method |
Description |
Code |
|---|---|---|
|
|
Gets a boolean value indicating whether the cart count should be cached. If it is true, the cart count is stored in the browser |
RequestResponse |
|
|
Gets a boolean value indicating whether the cart count is available in the browser |
RequestResponse |
|
|
Gets the value of the cart count. |
RequestResponse |
|
|
Updates the cart count in the browser |
RequestResponse |
|
|
Removes the cached cart count from the browser |
RequestResponse |
|
|
Calls to |
RequestResponse where:
|
|
|
Calls to |
RequestResponse where:
|
|
|
Calls to |
RequestResponse where:
|
|
|
Calls to |
RequestResponse where:
|
|
|
Calls to |
RequestResponse where:
|
|
|
Calls to If there are multiple calls to |
RequestResponse |
|
|
When |
RequestResponse |
|
|
Calls to |
RequestResponse |
|
|
Calls to |
RequestResponse where:
|
|
|
Forwards the call to |
RequestResponse |
|
|
Calls to |
RequestResponse where:
|
|
|
Calls to |
RequestResponse where:
|
CXACartContext emits the event CXAEvent.CartUpdated via CXAObservable when the cart object is received in the response of certain Ajax calls, including:
-
AddCartLine -
AddBundleCartLine -
AddCartLinesWithSublines -
RemoveCartLine -
UpdateCartLineQuantity -
GetCart -
GetMinicart -
RemoveMinicartLine -
GetPromoCodes
All the methods above might be calling to different API endpoints, but all the API endpoints return the same CartJsonResult model so the event can be emitted with the cart object as the event argument.
SXA Storefront uses several shared events. The following sections contain details about the cart model and illustrate the call sequence.
Updated cart model
The following class diagram shows the model for the CXAEvent.CartUpdated event, which is found in the cart-minicart-model.js, the cart-freeegiftselections-model.js, as well as the cart-lines-model.js. If the the Free Gift Selection rendering, Minicart rendering, or the Shopping Cart Lines rendering subscribes to the CXAEvent.CartUpdated event, the response returned is Sitecore.Commerce.XA.Feature.Cart.Models.JsonResults.CartJsonResult, which is the updated cart.
Minicart update call sequence
The following diagram shows the call sequence for Minicart updates.