Lesson 80 Implementation: Supporting Unlimited Historical Auctions While Allowing Only One Active Auction per Listing
After planning the architecture in Lesson 80, it was time to implement one of the most important structural improvements in the Flipnzee Auctions plugin.
Earlier versions of the plugin prevented duplicate auctions by updating the existing auction whenever the same listing was selected. While this solved duplicate auction creation, it also prevented maintaining a complete auction history.
This lesson redesigns the logic so that a listing can have unlimited historical auctions while ensuring that only one auction can remain active at any given time.
The Problem
Originally, the plugin searched for any auction belonging to the listing.
$existing_auction = $wpdb->get_var(
$wpdb->prepare(
"SELECT id
FROM {$table}
WHERE listing_id = %d
LIMIT 1",
$listing_id
)
);
If one existed, it was updated instead of creating a new auction.
Although simple, this approach caused a major limitation:
- historical auctions could never be preserved
- every new auction overwrote the previous one
- reporting and analytics became inaccurate
New Design
Instead of checking whether the listing has ever been auctioned, the plugin now checks only for active auctions.
Conceptually the lookup becomes:
SELECT id
FROM wp_flipnzee_auctions
WHERE listing_id = ?
AND status = 'active'
LIMIT 1;
This small change completely changes the behaviour of the system.
Behaviour Before
Listing 494
| Auction ID | Status |
|---|---|
| 15 | Closed |
Creating another auction resulted in:
Auction #15 being updated.
No historical record remained.
Behaviour After
Listing 494
| Auction ID | Status |
|---|---|
| 15 | Closed |
| 21 | Closed |
| 27 | Closed |
| 35 | Active |
Each completed auction remains permanently stored.
Only one auction is active.
Code Changes
The auction lookup logic was modified so only active auctions are considered duplicates.
If an active auction exists:
- update that active auction
- return its ID
Otherwise:
- insert a completely new auction record
This preserves auction history while still preventing multiple active auctions for the same listing.
Testing Performed
Several scenarios were tested.
Test 1
Create first auction
Result:
- New auction created
✔ Passed
Test 2
Create another auction while first auction is active
Result:
- Existing active auction updated
✔ Passed
Test 3
Close auction
Result:
Auction status became Closed.
✔ Passed
Test 4
Create a new auction for the same listing
Result:
A brand-new auction record was inserted.
Previous closed auction remained untouched.
✔ Passed
Test 5
Verify All Auctions page
The administration screen correctly displayed:
Auction #35 Active
Auction #34 Closed
Both auctions belong to the same listing.
History is preserved.
✔ Passed
Benefits
The redesigned architecture provides several advantages:
- Unlimited auction history
- One active auction per listing
- Cleaner reporting
- Better analytics
- Easier auditing
- Marketplace-style auction lifecycle
- Future support for auction history pages
What Was Learned
A small SQL condition can dramatically change application behaviour.
Instead of asking:
“Has this listing ever had an auction?”
the system now asks:
“Does this listing currently have an active auction?”
This subtle change aligns the plugin with how professional marketplace platforms typically manage auction lifecycles.
Source Code
The implementation focused primarily on:
includes/class-auction-manager.php
Key improvements included:
- checking only for active auctions
- preserving closed auctions
- creating new records only when no active auction exists
- maintaining a single active auction per listing
Download Source Code
Download the starting version of the plugin before the lesson:
Download the completed version after this lesson:
Final Result
Lesson 80 successfully redesigned the auction creation workflow.
The Flipnzee Auctions plugin now supports unlimited historical auctions while enforcing a single active auction per listing, providing a scalable foundation for future features such as auction archives, historical analytics, relisting workflows, and seller performance tracking.
