Skip to content
File Structure
index.js
- Import the Api, Repository, and Service JS files from cart
- Initialize each by passing in the context (set in ecommerce Core)
- Register components by setting them as globally available vue components (
Vue.use(...))
- Set the context equal to the service, routing all method calls to the Service file
service.js
- Format incoming data correctly (checking if they are arrays for the
addItems() and removeItems() methods)
- Route method call to Repository
repository.js
- Initialize store and api from context (given by
index.js)
- Verify the cart has an updated/created timestamp to verify it exists (return empty promise if false)
- If cart has been created or updated within the last 20 minutes, return that cart (to prevent additional api calls)
- Else, call api to get the store cart given the cart UUID, setting the cart equal to the resulting data
- Provide methods that format data and route method calls to the Api file (when necessary)
api.js
- Initialize with axios provided by
index.js file
- Send requests to HQ, returning the resulting promise data
Components
index.js
- Register Cart Items as a globally available component (
ec-cart-items)
items.vue
- Provide an interface built using
<slot> tags to allow sites to customize based on this template
- Cart displays products, allows quantity changes, accounts for promotions applied/available, and lists cart totals