Setup¶
The Shopping Cart extension comes with some pre-configured examples of views/forms using SearchKit/FormBuilder.
However, because it is so flexible and data varies by each CiviCRM setup you will likely need to customise and modify those forms.
Anonymous (not logged in) users¶
Carts are supported for anonymous users as well as logged in contacts - the cart is tracked against the session instead of a contact_id until the cart is submitted.
To allow this, grant the "Access Shopping Cart" permission to the Anonymous role - it is not granted to anyone by default.
Who can see which cart¶
A user reaches only the carts they own - by contact when logged in, by session when anonymous - and only while the cart is still open. Holders of "administer CiviCRM data" reach every cart, and do not need "Access Shopping Cart" granted separately.
View My Shopping Cart¶
- Form: afsearchViewMyShoppingCart
- URL (frontend): civicrm/shoppingcart/view
This form should not require any additional configuration.
Do not enable "Bypass permissions" on the SearchKit table. Cart rows are scoped by the row-level ACL described above, so it is not needed - and turning it on disables that ACL for both the table's own query and its inline editing, which would let any user of the form reach any cart item by id.
If you copy/rename the "View My Cart" SearchDisplay (eg. to further customise the columns),
add its name to the shoppingcart_cart_display_names setting so the cart_id filter still gets
applied automatically. It defaults to ['View_My_Cart_Table'] - the name of the SearchDisplay
that ships with this extension. For example:
Civi::settings()->set('shoppingcart_cart_display_names', ['View_My_Cart_Table', 'My_Custom_Cart_Table']);
Checkout button¶
- Form: afformShoppingCartCheckout
- URL (frontend): civicrm/shoppingcart/checkout
The form must contain one entity of "Cart1" configured as follows:
- Security: Form-based
- Allowed actions: Update
- Accept ID from URL: No
- Autofill: Current Cart
Payment form¶
Requires civi_contribute (core) with afform contributions enabled (contribute_enable_afform_contributions).
- Form: To do
- URL (frontend): civicrm/shoppingcart/pay
To do: Write up requirements. Both checkout and Payment forms need to be form-based so they work/prefill etc. We should think about updating form permissions to use "Access shopping cart" instead of groups.
Other forms: - Thankyou form - Add items to cart (via searchkit grid/action + formbuilder submission) - Discounts - Existing pending payment