> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spurtcommerce.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Shopping List(Admin)

> Developer guide for installing, configuring, and integrating the Shopping List add-on.

The **Shopping List (Shopping Cart) add-on** extends Picco360 / SpurtCommerce with customer-managed shopping lists and vendor-assisted cart management. Customers can create lists and manage products/SKU variants. Vendors can view customer lists, add products on a buyer's behalf, duplicate lists, record order conversions, and review dashboard analytics.

> **Naming:** The source module is named `ShoppingCart`. The user-facing feature is referred to as Shopping List / Shopping Cart. This guide retains the source names for code, database tables, and API routes.

## Features

### Storefront customers

* Create, rename, view, and delete shopping-list groups.
* Add, update, and remove product/SKU line items.
* View list subtotal and item count.
* Retrieve enriched item details, including product, SKU, pricing, discount/special pricing, and stock status.
* Use a lightweight list endpoint for dropdowns and SKU-in-list indicators.

### Vendors

* View customer shopping lists with filters.
* Add products to a customer's list, subject to tenant, stock, and quantity validation.
* Duplicate a list for a customer.
* View list details and products.
* Mark a list as ordered for conversion tracking.

### Vendor analytics

* Repeated products and repeat customers.
* New-list and order-conversion counts.
* Total revenue from ordered lists.
* Date-grouped list and new-customer charts.
* Trending products based on ordered lists.

## Architecture

The add-on uses a layered architecture integrated with the platform's routing, dependency injection, ORM, and event-hook infrastructure.

```text theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
HTTP request
    |
Tenant / authentication middleware
    |
Controller -> DTO validation -> Service -> Repository -> TypeORM -> Database
                                  ^
                                  |
Platform events <---- ShoppingCartHook
```

***

Layer                               Responsibility

***

Controllers                         Store and vendor HTTP endpoints using `routing-controllers`.

Request DTOs                        Validate payloads with `class-validator` and `class-transformer`.

Services                            Business logic and coordination through `typedi`.

Repositories                        TypeORM access and custom reporting queries.

Models                              Entities mapped to `shopping_cart` and `shopping_cart_detail`.

Migrations                          Schema changes, plugin registration, and permission seeding.

## Hook                                Connects order-placement and customer-deletion events through `HookUtil`.

## Technology stack

Area                   Technology

***

Language / runtime     TypeScript / Node.js Routing                `routing-controllers` Dependency injection   `typedi` ORM                    TypeORM Validation             `class-validator`, `class-transformer` Database               MySQL / MariaDB Dates                  `moment.js` Metadata               `reflect-metadata` Platform integration   `HookUtil`, `getDataSource`

The supplied README does not state exact dependency version constraints. Confirm compatibility against the target SpurtCommerce/Picco360 application's package configuration.

## Directory structure

```text theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
ShoppingCart/
├── ShoppingCartHook.ts
├── controllers/
│   ├── store/
│   │   ├── StoreShoppingCartController.ts
│   │   ├── StoreShoppingCartDetailController.ts
│   │   └── requests/
│   └── vendor/
│       ├── VendorShoppingCartController.ts
│       ├── VendorShoppingCartDashboardController.ts
│       └── requests/
├── models/
│   ├── ShoppingCart.ts
│   └── ShoppingCartDetail.ts
├── repositories/
│   ├── ShoppingCartRepository.ts
│   └── ShoppingCartDetailRepository.ts
├── services/
│   ├── ShoppingCartService.ts
│   └── ShoppingCartDetailService.ts
└── migrations/
    ├── 1747200087804-ShoppingCartPluginSeed.ts
    ├── 1747200372449-CreateShoppingCartTable.ts
    ├── 1747200938997-CreateShoppingCartDetailTable.ts
    ├── 1748514150206-AlterShoppingCartPluginSeed.ts
    ├── 1749279888714-AddCollumnIsOrdered.ts
    ├── 1750051962853-UpdatePluginRoutingUrl.ts
    ├── 1750066197446-AddCollumnShoppingCart.ts
    ├── 1751352779017-UpdatePluginRouteUrl.ts
    └── 1752584905864-AddVendorPermissionShoppingCart.ts
```

### Main components

***

Component                                 Responsibility

***

`StoreShoppingCartController`             Storefront list-group operations.

`StoreShoppingCartDetailController`       Storefront line-item operations.

`VendorShoppingCartController`            Vendor list management, duplication, and order status.

