Skip to content

Commit

Permalink
[#17] Extending and Closing Auctions (#120)
Browse files Browse the repository at this point in the history
* [#81] Set and Get the GUID for Auctions

* [#81] Added Auction End Date/Time field

* [#81] API access method + documentation

* Fix a PHP bug.

* VS Code settings and extensions recommendations

* Update Auction Meta Box, Determine Auction Status

* Just some PR feedback that got left off.

* [#26] Data validation, restructure, & Status Column

* [#26] Added Time Until info

* Styling tweaks

* [#26] Update Auction meta when auction has started.

* [#26] Cron hook documentation

* [#26] Last minute tweaks.

* [#26] Better method name.

* [#26] Removed a space

* [#26] Swap API for $this

* [#26] More last second fixes.

* [N/A] Modified Auction Metrics block.

* [N/A] Last change to Pattern

* [#82] Add conditional trigger wrapper to Auction Start cron job.

* [#82] Bad merge

* [#82] Auctioneer class

* [#82] WIP: Trigger Start of Auction to Auctioneer

* [#82] Catch DateTime Exception

* [#82] Some Cleanup and Documentation

* [#82] Endpoint adjustment, stripped down payload, removed msg check.

* [#82] Change to Auction Start endpoint

* [#82] Added 1 last check for the guid

* [#17] Restructure ACF Fields, Bid Extension Field and API method/doc.

* [#17] Auction Close and Extension

* [#17] ACF Tab Identifiers

* [#17] Bid Extension Bug Fixes

* [#17] Default Seconds Value

* [#17] Auction Ended and Bid Extension bug fixes

* [#17] Compare MySQL Formats

* [#17] More logic bug fixes

* [#33] Restore API call to update auction

* [#33] Auction Close Signal to Auctioneer

* [#32] Auction Checkout Validation

* [#17] Extend Auction from CURRENT time.

* [#33] Auction Close and Auctions Endpoint Submodule

* [#17] Fix Upcoming calculation

* [#32] Disable Bid Now when Auction isn't active

* [#17] End Time Setting Filter and Auto-update Close Date/Time

* [#17] Pre-empty cart on Bid & Reward Products

* [#17] Some cleanup, tweaks, and API Documentation

* [#17] DRY Auctions Endpoint value

* [#17] Admin UI updates

* [N/A] Pull Request Template Update

* [#17] Moved last response update to request method

* [#17] Replaced API endpoint URLs built with sprintf

---------

Co-authored-by: Nathan Schmidt <[email protected]>
  • Loading branch information
bd-viget and nathan-schmidt-viget authored Jan 5, 2024
1 parent 259cece commit 815adb5
Show file tree
Hide file tree
Showing 13 changed files with 999 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Testing Instructions

- List out testing instructions
1. List out testing instructions

## Screenshots

Expand Down
76 changes: 71 additions & 5 deletions client-mu-plugins/goodbids/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,26 @@ Returns the current Auction ID (if valid).
`goodbids()->auctions->get_setting( string $setting, int $auction_id )`
Returns a setting value for an auction. If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->has_bid_product( int $auction_id )`
Checks if the Auction has a Bid Product. If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->get_bid_product_id( int $auction_id )`
Returns the Auction's Bid Product ID. If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->get_bid_product( int $auction_id )`
Returns the Auction's Bid Product object. If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->set_bid_product_id( int $auction_id, int $bid_product_id )`
Associates the Bid Product with the Auction and the Auction with the Bid Product.

`goodbids()->auctions->get_reward_product_id( int $auction_id )`
Returns the Auction's Reward Product ID. If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->get_reward_product( int $auction_id )`
Returns the Auction's Reward Product object. If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->get_product_type( int $product_id )`
Returns the type of the given product ID. Available types are: "bids" and "rewards".
Returns the type of the given product ID. Possible types are: "bids", "rewards", or null.

`goodbids()->auctions->get_estimated_value( int $auction_id )`
Returns the Auction Reward's Estimated Value. If `$auction_id` is not provided, the current post ID will be used.
Expand All @@ -73,6 +79,15 @@ Checks if the Auction has started. If `$auction_id` is not provided, the current
`goodbids()->auctions->has_ended( int $auction_id )`
Checks if the Auction has ended. If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->get_extensions( int $auction_id )`
Returns the number of times the Auction has been extended. If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->is_extension_window( int $auction_id )`
Checks if the Auction is currently inside the extension window. If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->get_bid_extension( int $auction_id )`
Returns the Auction's Bid Extension value (in seconds). If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->get_bid_increment( int $auction_id )`
Returns the Auction's Bid Increment value. If `$auction_id` is not provided, the current post ID will be used.

Expand All @@ -91,15 +106,24 @@ Returns the Auction's Expected High Bid value. If `$auction_id` is not provided,
`goodbids()->auctions->get_guid( int $auction_id )`
Returns the Auction's Unique GUID. If `$auction_id` is not provided, the current post ID will be used.

`goodbids()->auctions->get_bid_orders( int $auction_id, int $limit )`
`goodbids()->auctions->get_bid_order_ids( int $auction_id, int $limit )`
Returns an array of Bid Order IDs for the given Auction ID. `$limit` can be specified to return a set number of orders.

`goodbids()->auctions->get_bid_orders( int $auction_id, int $limit )`
Returns an array of Bid Orders for the given Auction ID. `$limit` can be specified to return a set number of orders.

`goodbids()->auctions->get_bid_order( int $auction_id, int $limit )`
Returns an array of Bid Order objects for the given Auction ID. `$limit` can be specified to return a set number of orders.

`goodbids()->auctions->get_last_bid( int $auction_id )`
Returns the Bid Order object of the last bid for the given Auction ID.

`goodbids()->auctions->get_last_bidder( int $auction_id )`
Returns the User object that placed the last bid.

`goodbids()->auctions->get_bid_count( int $auction_id )`
Get the number of bids for the given Auction ID.

`goodbids()->auctions->get_status( int $auction_id )`
Returns the status of the Auction. Possible values are: "Upcoming", "Live", and "Closed". If the Auction has not yet been published, it will return "Draft".

Expand All @@ -125,8 +149,50 @@ Get the location of a block. Return values can be: "directory" (Default) or "jso
`goodbids()->acf->blocks()->get_block_locations()`
Get all directories where blocks can be found.


### WooCommerce Functions

`goodbids()->woocommerce->get_order_auction_id( int $order_id)`
Get the Auction ID for the given Order ID. If `$order_id` is not provided, the current order ID will be used.
`goodbids()->woocommerce->get_order_auction_info( int $order_id )`
Returns an array of information for the given Order ID, including the Auction ID (`auction_id`) and Order Type (`order_type`).

`goodbids()->woocommerce->get_order_auction_id( int $order_id )`
Returns the Auction ID for the given Order ID. If `$order_id` is not provided, the current order ID will be used.

`goodbids()->woocommerce->get_order_type( int $order_id )`
Returns the type of the given order ID. Possible types are: "bids", "rewards", or null.

`goodbids()->woocommerce->is_bid_order( int $order_id )`
Checks if the given order ID is a Bid Order.

`goodbids()->woocommerce->is_reward_order( int $order_id )`
Checks if the given order ID is a Reward Order.

### Auctioneer Functions

`goodbids()->auctioneer->request( string $endpoint, array $data, string $method )`
Makes a request to the Auctioneer API.

`goodbids()->auctioneer->get_last_response()`
Returns the last response from the Auctioneer API.

`goodbids()->auctioneer->is_invalid_response( mixed $response )`
Checks if the API response is valid.

`goodbids()->auctioneer->get_response_json( array $response )`
Returns the API response body data as an associative array.

`goodbids()->auctioneer->get_response_message( array $response )`
Retrieves the formatted response message from the API response body.

`goodbids()->auctioneer->get_response_message_raw( array $response )`
Retrieves the raw response message from the API response body.

### Auctioneer: Auction (Endpoint) Functions

`goodbids()->auctioneer->auctions->start( int $auction_id )`
Signals to the Auctioneer API that the Auction has started.

`goodbids()->auctioneer->auctions->update( int $auction_id, string $context )`
Sends an update to the Auctioneer API. The context provided should identify the purpose of the update and will be pre-pended with `update:` before requesting the payload.

`goodbids()->auctioneer->auctions->end( int $auction_id )`
Signals to the Auctioneer API that the Auction has ended.
119 changes: 116 additions & 3 deletions client-mu-plugins/goodbids/acf-json/group_6570c1fa76181.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
"key": "group_6570c1fa76181",
"title": "Auction Settings",
"fields": [
{
"key": "field_65859b2a3eb25",
"label": "1. Schedule *",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "left",
"endpoint": 0
},
{
"key": "field_6570c1fb429a8",
"label": "Auction Start",
Expand All @@ -16,7 +33,7 @@
"class": "",
"id": ""
},
"display_format": "m\/d\/Y g:i a",
"display_format": "m\/d\/Y g:i:s a",
"return_format": "Y-m-d H:i:s",
"first_day": 0
},
Expand All @@ -34,10 +51,89 @@
"class": "",
"id": ""
},
"display_format": "m\/d\/Y g:i a",
"display_format": "m\/d\/Y g:i:s a",
"return_format": "Y-m-d H:i:s",
"first_day": 0
},
{
"key": "field_65859b4a3eb26",
"label": "Bid Extension",
"name": "bid_extension",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_65859b5f3eb27",
"label": "Minutes",
"name": "minutes",
"aria-label": "",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "50",
"class": "",
"id": ""
},
"default_value": "",
"min": "",
"max": "",
"placeholder": "",
"step": "",
"prepend": "",
"append": ""
},
{
"key": "field_65859b753eb28",
"label": "Seconds",
"name": "seconds",
"aria-label": "",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "50",
"class": "",
"id": ""
},
"default_value": 0,
"min": "",
"max": "",
"placeholder": "",
"step": "",
"prepend": "",
"append": ""
}
]
},
{
"key": "field_65859ba03eb29",
"label": "2. Reward *",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "left",
"endpoint": 0
},
{
"key": "field_657334958904f",
"label": "Auction Product",
Expand Down Expand Up @@ -90,6 +186,23 @@
"prepend": "$",
"append": ".00"
},
{
"key": "field_65859bbb3eb2a",
"label": "3. Bids *",
"name": "",
"aria-label": "",
"type": "tab",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"placement": "left",
"endpoint": 0
},
{
"key": "field_657334728904e",
"label": "Bid Increment",
Expand Down Expand Up @@ -197,6 +310,6 @@
"active": true,
"description": "",
"show_in_rest": 0,
"modified": 1703027242,
"modified": 1703701540,
"private": true
}
32 changes: 32 additions & 0 deletions client-mu-plugins/goodbids/blocks/bid-now/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,36 @@ public function get_button_url(): string {
public function get_block_classes(): string {
return 'wp-block-buttons is-vertical is-content-justification-center is-layout-flex wp-block-buttons-is-layout-flex';
}

/**
* Determine if Auction is active.
*
* @since 1.0.0
*
* @return bool
*/
public function is_auction_active(): bool {
if ( ! goodbids()->auctions->has_started( $this->auction_id ) ) {
return false;
}

if ( goodbids()->auctions->has_ended( $this->auction_id ) ) {
return false;
}

return true;
}

/**
* Display a message when auction is not active.
*
* @since 1.0.0
* @return void
*/
public function render_auction_not_active(): void {
printf(
'<p>%s</p>',
esc_html__( 'Auction is currently not active.', 'goodbids' )
);
}
}
8 changes: 7 additions & 1 deletion client-mu-plugins/goodbids/blocks/bid-now/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@

$bid_now = new GoodBids\Blocks\BidNow( $block );

// Bail early if we're not inside an Auction post type.
// Bail early if initial requirements are not met.
if ( ! $bid_now->display() ) :
return;
endif;

// Make sure the auction is active.
if ( ! $bid_now->is_auction_active() ) :
$bid_now->render_auction_not_active();
return;
endif;
?>
<div <?php block_attr( $block, $bid_now->get_block_classes() ); ?>>
<a
Expand Down
Loading

0 comments on commit 815adb5

Please sign in to comment.