< back

Shopping Cart

Cart Functional Overview

All carts have a similar set of functions. They must be able to add items to the cart, change quantity of items in the cart and remove items from the cart. Ideally they should also be able to estimate shipping and taxes for an order and optionally allow for entry of promotional codes (aka coupons).

Because StoreBuilder is designed for customization with an open development layer, you can implement these core functions any way you like or remove/hide these functions.

Cart Implementation Details

The cart page by default will be routed to the /cart url. The cart page will be rendered using the CartViewModel class (including any mixins or extenders for customization) and the sb-cart handlebars template in your active StoreBuilder theme.

POST Request Parameters

You may POST to /cart with either a JSON payload or Form Url Encoded values payload. It the incoming request has a Content-Type:application/json header present then StoreBuilder will look for a JSON payload. If the incoming POST request has a Content-Type:application/x-www-form-urlencoded header present then StoreBuilder will look for Form values.

GET/POST Response Body

If the incoming request has an Accept:application/json header present, then StoreBuilder will return a JSON payload in the response. Otherwise StoreBuilder will return a rendered view as text/html.

If the incoming request is not requesting a json response, then StoreBuilder will additionally look for a X-Requested-With:XMLHttpRequest header to determine whether the response should be a partial view or a complete page. If the X-Requested-With:XMLHttpRequest header is present, then StoreBuilder will return the results of the handlebars template directly, otherwise Storebuilder will route the results to be "wrapped" with any (optional) surrounding view (such as wrapping the results with a Razor view to add all the surrounding page header/footer/etc).

GET/POST Response Data

The data that will either be supplied to Handlebars for rendering a template or serialized as JSON in the response body is defined by the CartViewModel and any mixins that your custom code or other plugins have added to the CartViewModel.

CartViewModel Data

The CartViewModel exposes the following data elements for use in your cart Handlebars templates.

Field NameData TypeDescription
Id
GuidThe primary key for the Cart record.
RowId
intA database generated int key for the cart record.