`VendorShoppingCartDashboardController`   Vendor analytics endpoints.

`ShoppingCartService`                     Shopping-list group business logic and query-builder listing.

`ShoppingCartDetailService`               Line-item business logic.

`ShoppingCartRepository`                  Custom reports: repeated products/customers, revenue, and charts.

## `ShoppingCartDetailRepository`            Line-item repository wrapper.

## Data model

The add-on has two primary entities with a one-to-many relationship:

```text theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
ShoppingCart (1) -------- (N) ShoppingCartDetail
```

### `ShoppingCart` --- `shopping_cart`

Represents a shopping-list group owned by a customer within a tenant.

***

Field                               Description

***

`id`                                Primary key.

`customer_id`                       Owning customer.

`name`                              Shopping-list name.

`is_default`                        Default-list flag.

`is_active`                         Active flag.

`is_delete`                         Soft-delete flag.

`tenant_id`                         Tenant/vendor scope.

`created_by`, `modified_by`         Creator and last modifier user IDs.

`created_date`, `modified_date`     Creation and modification timestamps.

`is_ordered`                        Whether the list has been ordered (`0` / `1`).

`customer_user_id`                  Customer user ID.

`created_by_type`                   Creator type: `seller` or `buyer`.

## `notes`                             List notes.

When a customer creates a new default list, an existing default list is first changed to non-default.

### `ShoppingCartDetail` --- `shopping_cart_detail`

Stores line items inside a list.

***

Field                               Description

***

`id`                                Primary key.

`product_id`                        Product ID.

`shopping_cart_id`                  Parent list ID; foreign key to `shopping_cart.id`.

`sku_id`                            Selected SKU ID.

`variant_option_id`                 Variant option ID.

`variant_option_name`               Variant option name.

`quantity`                          Quantity; default `1`.

`price`                             Unit price; `decimal(10,2)`, default `0.00`.

`notes`                             Item notes.

`is_active`, `is_delete`            Active and soft-delete flags.

## Audit fields                        `created_by`, `modified_by`, `created_date`, `modified_date`.

The detail table's foreign key cascades when its parent cart record is deleted.

## Response format

The supplied README describes the platform response envelope as:

```json theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
{
  "status": 1,
  "message": "Success message",
  "data": {}
}
```

`status` is documented as `1` or `0`. The exact `message` and `data` structure varies by endpoint. The source README does not include exact request DTOs or endpoint-level JSON examples; consult the relevant controller and request DTO before implementing a client.

## Hooks and cross-module integration

`ShoppingCartHook.ts` self-registers with the platform's central `HookUtil`. It exposes repository-safe operations such as save, find, find-one, update, and delete-shopping-cart. Repository access is guarded so the hook can be called before the TypeORM `DataSource` is initialized or before the `ShoppingCart` entity is registered.

***

Event                             Handler                  Behavior

***

`shopping_cart_order`             `handleOrder`            Marks the referenced list `isOrdered = 1` when an order is placed.

`shopping_list_order`             `handleOrder`            Alias for the order event.

`shopping_cart_customer_delete`   `handleCustomerDelete`   Soft-deletes lists belonging to a deleted customer user.

## `shopping_list_customer_delete`   `handleCustomerDelete`   Alias for the customer-deletion event.

The README does not specify the exact event payload. Inspect the hook implementation and platform event callers before emitting these events from another module.

## Permissions

Migration `1752584905864-AddVendorPermissionShoppingCart.ts` seeds the **Shopping List** permission group (`slug_name = shopping-list`, sort order `32`).

### Vendor permissions

Slug                        Name                      Listed

***

`list-shopping-list`        List Shopping List        Yes `edit-shopping-list`        Edit Shopping List        No `duplicate-shopping-list`   Duplicate Shopping List   No

### Storefront permissions

The store controllers reference these customer permissions:

* `create-shopping-list`
* `view-shopping-list`
* `view-shopping-list-line-item`
* `delete-shopping-list`
* `edit-shopping-list-line-item`
* `delete-shopping-list-line-item`

Assign the relevant permissions to the appropriate customer and vendor roles in the host application.

## Database migrations

Run migrations in timestamp order using the platform's TypeORM migration runner.

***

Order Migration                                            Purpose

***

1 `1747200087804-ShoppingCartPluginSeed.ts`            Registers the ShoppingCart plugin (Sales type; initial vendor route).

