Skip to content

Commit

Permalink
[#39] Auction index (#103)
Browse files Browse the repository at this point in the history
* [#39] setting up archive page

* [#39] Setting default image for Auction index

* [#39] setting number of post per page on auction index

* [#39] adding auction archive page to nav

* [#39] pattern refactor to use plugin

* [#39] fixing PR edits

* [#39] removing page for menu

* [#39] updating default post per page
  • Loading branch information
nathan-schmidt-viget authored Dec 19, 2023
1 parent 0737f7e commit 7ccc537
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 38 deletions.
48 changes: 39 additions & 9 deletions client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function __construct() {

// Update Bid Product when Auction is updated.
$this->update_bid_product_on_auction_update();

// Sets a default image
$this->set_default_feature_image();
}

/**
Expand Down Expand Up @@ -160,7 +163,7 @@ private function get_template(): array {
*
* @return void
*/
private function init_rewards_category() : void {
private function init_rewards_category(): void {
add_action(
'init',
function () {
Expand All @@ -187,7 +190,7 @@ public function get_post_type(): string {
*
* @return ?int
*/
public function get_auction_id() : ?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'] ) ) {
Expand All @@ -208,7 +211,7 @@ public function get_auction_id() : ?int {
*
* @return ?int
*/
public function get_rewards_category_id() : ?int {
public function get_rewards_category_id(): ?int {
$rewards_category = get_term_by( 'slug', 'rewards', 'product_cat' );

if ( ! $rewards_category ) {
Expand Down Expand Up @@ -270,8 +273,8 @@ public function set_bid_product_id( int $auction_id, int $bid_product_id ): void
*
* @since 1.0.0
*
* @param string $meta_key
* @param ?int $auction_id
* @param string $meta_key
* @param ?int $auction_id
*
* @return mixed
*/
Expand All @@ -292,7 +295,7 @@ public function get_setting( string $meta_key, int $auction_id = null ): mixed {
*
* @return int
*/
public function get_reward_product_id( int $auction_id = null ) : int {
public function get_reward_product_id( int $auction_id = null ): int {
return intval( $this->get_setting( 'auction_product', $auction_id ) );
}

Expand All @@ -305,7 +308,7 @@ public function get_reward_product_id( int $auction_id = null ) : int {
*
* @return int
*/
public function get_estimated_value( int $auction_id = null ) : int {
public function get_estimated_value( int $auction_id = null ): int {
return intval( $this->get_setting( 'estimated_value', $auction_id ) );
}

Expand Down Expand Up @@ -362,7 +365,7 @@ public function get_bid_increment( int $auction_id = null ): int {
*
* @return int
*/
public function get_starting_bid( int $auction_id = null ) : int {
public function get_starting_bid( int $auction_id = null ): int {
return intval( $this->get_setting( 'starting_bid', $auction_id ) );
}

Expand Down Expand Up @@ -406,7 +409,7 @@ public function get_goal( int $auction_id = null ): int {
*
* @return int
*/
public function get_expected_high_bid( int $auction_id = null ) : int {
public function get_expected_high_bid( int $auction_id = null ): int {
return intval( $this->get_setting( 'expected_high_bid', $auction_id ) );
}

Expand Down Expand Up @@ -454,4 +457,31 @@ function ( int $post_id ) {
}
);
}

/**
* Set the default feature image for Auction
*
* @since 1.0.0
*
* @return void
*/
private function set_default_feature_image(): void {
add_filter(
'post_thumbnail_html',
function ( string $html, int $post_id ) {
if ( ! is_post_type_archive( $this->get_post_type() ) ) {
return $html;
}

$reward_id = goodbids()->auctions->get_reward_product_id( $post_id );
$product = wc_get_product( $reward_id );
$image_html = $product->get_image();
return sprintf(
$image_html,
);
},
10,
2
);
}
}
12 changes: 6 additions & 6 deletions client-mu-plugins/goodbids/src/classes/Frontend/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ function (): void {
]
);

$sample_pattern = [
'name' => 'sample-pattern',
'path' => GOODBIDS_PLUGIN_PATH . 'views/patterns/sample-pattern.php',
'title' => __( 'GoodBids Sample Pattern', 'goodbids' ),
$auction_archive = [
'name' => 'template-archive-auction',
'path' => GOODBIDS_PLUGIN_PATH . 'views/patterns/template-archive-auction.php',
'title' => __( 'Archive Auction', 'goodbids' ),
'categories' => [ 'goodbids' ],
'keywords' => [ 'example', 'template', 'demo' ],
'keywords' => [ 'non-profit', 'starter', 'archive' ],
'inserter' => true,
];

$this->patterns = apply_filters(
'goodbids_block_patterns',
[
$sample_pattern,
$auction_archive,
]
);

Expand Down
21 changes: 20 additions & 1 deletion client-mu-plugins/goodbids/src/classes/Network/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __construct() {
// New Site Actions
$this->activate_child_theme_on_new_site();
$this->default_child_theme_logo();
$this->set_default_posts_per_page();
}

/**
Expand Down Expand Up @@ -323,7 +324,6 @@ function ( WP_Site $new_site, array $args ) {
private function save_edit_site_fields(): void {
add_action(
'wp_update_site',

/**
* @param WP_Site $new_site New site object.
* @param WP_Site $old_site Old site object.
Expand Down Expand Up @@ -420,4 +420,23 @@ function ( string $html, int $blog_id ) {
2
);
}

/**
* Set the archive to show nine posts per pagination
*
* @since 1.0.0
*
* @return void
*/
private function set_default_posts_per_page(): void {
add_action(
'goodbids_init_site',
function ( int $site_id ): void {
update_option(
'posts_per_page',
9
);
}
);
}
}
22 changes: 0 additions & 22 deletions client-mu-plugins/goodbids/views/patterns/sample-pattern.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Pattern: Auction Archive
*
* @since 1.0.0
* @package GoodBids
*/
?>

<!-- wp:group {"tagName":"main","style":{"spacing":{"blockGap":"0","margin":{"top":"0"}}},"layout":{"type":"constrained","justifyContent":"left"}} -->
<main class="wp-block-group" style="margin-top:0">
<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:heading {"level":1,"style":{"typography":{"textTransform":"capitalize"}}} -->
<h1 class="wp-block-heading" style="text-transform:capitalize">
<?php esc_html_e( 'Our Auctions', 'goodbids-nonprofit' ); ?>
</h1>
<!-- /wp:heading -->

<!-- wp:query {"query":{"perPage":9,"pages":0,"offset":"0","postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true},"align":"wide","layout":{"type":"default"}} -->
<div class="wp-block-query alignwide">
<!-- wp:query-no-results -->
<!-- wp:pattern {"slug":"twentytwentyfour/hidden-no-results"} /-->
<!-- /wp:query-no-results -->

<!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|50","bottom":"var:preset|spacing|50","left":"0","right":"0"},"margin":{"top":"0","bottom":"0"}}},"layout":{"type":"default"}} -->
<div class="wp-block-group" style="margin-top:0;margin-bottom:0;padding-top:var(--wp--preset--spacing--50);padding-right:0;padding-bottom:var(--wp--preset--spacing--50);padding-left:0">

<!-- wp:post-template {"align":"full","style":{"spacing":{"blockGap":"var:preset|spacing|30"}},"layout":{"type":"grid","columnCount":3}} -->

<!-- wp:post-featured-image {"isLink":true,"aspectRatio":"1","style":{"spacing":{"margin":{"bottom":"0"},"padding":{"bottom":"var:preset|spacing|20"}}}} /-->

<!-- wp:group {"style":{"spacing":{"blockGap":"10px","margin":{"top":"var:preset|spacing|20"},"padding":{"top":"0"}}},"layout":{"type":"flex","orientation":"vertical","flexWrap":"nowrap"}} -->
<div class="wp-block-group" style="margin-top:var(--wp--preset--spacing--20);padding-top:0">
<!-- wp:post-title {"isLink":true,"style":{"layout":{"flexSize":"min(2.5rem, 3vw)","selfStretch":"fixed"}},"fontSize":"large"} /-->

<!-- wp:spacer {"height":"0px","style":{"layout":{"flexSize":"min(1.5rem, 3vw)","selfStretch":"fixed"}}} -->
<div style="height:0px" aria-hidden="true" class="wp-block-spacer">
</div>
<!-- /wp:spacer -->
</div>
<!-- /wp:group -->

<!-- /wp:post-template -->

<!-- wp:spacer {"height":"var:preset|spacing|40","style":{"spacing":{"margin":{"top":"0","bottom":"0"}}}} -->
<div style="margin-top:0;margin-bottom:0;height:var(--wp--preset--spacing--40)" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->

<!-- wp:query-pagination {"paginationArrow":"arrow","layout":{"type":"flex","justifyContent":"space-between"}} -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->

</div>
<!-- /wp:group -->
</div>
<!-- /wp:query -->
</main>
<!-- /wp:group -->
3 changes: 3 additions & 0 deletions themes/goodbids-nonprofit/templates/archive-gb-auction.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:template-part {"slug":"header","area":"header","tagName":"header"} /-->
<!-- wp:pattern {"slug":"goodbids/template-archive-auction"} /-->
<!-- wp:template-part {"slug":"footer","area":"footer","tagName":"footer"} /-->

0 comments on commit 7ccc537

Please sign in to comment.