Lesson 53: Prevent Duplicate Auctions by Enforcing One Auction Per Listing

When developing the Flipnzee Auctions plugin, a valuable architectural issue emerged during testing. Because the same listing was used repeatedly, multiple auction records were created for a single listing. Although this was acceptable during development, it exposed an important design flaw.

A marketplace listing should normally have only one auction associated with it. If multiple auction records exist for the same listing, the frontend may display an older auction instead of the latest one, leading to incorrect bid history, current bid values, and auction status.

In this lesson, the plugin will be improved to enforce a one-listing-one-auction relationship, ensuring cleaner data and more predictable behaviour.


What Problem Are We Solving?

During testing, several auction records existed for the same listing:

Listing ID 491

├── Auction #25
├── Auction #26
├── Auction #27
├── Auction #30
└── Auction #31

Although Auction #31 contained the latest bids, the frontend displayed Auction #25 because it appeared first in the query results.

The correct design should always be:

Listing ID 491
        │
        ▼
     Auction #31

One listing should always reference one auction.


Objectives

By the end of this lesson, the plugin will:

  • Prevent multiple auction records for the same listing.
  • Detect when an auction already exists.
  • Update the existing auction instead of creating another.
  • Keep auction history clean.
  • Ensure the frontend always displays the correct auction.

Implementation Plan

The implementation will include the following improvements:

Step 1

Check whether an auction already exists for the selected listing before inserting a new record.


Step 2

If an auction already exists:

  • Update its prices.
  • Update auction dates.
  • Update reserve price.
  • Update Buy Now price.
  • Preserve the same auction ID.

Step 3

Only create a new auction if no auction exists for that listing.


Step 4

Display an admin notice such as:

An auction already exists for this listing. The existing auction has been updated instead of creating a duplicate.

This makes the behaviour clear to administrators.


Step 5

Verify that frontend shortcodes always display the latest auction because only one auction record exists.


Expected Benefits

After completing this lesson:

  • Cleaner database structure.
  • No duplicate auctions.
  • Correct bid history.
  • Correct highest bidder.
  • Correct current bid.
  • Easier maintenance.
  • Better user experience.

What You Will Learn

This lesson introduces an important database design principle:

Enforce data integrity at the application level rather than relying on users to avoid mistakes.

Instead of allowing duplicate auction records and trying to handle them later, the plugin will proactively prevent them from being created.

This small architectural improvement will make the Flipnzee Auctions plugin significantly more reliable as development continues.


Coming Up Next

In the next implementation lesson, we will modify the auction creation logic so that every listing can have only one associated auction, automatically updating the existing auction whenever the administrator edits its settings instead of creating duplicate records.

Leave a Reply