2 `1747200372449-CreateShoppingCartTable.ts`           Creates `shopping_cart`.

3 `1747200938997-CreateShoppingCartDetailTable.ts`     Creates `shopping_cart_detail` and its cascading foreign key.

4 `1748514150206-AlterShoppingCartPluginSeed.ts`       Updates/upserts the plugin record.

5 `1749279888714-AddCollumnIsOrdered.ts`               Adds `is_ordered`.

6 `1750051962853-UpdatePluginRoutingUrl.ts`            Updates vendor and dashboard plugin routes.

7 `1750066197446-AddCollumnShoppingCart.ts`            Adds `customer_user_id`, `created_by_type`, and `notes`.

8 `1751352779017-UpdatePluginRouteUrl.ts`              Adds store routes and create-duplicate route metadata.

## 9 `1752584905864-AddVendorPermissionShoppingCart.ts`   Seeds the Shopping List vendor permission group and permissions.

> **Production caution:** The supplied README says every migration `down()` method is a no-op and describes the migrations as forward-only. Back up the database and review migration behavior before applying them. Do not assume that a normal migration rollback will reverse these changes.

## Installation (Pre-built Premium Add-on)

The Shopping List module is delivered as a pre-built premium add-on package. Install the compiled JavaScript files supplied by SpurtCommerce; do not run a TypeScript build for this delivered package.

### 1. Place the package in the add-ons directory

Extract the delivered package into the `add-ons/` folder in the SpurtCommerce project root (the folder containing `main.js` and `package.json`). Preserve the package structure and use the folder name supplied by SpurtCommerce.

The package can use either of these layouts:

**Compiled files at the add-on root:**

```text theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
my-spurtcommerce-project/
├── add-ons/
│   └── shopping-list/
│       ├── index.js
│       ├── controllers/
│       ├── models/
│       ├── repositories/
│       ├── services/
│       └── migrations/
├── main.js
└── package.json
```

**Compiled files inside `dist/`:**

```text theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
my-spurtcommerce-project/
├── add-ons/
│   └── shopping-list/
│       ├── package.json
│       └── dist/
│           ├── index.js
│           └── ...
├── main.js
└── package.json
```

For the `dist/` layout, the add-on folder must include a root `package.json` with a `main` entry pointing to the compiled entry file:

```json theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
{
  "name": "<addon-name>",
  "version": "1.0.0",
  "main": "dist/index.js"
}
```

Alternatively, add a root `index.js` containing `module.exports = require('./dist');`. A nested `dist/` folder without a root entry point is not discovered as an add-on package.

### 2. Configure required environment settings

Review the delivered package’s README or handover notes for add-on-specific environment variables. Add only the documented values to the SpurtCommerce project's `.env` file. The Shopping List source notes supplied for this guide do not identify a required add-on-specific environment variable.

### 3. Install extra dependencies only when required

SpurtCommerce supplies its core dependencies. If the delivered Shopping List package explicitly lists an additional third-party dependency, install that dependency from the project root:

```bash theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
npm install <package-name>
```

Do not run a TypeScript build for the pre-built package.

### 4. Start or restart the application

Start SpurtCommerce using the command configured for your project, for example:

```bash theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
node main.js
```

or:

```bash theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
npm start
```

Restart the application after copying the add-on or changing environment settings. No manual changes to `main.js` or core loader files are required when the supported add-on registry is present.

### 5. Automatic discovery, database setup, and route registration

During startup, SpurtCommerce automatically:

1. Scans `add-ons/` through `addonRegistry` and loads the package’s `spurtcommerceAddon` manifest.
2. Registers the `ShoppingCart` and `ShoppingCartDetail` entities through `typeormLoader`, runs the package migrations, and calls the manifest initializer when supplied.
3. Registers the plugin through `pluginLoader`.
4. Mounts the add-on's Store and Vendor controllers through `expressLoader` under `/api/*`.
5. Registers the Shopping List hooks through `HookUtil`.

The add-on contains nine migrations. The supplied source notes describe the migration `down()` methods as no-ops/forward-only. Back up the database and review the delivered migration files before production installation; do not rely on an automatic rollback to reverse schema changes.

### 6. Verify installation and enable the add-on

Check the startup log for a discovery message similar to:

```text theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
[AddonRegistry] Discovered local add-on: <AddonPluginName> (<addon-name>)
```

