Download the PHP package tandrezone/cart-officer without Composer
On this page you can find all versions of the php package tandrezone/cart-officer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tandrezone/cart-officer
More information about tandrezone/cart-officer
Files in tandrezone/cart-officer
Package cart-officer
Short Description A lightweight, session-based PHP shopping cart package. Supports add, update, delete and order creation.
License MIT
Informations about the package cart-officer
CartOfficer
A lightweight, session-based PHP shopping cart composer package.
Supports adding products (with variants), updating quantities, deleting items and creating an order that POSTs the cart payload to your own endpoint — all with a polished, accessible slide-in UI.
Requirements
| Requirement | Version |
|---|---|
| PHP | ≥ 7.4 |
| Composer | any |
No framework required — works with any PHP project.
Installation
Quick Start
1. Create the cart endpoint (e.g. cart.php)
2. Add the CSS in your <head>
Tip: copy
public/css/cart.cssandpublic/js/cart.jsto your ownpublic/folder if you need to serve assets from a different path.
3. Configure the JS (optional, before the script tag)
4. Include the templates
Place the cart button wherever you want it (header, navbar, etc.):
Place the sidebar (and overlay) once, just before </body>:
5. Add the JS before </body>
Adding an "Add to Cart" Button to a Product
Add the class co-add-btn and the required data-* attributes to any button:
| Attribute | Required | Description |
|---|---|---|
data-product-id |
✅ | Unique product identifier |
data-product-name |
✅ | Product name shown in the cart |
data-price |
✅ | Unit price (numeric, e.g. 29.99) |
data-product-variant |
optional | Variant string (colour, size, SKU…) |
data-quantity |
optional | Units to add per click (default 1) |
Clicking the button fires an AJAX request to
cartEndpointand updates the cart badge and sidebar automatically — no page reload.
Complete Page Example
Cart Sidebar Features
When the cart icon is clicked a slide-in panel opens with:
| Feature | Description |
|---|---|
| Product table | Lists product name, variant, unit price, quantity, line total |
| Quantity controls | − / + buttons and a direct input field; changes commit on blur or button press |
| Delete item | Trash-icon button removes the line from the cart |
| Grand total | Recalculated automatically after every change |
| Create Order | POSTs the full cart payload as cart_payload JSON to your orderRoute |
| Clear cart | Empties the cart in one click (with confirmation) |
Handling the Order on Your Server
When the user clicks Create Order, CartOfficer POSTs a form to your orderRoute with the field cart_payload (JSON string).
Each item in $payload['items'] has:
PHP API
Cart
CartItem
CartController
Request parameters (POST body or JSON):
| Action | Required params |
|---|---|
add |
product_id, product_name, price (+ optional product_variant, quantity) |
update |
key, quantity |
delete |
key |
clear |
(none) |
order |
(none) |
get |
(none) |
All actions return JSON:
CSRF Protection
The JS automatically reads <meta name="csrf-token" content="…"> and includes the token as _token in the order form POST. For AJAX cart operations you may add your own middleware or validate the X-Requested-With header.
Customising Styles
Override CSS custom properties in your own stylesheet:
License
MIT