Developing Order Tracking for E-commerce
Order tracking reduces support load and builds customer trust: instead of "where's my order?" calls, user sees current status in account or via direct link. Takes 4–6 business days.
Order State Machine
Order passes through defined states. Transitions controlled by state machine:
pending → confirmed → processing → shipped → delivered → completed
↓
failed
↓
cancelled
class Order extends Model {
use HasStates;
protected function registerStates(): void {
$this->addState('status', OrderStatus::class)
->allowTransition(Pending::class, Confirmed::class)
->allowTransition(Confirmed::class, [Processing::class, Cancelled::class])
->allowTransition(Processing::class, [Shipped::class, Cancelled::class])
->allowTransition(Shipped::class, [Delivered::class, Failed::class])
->allowTransition(Delivered::class, Completed::class);
}
}
Each transition triggers event writing history, sending notification, updating timestamp.
Status History
CREATE TABLE order_status_history (
id BIGSERIAL PRIMARY KEY,
order_id BIGINT REFERENCES orders(id) ON DELETE CASCADE,
status VARCHAR(30) NOT NULL,
comment TEXT,
changed_by BIGINT REFERENCES users(id),
created_at TIMESTAMP DEFAULT NOW()
);
This table forms timeline on tracking page.
Carrier API Tracking
After shipment, order gets tracking number. System auto-queries updates:
CDEK:
$cdek = new \CdekSDK2\Client($clientId, $clientSecret);
$info = $cdek->orders()->get($order->cdek_uuid);
Russian Post:
$russianPost = new \RussianPost\TrackingClient($login, $password);
$operations = $russianPost->getOperationHistory($order->tracking_number);
Polling every 2 hours:
$schedule->command('orders:sync-tracking')->everyTwoHours();
On carrier status change — auto-update order status and notify customer.
Public Tracking Page
Available without login via token link — for guest orders and direct email:
/orders/track?token=abc123xyz
Page displays:
- Order summary
- Status timeline
- Shipping info with carrier link
- Contact support option
Status Timeline Component
Visual progress bar with steps:
const steps = ['Pending', 'Confirmed', 'Processing', 'Shipped', 'Delivered'];
const currentIndex = steps.indexOf(statusLabel[order.status]);
steps.map((step, i) => (
<div key={step} className={cn('step', {
'step-complete': i < currentIndex,
'step-active': i === currentIndex,
'step-pending': i > currentIndex,
})}>
{step}
</div>
))
Email and SMS Notifications
On each status change — email with current state and tracking link. Critical events (shipped, delivered) — additional SMS via SMS.ru:
class OrderShipped extends Notification {
public function via($notifiable): array {
return ['mail', SmsSenderChannel::class];
}
public function toMail($notifiable): MailMessage {
return (new MailMessage)
->subject("Order #{$this->order->number} shipped")
->line("Tracking: {$this->order->tracking_number}")
->action('Track order', route('orders.track', $this->order->guest_token));
}
public function toSms($notifiable): string {
return "Order #{$this->order->number} shipped. Tracking: {$this->order->tracking_number}";
}
}
Delivery Map
For courier delivery optional real-time courier location via API (Dostavista, Yandex Go). Requires WebSocket/SSE for real-time updates.
Marketplace Integration
If selling via Wildberries/Ozon, their orders pulled via APIs and displayed in unified cabinet — customer sees all orders in one place regardless of purchase channel.