Then confirm that the plugin is enabled in Admin or in the `plugins` table:

```sql theme={"theme":{"light":"github-dark-default","dark":"github-light-default"}}
SELECT id, plugin_name, slug_name, plugin_status
FROM plugins
WHERE slug_name = '<addon-slug>';
```

Confirm `plugin_status = 1`, then test the Storefront and Vendor endpoints documented above. Verify customer list operations, vendor-assisted list operations, order conversion, permissions, and notifications in a development or staging environment before production use.

### Troubleshooting installation

| Symptom | Likely cause | Resolution |
| - | - | - |
| Add-on not discovered | Missing root `index.js`, incorrect folder placement, or `dist/` folder without a root entry point | Add the required root `package.json` (`main: "dist/index.js"`) or root `index.js` shim and restart the application. |
| API returns `404` | Server was not restarted or controllers were not loaded | Restart the server and inspect the add-on discovery logs. |
| API returns `403` | Plugin is disabled or required permissions are not assigned | Enable the plugin and verify vendor/customer permissions. |
| Missing module error | An add-on-specific dependency is not installed | Install the dependency listed by the delivered package documentation. |
| Migration/database error | Migration failed, entity registration is incomplete, or package and core versions are incompatible | Review startup logs, confirm version compatibility, and restore from backup if required. |

## Operational considerations

* **Tenant isolation:** Preserve vendor tenant checks for lists, products, and SKUs.
* **Inventory validation:** Keep stock and min/max quantity checks when extending line-item operations.
* **Email notifications:** Vendor add-item and duplicate-list flows use email template ID `60`. Verify that the template and mail service are configured.
* **Soft deletion:** The entities use `is_delete`; customer deletion is handled through a soft-delete hook.
* **Order conversion:** `is_ordered` records conversion, and the order hook updates it.
* **Forward-only migrations:** Back up the database and plan manual recovery before applying migrations to production.

## Troubleshooting

***

Issue                               Checks

***

Store/vendor routes are missing     Check controller discovery and confirm plugin route migrations have run.

Database or table errors            Confirm both entities are registered and migrations ran in timestamp order.

Vendor cannot access a list         Check tenant ownership and the relevant vendor permission.

Customer receives an authorization  Check the customer's storefront error                               shopping-list permissions.

Customer does not receive a         Verify mail configuration and email notification                        template ID `60`.

List is not marked ordered          Verify the order flow emits `shopping_cart_order` or `shopping_list_order` with the payload expected by the hook.

## Dashboard report is empty           Check test data, `is_ordered`, and the report query filters.

## Source files for deeper implementation details

For exact DTO fields, event payloads, and report query parameters not present in the README, inspect:

* `controllers/store/StoreShoppingCartController.ts`
* `controllers/store/StoreShoppingCartDetailController.ts`
* `controllers/vendor/VendorShoppingCartController.ts`
* `controllers/vendor/VendorShoppingCartDashboardController.ts`
* `controllers/store/requests/`
* `controllers/vendor/requests/`
* `models/ShoppingCart.ts`
* `models/ShoppingCartDetail.ts`
* `ShoppingCartHook.ts`
* `repositories/ShoppingCartRepository.ts`
* `services/ShoppingCartService.ts`
* `services/ShoppingCartDetailService.ts`

## License

The supplied README does not specify the add-on's license. Check the source repository's license file before redistribution or modification.

## API Endpoints

### Storefront API

The storefront endpoints allow customers to manage their own shopping-list groups and line items.

1. **Create a list** --- `POST /api/store-shopping-cart`. Uses `create-shopping-list`; a new list is marked as created by a buyer. If it becomes the default list, the existing default is unset.
2. **Add or update items** --- `POST /api/store-shopping-cart-detail`. Validates product/SKU, minimum and maximum quantity, and stock. If the same product + SKU already exists, its quantity is incremented.
3. **List groups** --- `GET /api/store-shopping-cart`. Returns lists with subtotal and item count.
4. **Dropdown data** --- `GET /api/store-shopping-cart/list`. Returns lightweight list data and indicates whether a SKU is already in a list.
5. **List detail** --- `GET /api/store-shopping-cart/:id/detail`. Returns line items enriched with product, SKU, pricing/discount, and stock information.
6. **Update a group** --- `PUT /api/store-shopping-cart/:id`.
7. **Delete a group** --- `DELETE /api/store-shopping-cart/:id`.
8. **Remove line items** --- `POST /api/store-shopping-cart-detail/delete`.

