Order Model
The Order model represents a single item in a customer's order. Multiple orders can be grouped together under a single payment transaction.
Structure
{
"id": 1,
"user_id": 5,
"user": {
"id": 5,
"first_name": "John",
"last_name": "Doe",
"email": "john.doe@example.com",
...
},
"store_id": 3,
"store": {
"id": 3,
"name": "My Store",
"email": "store@example.com",
...
},
"product_variant_id": 10,
"product_variant": {
"id": 10,
"product_id": 5,
"name_en": "Product Name",
"sku": "SKU-001",
"price": 29.99,
...
},
"quantity": 2,
"price": 59.98,
"currency_name": "AZN",
"payment_status": "1",
"status": "1",
"transaction_order_id": "ORDER123456",
"address_id": 1,
"address": {
"id": 1,
"user": {...},
"city": {
"id": 1,
"name": "Baku",
"country": {
"id": 1,
"name": "Azerbaijan"
}
},
"zip_code": "AZ1000",
"address": "123 Main St",
"phone": "+994501234567"
},
"created": "2025-01-15T10:30:00Z"
}
Fields
| Field | Type | Description | Notes |
|---|---|---|---|
id |
integer | Unique identifier | Auto-increment, primary key |
user_id |
integer | Customer who placed the order | Required, foreign key to UserModel |
store_id |
integer | Store that owns the product | Required, foreign key to StoreModel |
product_variant_id |
integer | Product variant ordered | Required, foreign key to ProductVariantModel |
quantity |
integer | Quantity ordered | Required, must be > 0 |
price |
float | Total price for this order item | Calculated: variant_price × quantity × currency_rate |
currency_name |
string | Currency code | e.g., "AZN", "USD" |
payment_status |
string | Payment status | "1" = Success, "2" = Failed, "3" = Pending |
status |
string | Order status | See Order Status Values below |
transaction_order_id |
string | Payment transaction ID | Links orders to payment |
address_id |
integer | Shipping address | Required, foreign key to AddressModel |
is_deleted |
boolean | Soft delete flag | Default: false |
created |
datetime | Order creation timestamp | Auto-generated |
updated |
datetime | Last update timestamp | Auto-updated |
Payment Status Values
"1"- Success (payment completed)"2"- Failed (payment failed)"3"- Pending (awaiting payment)
Order Status Values
Store-Managed Statuses
"1"- Incoming (order received)"2"- Packing (being prepared)"3"- Ready For Admin (ready for shipping)
Admin-Managed Statuses
"4"- Out For Delivery (shipped)"5"- Delivered (delivered to customer)"6"- Pickup Tasks (completed)
Special Status
"7"- Waiting (cancelled/awaiting payment)
Status Progression
- Order created with
status: "7"andpayment_status: "3" - After successful payment:
payment_status: "1"andstatus: "1" - Store updates:
"1"→"2"→"3"→"4" - Admin updates:
"4"→"5"→"6"
Relationships
- UserModel: Many-to-one relationship with customer
- StoreModel: Many-to-one relationship with store
- ProductVariantModel: Many-to-one relationship with product variant
- AddressModel: Many-to-one relationship with shipping address
- PaymentOrderModel: One-to-many relationship with payment links
Notes
- Multiple orders can share the same
transaction_order_id(grouped payment) - Stock quantity is decremented when
payment_statuschanges to "1" - Orders with
status: "7"are considered cancelled/awaiting payment - Price is calculated based on variant price, quantity, and currency conversion
- Orders are soft deleted, not permanently removed