Skip to main content

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_items table
  • 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 -T test suffix
  • Tab persistence via URL query parameter (?tab=order-generator)

Permission Required: manage_options

Version Added: 1.18.29


When to Use

Use CaseDescription
BC Export TestingGenerate orders to test Business Central insert/verify pipeline
Analytics ValidationPopulate data for report development and dashboard testing
Bulk ProcessingStress-test queue processing and cron jobs
Address ValidationTest address formatting with specific regions
TrainingCreate sample data for demonstrations

Interface

Navigate to GSM Middleware → Tools → Testing → Order Generator

Configuration Fields

FieldTypeDescription
SiteDropdownTarget site (must have active items from inventory sync)
Number of OrdersNumber (1–100)How many orders to generate
Items per OrderNumber (1–50)Line items per order
Coupon CodeText (optional)Coupon code to include
Coupon AmountNumber (optional)Discount amount
Shipping CostNumber (optional)Shipping charge to add
Sales TaxNumber (optional)Tax amount (creates SALES TAX line item)
Address ModeRadioRandom, 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:

  • Zip
  • State
  • City
  • Address
  • Country

Optional columns (auto-generated if omitted):

  • First_Name
  • Last_Name
  • Email
  • Phone
  • Address_2

A preview table shows parsed addresses before generation. Fields that will be auto-generated display "auto" in the preview.

Download Example CSV

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 = 1 AND valid = 1 are used
  • Excludes synthetic SKUs: COUPON, SHIPPING, SALES TAX, STORE CREDIT
  • Uses each item's actual price and weight when 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:

FieldSKUBehavior
Coupon AmountCOUPONNegative price line item
Shipping CostSHIPPINGShipping charge line item
Sales TaxSALES TAXTax line item

Synthetic SKUs are auto-ensured in rm_items if they don't already exist.


Results

After generation, a results table shows:

ColumnDescription
Order NumberGenerated order number with prefix
CustomerGenerated customer name
Line ItemsSKU, quantity, and price per line item
TaxSales tax amount (if provided)
TotalOrder 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

FilePurpose
src/Data/Fake_Order_Data.phpRealistic fake data generation (names, addresses for 50 states, emails, phones)
src/API/Order_Generator_API.phpREST endpoint handler
assets/js/pages/testing/OrderGeneratorTab.jsxReact UI component

Database Writes

Orders are inserted into three tables:

  • rm_order — Order header (number, site, dates, payment flags)
  • rm_address — Shipping and billing addresses
  • rm_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)

  • 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