***

Method            Endpoint                                   Permission                         Description

***

`POST`            `/api/store-shopping-cart`                 `customer`, `create-shopping-list` Create a list group.

`PUT`             `/api/store-shopping-cart/:id`             `customer`, `create-shopping-list` Update a list group.

`GET`             `/api/store-shopping-cart/list`            `customer`, `view-shopping-list`   Lightweight dropdown list.

`GET`             `/api/store-shopping-cart`                 `customer`, `view-shopping-list`   Customer list groups.

`GET`             `/api/store-shopping-cart/:id/detail`      `customer`,                        List line-item `view-shopping-list-line-item`     details.

`DELETE`          `/api/store-shopping-cart/:id`             `customer`, `delete-shopping-list` Delete a list group.

`POST`            `/api/store-shopping-cart-detail`          `customer`,                        Add/update line `edit-shopping-list-line-item`     items.

## `POST`            `/api/store-shopping-cart-detail/delete`   `customer`,                        Remove line `delete-shopping-list-line-item`   items.

### Vendor API

Vendor operations are scoped to the vendor's tenant.

1. **List customer lists** --- `GET /api/vendor-shopping-cart`. Aggregates subtotal and item count, joins customer name, and supports customer, name, ordered-status, keyword, and date filters.
2. **Add an item** --- `POST /api/vendor-shopping-cart`. Validates tenant ownership, stock, and quantity limits; inserts or increments the line item and sends a customer notification using email template ID `60`.
3. **Duplicate a list** --- `POST /api/vendor-shopping-cart/create-duplicate`. Creates a new default list from an item list, validates product/SKU tenant ownership, and emails the customer.
4. **View list detail** --- `GET /api/vendor-shopping-cart/:id/detail`.
5. **View products** --- `GET /api/vendor-shopping-cart/:id/product-list`.
6. **Remove line items** --- `POST /api/vendor-shopping-cart/delete`.
7. **Mark as ordered** --- `PUT /api/vendor-shopping-cart/:id`, setting `is_ordered = 1`.

***

Method            Endpoint                                       Permission                  Description

***

`GET`             `/api/vendor-shopping-cart`                    `vendor`,                   List customer `list-shopping-list`        shopping lists.

`POST`            `/api/vendor-shopping-cart`                    `vendor`,                   Add an item to a `edit-shopping-list`        customer's list; send notification.

`POST`            `/api/vendor-shopping-cart/create-duplicate`   `vendor`,                   Duplicate a list `duplicate-shopping-list`   for a buyer; send notification.

`GET`             `/api/vendor-shopping-cart/:id/detail`         `vendor`,                   Retrieve list `list-shopping-list`        details.

`GET`             `/api/vendor-shopping-cart/:id/product-list`   `vendor`,                   Retrieve list `list-shopping-list`        products.

`POST`            `/api/vendor-shopping-cart/delete`             Not specified in README     Remove line items.

## `PUT`             `/api/vendor-shopping-cart/:id`                `vendor`,                   Update ordered `edit-shopping-list`        status.

### Vendor Dashboard API

All dashboard endpoints are under `/api/vendor-dashboard-shopping-cart` and are described as vendor-role endpoints.

***

Method                  Endpoint                                                           Description

***

`GET`                   `/api/vendor-dashboard-shopping-cart/reports/repeated-products`    Products appearing in more than one list.

`GET`                   `/api/vendor-dashboard-shopping-cart/reports/repeated-customers`   Customers with at least one ordered list and at least two lists overall.

`GET`                   `/api/vendor-dashboard-shopping-cart/new`                          Count of new, not-ordered lists.

`GET`                   `/api/vendor-dashboard-shopping-cart/orders/conversions`           Count of ordered lists.

`GET`                   `/api/vendor-dashboard-shopping-cart/revenue/total`                Revenue from ordered lists.

`GET`                   `/api/vendor-dashboard-shopping-cart/chart-data`                   List counts grouped by date (week/month/year).

`GET`                   `/api/vendor-dashboard-shopping-cart/customers/new`                New-customer chart data.

## `GET`                   `/api/vendor-dashboard-shopping-cart/products/trending`            Trending products based on ordered lists.

The README does not provide report query parameters or detailed response schemas. Check `VendorShoppingCartDashboardController` and `ShoppingCartRepository` for those definitions.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.