Modules
Products
The catalogue with stock per variant, sales trends, margins, list and grid views and a quick view.
Products carry cost, an optional compareAtPrice, variants with their own stock, lowStockThreshold, an optional restockAt and 30 days of dailySales. Stock state, margin, discount and days left are derived.
Files
File | Role |
|---|---|
pages/e-commerce/products.vue | The catalogue. |
composables/useProducts.ts | Products and save, setStatus (publish or archive), duplicate, restock and remove. |
composables/useProductForm.ts | The schema of the create and edit form. |
types/models/products.ts | Products and variants. |
config/products.config.ts | Views, category icons and stock thresholds. |
utils/products.ts | Pure rules, unit tested. |
components/pages/products/ | ProductCard, ProductQuickView, ProductSalesCell, ProductStockCell. |
Data
useProducts() loads its data through a ProductsProvider (types/models/products.ts); the demo uses createProductsMockProvider(). Write a provider that calls your API and make it the default: the pages do not change. See Connect your API.
Permissions
Viewing needs products.view; create and duplicate products.create; edit and archive products.update; delete products.delete. Buttons hide with can().
Configuration
PRODUCT_VIEWS
The views: all, active and low stock.
const PRODUCT_VIEWS: ProductView[]
PRODUCT_DEFAULT_VIEW_MODE
list or grid; the choice persists in the products-layout cookie.
const PRODUCT_DEFAULT_VIEW_MODE: ProductViewMode
PRODUCT_SALES_DAYS
Days of sales history.
const PRODUCT_SALES_DAYS: 30
PRODUCT_RUNNING_LOW_DAYS
Days left that count as running low.
const PRODUCT_RUNNING_LOW_DAYS: 7
PRODUCT_DEFAULT_LOW_STOCK
The default low stock threshold.
const PRODUCT_DEFAULT_LOW_STOCK: 5
PRODUCT_CATEGORY_STYLES
The icon and colour of each category.
const PRODUCT_CATEGORY_STYLES: Record<string, { icon: string; color: string; }>Rules
Pure functions in utils/, unit tested in tests/unit/. Statuses and segments are derived from the stored data, never stored themselves.
productStock()
Total stock.
productStock(product: Pick<Product, 'variants'>): number
productStockState()
The stock state.
productStockState(product: StockFields): ProductStockState
productSalesTrend()
The sales trend.
productSalesTrend(product: Pick<Product, 'dailySales'>): number
productDaysLeft()
Days of stock left.
productDaysLeft(product: Pick<Product, 'variants' | 'dailySales'>): number | undefined
productMargin()
The margin.
productMargin(product: Pick<Product, 'price' | 'cost'>): number
productAttention()
Products that need attention.
productAttention(products: Product[]): { out: number; runningLow: number; }outrunningLowHow it works
- Operational screens have no KPI cards: analytics live in the dashboards. A warning
BaseAlertappears only when something needs attention, and its action filters the table. - Views and the list/grid toggle are
BaseToggleGroup compact fitin the table toolbar. Drafts and archived products go through the status filter. - The grid renders
ProductCards through theBaseDataTable#bodyslot, so search, filters, sorting and pagination stay shared. The table is keyed by the layout because slots are read once. - Clicking a row or card opens
ProductQuickView: price, cost, margin, a salesBaseSparkline, stock per variant, recent orders and the actions. - Create and edit stay in
BaseFormPanel+BaseForm.