Cart, Checkout & Concurrency Locks β
In high-volume e-commerce, flash sales and campaign traffic can trigger severe Race Conditionsβleading to overselling inventory beyond physical warehouse limits. Reyhan Commerce employs robust Atomic Mutexes and Pessimistic Locking during checkout.
1. Concurrency Protection Workflow β
2. Guest-to-Authenticated Cart Synchronization β
Reyhan supports seamless guest shopping with immediate cart migration upon authentication:
- Guest Phase: Unauthenticated shoppers store items locally in browser storage and Redis session keys.
- Authentication Phase: When the customer logs in via SMS OTP, the storefront issues a single synchronization call:http
POST /api/v1/cart/sync Content-Type: application/json Authorization: Bearer <sanctum_token> { "items": [ { "variant_id": 42, "quantity": 2 } ] } - Merge Engine: The backend atomically aggregates quantities, checks current stock availability, applies user-specific tier pricing, and returns the unified active cart payload.
3. Order Status State Machine β
Orders progress through a strictly defined lifecycle powered by native PHP 8.3+ Backed Enums:
php
namespace Reyhan\Core\Enums\Order;
enum OrderStatus: string
{
case PendingPayment = 'pending_payment';
case Processing = 'processing';
case Shipped = 'shipped';
case Delivered = 'delivered';
case Cancelled = 'cancelled';
case Refunded = 'refunded';
}