Order Generator
Create fake test orders directly in the middleware database for testing sync pipelines, Business Central export, analytics reports, and bulk processing workflows.
Overview
The Order Generator is a tab within Tools → Testing that creates realistic test orders in rm_order, rm_address, and rm_lineitems tables without touching external platforms.
Key Features:
- Generate 1–100 orders per batch with 1–50 line items each
- Uses real products from the selected site's
rm_itemstable - Three address modes: random US, specific state, CSV upload, or manual entry
- Optional coupon codes, shipping costs, and sales tax line items
- Order numbers use the site's store prefix with
-Ttest suffix - Tab persistence via URL query parameter (
?tab=order-generator)
Permission Required: manage_options
Version Added: 1.18.29
When to Use
| Use Case | Description |
|---|---|
| BC Export Testing | Generate orders to test Business Central insert/verify pipeline |
| Analytics Validation | Populate data for report development and dashboard testing |
| Bulk Processing | Stress-test queue processing and cron jobs |
| Address Validation | Test address formatting with specific regions |
| Training | Create sample data for demonstrations |
Interface
Navigate to GSM Middleware → Tools → Testing → Order Generator
Configuration Fields
| Field | Type | Description |
|---|---|---|
| Site | Dropdown | Target site (must have active items from inventory sync) |
| Number of Orders | Number (1–100) | How many orders to generate |
| Items per Order | Number (1–50) | Line items per order |
| Coupon Code | Text (optional) | Coupon code to include |
| Coupon Amount | Number (optional) | Discount amount |
| Shipping Cost | Number (optional) | Shipping charge to add |
| Sales Tax | Number (optional) | Tax amount (creates SALES TAX line item) |
| Address Mode | Radio | Random, Specific State, Manual, or CSV Upload |
Address Modes
Random (Default)
Generates realistic fake addresses from all 50 US states using the Fake_Order_Data utility class. Each order gets a unique randomly-generated customer name, email, phone, and address.
Specific State
Select a US state from the dropdown. All generated orders will use addresses from that state.
Manual Entry
Enter a specific address for all generated orders. Useful for testing address validation edge cases.
CSV Upload
Upload a CSV file of addresses. The generator creates one order per row.
Required columns:
ZipStateCityAddressCountry
Optional columns (auto-generated if omitted):
First_NameLast_NameEmailPhoneAddress_2
A preview table shows parsed addresses before generation. Fields that will be auto-generated display "auto" in the preview.
Click the "Download Example CSV" link to get a properly formatted template file.
Order Number Format
Generated orders use the site's configured store prefix:
{prefix}XXXXXXXX-T
Examples:
GBG3K7MN2P-T(prefix: GBG)ST343372AB-T(prefix: ST)
The -T suffix marks them as test orders, distinguishing them from real platform orders.
Line Items
Line items use real products from the selected site's rm_items table:
- Only items with
active = 1ANDvalid = 1are used - Excludes synthetic SKUs:
COUPON,SHIPPING,SALES TAX,STORE CREDIT - Uses each item's actual
priceandweightwhen available - Random quantities assigned per line item
If the site has no active/valid items, the generator returns an error prompting you to run inventory sync first.
Synthetic Line Items
When optional fields are provided, the generator creates additional line items:
| Field | SKU | Behavior |
|---|---|---|
| Coupon Amount | COUPON | Negative price line item |
| Shipping Cost | SHIPPING | Shipping charge line item |
| Sales Tax | SALES TAX | Tax line item |
Synthetic SKUs are auto-ensured in rm_items if they don't already exist.
Results
After generation, a results table shows:
| Column | Description |
|---|---|
| Order Number | Generated order number with prefix |
| Customer | Generated customer name |
| Line Items | SKU, quantity, and price per line item |
| Tax | Sales tax amount (if provided) |
| Total | Order total |
REST API
Generate Orders
POST /wp-json/gsm-middleware/v1/testing/generate-orders
Authentication: Requires manage_options capability (WordPress nonce).
Request Body:
{
"site_id": 57,
"count": 10,
"items_per_order": 3,
"coupon_code": "SUMMER20",
"coupon_amount": 20.00,
"shipping_cost": 9.99,
"sales_tax": 8.50,
"address_mode": "random",
"state": null,
"addresses": null
}
Response:
{
"success": true,
"orders": [
{
"order_number": "GBG3K7MN2P-T",
"customer": "John Smith",
"line_items": [
{ "sku": "PROD-001", "qty": 2, "price": 49.99 },
{ "sku": "PROD-042", "qty": 1, "price": 129.00 }
],
"tax": 8.50,
"total": 237.48
}
],
"total_orders": 10
}
Technical Details
Files
| File | Purpose |
|---|---|
src/Data/Fake_Order_Data.php | Realistic fake data generation (names, addresses for 50 states, emails, phones) |
src/API/Order_Generator_API.php | REST endpoint handler |
assets/js/pages/testing/OrderGeneratorTab.jsx | React UI component |
Database Writes
Orders are inserted into three tables:
rm_order— Order header (number, site, dates, payment flags)rm_address— Shipping and billing addressesrm_lineitems— Product line items with SKU, quantity, price
Tab URL Persistence
The active Testing Tools tab is stored in the URL query parameter:
?page=gsm-testing&tab=order-generator
Uses history.replaceState so no extra browser history entries are created. Refreshing or sharing the URL returns directly to the Order Generator tab.
Troubleshooting
"No active items found for this site"
The selected site has no products with active = 1 AND valid = 1 in rm_items.
Solution: Run inventory sync for the site first (Sites → select site → Run Inventory Sync).
Orders Not Appearing in BC Export
Test orders (with -T suffix) are inserted with standard flags and will flow through the normal BC export pipeline. If you want to prevent export, manually set imported = 1 on the generated orders.
CSV Upload Errors
- Ensure CSV has the required columns:
Zip,State,City,Address,Country - Check for encoding issues (use UTF-8)
- Verify column headers match exactly (case-sensitive)
Related Documentation
- Test Order — Import individual orders from platforms for testing
- Queue Page — Monitor async job processing
- Data Analytics — View reports generated from test data
- BC Export — Business Central export pipeline