The admin enables or disables each option (phone, address, Snapchat, Instagram, Telegram, SimpleX, WhatsApp, Signal, notes, preferred time) from a new "Checkout fields" page; the customer's name is always asked. Backend - checkoutfields module: single-row settings (CHECK id = 1), public GET and admin GET/PUT. - orders: answers stored as JSONB (contacts, info_sup); the customer phone moves from customer_phone to contacts.phone (migration 000034 copies existing values before dropping the column). - Orders are validated against the live settings: disabled options and unknown keys are dropped, enabled phone/address are required, and format, length and control characters are checked. - The Telegram notification includes the answers. Frontend - Checkout form generated from the enabled options; admin settings page; answers shown in the order list and detail. - API calls live in src/api (checkoutFields.ts, orders.ts); ApiError keeps the response body so the rejected field can be reported. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
49 lines
1.8 KiB
Go
49 lines
1.8 KiB
Go
// Package orders lets a customer place an order directly from the
|
|
// storefront, and lets the admin track and update it. Pricing is never
|
|
// trusted from the client: each line is resolved against the pricing
|
|
// module's authoritative price tier at creation time.
|
|
//
|
|
// Whether an order requires a logged-in (and possibly identity-verified)
|
|
// customer account is an admin-configurable gate, not a fixed rule of this
|
|
// package -- see gate.go and site.Settings.CustomerAccountsEnabled.
|
|
package orders
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Order struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
|
|
CustomerID *uuid.UUID `gorm:"type:uuid;index"`
|
|
CustomerName string `gorm:"not null"`
|
|
TotalCents int64 `gorm:"not null;default:0"`
|
|
Notes string `gorm:"not null;default:''"`
|
|
Contacts Contacts `gorm:"type:jsonb;not null;default:'{}'"`
|
|
InfoSup InfoSup `gorm:"type:jsonb;not null;default:'{}'"`
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
func (Order) TableName() string { return "orders" }
|
|
|
|
// OrderItem snapshots the product name, unit symbol and unit price at order
|
|
// time, so the order stays accurate even if the product/unit is later
|
|
// renamed or deleted.
|
|
type OrderItem struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primaryKey"`
|
|
OrderID uuid.UUID `gorm:"type:uuid;not null;index"`
|
|
ProductID *uuid.UUID `gorm:"type:uuid"`
|
|
ProductName string `gorm:"not null"`
|
|
PriceTierID *uuid.UUID `gorm:"type:uuid"`
|
|
UnitSymbol string `gorm:"not null"`
|
|
TierQuantity float64 `gorm:"not null"`
|
|
Multiplier int64 `gorm:"not null;default:1"`
|
|
UnitPriceCents int64 `gorm:"not null"`
|
|
TotalCents int64 `gorm:"not null"`
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
func (OrderItem) TableName() string { return "order_items" }
|