Заказы Shop
Обзор
- Scope
- Transactional commerce flow от basket conversion через stock и payment events
Ключевые понятия
- Basket Conversion
- Transactional conversion активной непустой корзины в заказ с immutable order line snapshots.
- Active Reservation
- Временный stock claim для заказа, опционально scoped к warehouse и expiring по configured TTL.
- Reservation Commit
- Stock deduction с последующим transition reservation status в committed.
Структура
- Tables
- Baskets
- shop_baskets
- shop_basket_items
- Orders
- shop_orders
- shop_order_items
- shop_order_history
- Reservationsshop_stock_reservations
- Payments
- shop_payment_transactions
- shop_receipts
- Baskets
- Services
- PlacementModules/Shop/Services/Order/OrderPlacementService.php
- ReservationsModules/Shop/Services/Order/StockReservationService.php
- Stock LifecycleModules/Shop/Services/Order/OrderStockLifecycle.php
- EventsOrderLifecycleDispatcher
Факты
- Shop orders хранят unique number, status, payment status, amounts, currency, customer/shipping data, integration fields, timestamps и soft-deletion state. authoritative
- Order items хранят snapshot type/entity, name, SKU, quantity, unit и total prices, currency, status, metadata и external synchronization values. authoritative
- OrderPlacementService отклоняет inactive или empty baskets и запускает registered placement validators перед database transaction. authoritative
- Placement блокирует offer-backed basket items через lockForUpdate перед stock reservation work. authoritative
- Placement создаёт order и item snapshots, опционально создаёт reservations, помечает basket converted, создаёт initial history и диспатчит placed lifecycle event после commit. authoritative
- StockReservationService выводит active reservation expiry из shop.order.reservation_ttl_minutes; zero или negative TTL не создаёт expiry timestamp. authoritative
- Cancellation освобождает active reservations; expiry routine освобождает active expired reservations и также обрабатывает missing orders. authoritative
- Commit блокирует active reservations, декрементирует offer quantity или warehouse stock и помечает reservations committed. authoritative
- OrderStockLifecycle commits reservations, когда status меняется на configured commit status или payment_status меняется на paid. authoritative
Инструкции
Place Order
- validate active non-empty basket и channel validators
- open transaction и lock offer-backed basket rows
- validate availability и create order/item snapshots
- create reservations when requested
- mark basket converted и persist order history
- dispatch placed event after transaction commit
Handle Order Status Change
- if status becomes cancelled, release active reservations
- if status or payment state reaches commit condition, commit active reservations and deduct stock
Правила
Architectural rule
Не пересчитывайте historic order lines из mutable product или offer records; используйте persisted order-item snapshot.
Architectural rule
Держите order creation, line snapshots, reservation creation, basket conversion и initial history внутри placement transaction.
Примеры
Placement Flow
ShopB2C CheckoutService -> Shop OrderPlacementService
validators tagged shop.order.placement.validators run before the transaction
modules/Shop/Services/Order/OrderPlacementService.php
Channel Validator Tag
$this->app->tag(B2cCheckoutPlacementValidator::class, 'shop.order.placement.validators');
modules/ShopB2C/Providers/ShopB2CServiceProvider.php