Skip to content

Commit

Permalink
Placing Bids (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
bd-viget authored Dec 18, 2023
1 parent 421f2c6 commit 6e9a12c
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 4 deletions.
5 changes: 4 additions & 1 deletion client-mu-plugins/goodbids/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ Renders an admin field based on the given field array. The `$prefix` and `$data`
### Auction Functions

`goodbids()->auctions->get_post_type()`
Returns the auction post type slug.
Returns the Auction post type slug.

`goodbids()->auctions->get_auction_id()`
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.
Expand Down
4 changes: 2 additions & 2 deletions client-mu-plugins/goodbids/acf-json/group_6570c1fa76181.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"taxonomy": [
"product_cat:rewards"
],
"return_format": "object",
"return_format": "id",
"multiple": 0,
"allow_null": 0,
"bidirectional": 0,
Expand Down Expand Up @@ -179,6 +179,6 @@
"active": true,
"description": "",
"show_in_rest": 0,
"modified": 1702493167,
"modified": 1702659886,
"private": true
}
14 changes: 14 additions & 0 deletions client-mu-plugins/goodbids/blocks/bid-now/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "bid-now",
"title": "Bid Now Button",
"description": "Displays a bid now button for the current Auction.",
"icon": "money-alt",
"category": "goodbids",
"keywords": ["bid", "purchase", "donate", "button", "submit", "cart"],
"acf": {
"mode": "preview"
},
"supports": {
"jsx": false
}
}
28 changes: 28 additions & 0 deletions client-mu-plugins/goodbids/blocks/bid-now/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Block: Bid Now
*
* @global array $block
*
* @since 1.0.0
* @package GoodBids
*/

if ( ! is_admin() && goodbids()->auctions->get_post_type() !== get_post_type() ) :
// Bail early if we're not inside an Auction post type.
return;
endif;

$auction_id = goodbids()->auctions->get_auction_id();
$bid_product_id = goodbids()->auctions->get_bid_product_id( $auction_id );

$classes = 'wp-block-buttons is-vertical is-content-justification-center is-layout-flex wp-block-buttons-is-layout-flex';
$button_url = $bid_product_id && ! is_admin() ? add_query_arg( 'add-to-cart', $bid_product_id, wc_get_checkout_url() ) : '#';
?>
<div <?php block_attr( $block, $classes ); ?>>
<div class="wp-block-button has-custom-width wp-block-button__width-100">
<a href="<?php echo esc_url( $button_url ); ?>" class="wp-block-button__link wp-element-button">
<?php esc_html_e( 'Bid Now', 'goodbids' ); ?>
</a>
</div>
</div>
40 changes: 40 additions & 0 deletions client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,32 @@ function () {
'capability_type' => 'page',
'show_in_rest' => true,
'rest_base' => self::SINGULAR_SLUG,
'template' => $this->get_template(),
];

register_post_type( self::POST_TYPE, $args );
}
);
}

/**
* Get the default template for Auctions.
*
* @since 1.0.0
*
* @return array
*/
private function get_template(): array {
return apply_filters(
'woocommerce_auction_default_template',
[
[
'acf/bid-now',
],
]
);
}

/**
* Initialize Rewards Category
*
Expand Down Expand Up @@ -161,6 +180,27 @@ public function get_post_type(): string {
return self::POST_TYPE;
}

/**
* Returns the current Auction post ID.
*
* @since 1.0.0
*
* @return ?int
*/
public function get_auction_id() : ?int {
$auction_id = is_singular( $this->get_post_type() ) ? get_queried_object_id() : get_the_ID();

if ( ! $auction_id && is_admin() && ! empty( $_GET['post'] ) ) {
$auction_id = intval( sanitize_text_field( $_GET['post'] ) );
}

if ( $this->get_post_type() !== get_post_type( $auction_id ) ) {
return null;
}

return $auction_id;
}

/**
* Retrieve the Rewards category ID, or create it if it doesn't exist.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function get_all_blocks() : array {
$group = glob( trailingslashit( $location ) . '**/block.json' );

foreach ( $group as $block_path ) {
$block = json_decode( wpcom_vip_file_get_contents( $block_path ), true );
$block = json_decode( file_get_contents( $block_path ), true ); // phpcs:ignore

// Add path as a property.
$block['path'] = dirname( $block_path );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,5 @@ function () {
2
);
}

}

0 comments on commit 6e9a12c

Please sign in to comment.