Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#39] Auction index #103

Merged
merged 8 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the update to your Auction page PR, this is a great example of when we would need to pass the ID into the method. 👍

$product = wc_get_product( $reward_id );
$image_html = $product->get_image();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$image_html = $product->get_image();
return $product->get_image();

I can't remember if the sprintf was doing something before, but if we no longer have anything to pass into the $image_html var, this can go ahead and return here.

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,
]
Comment on lines -58 to 71
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moves this from the theme pattern into the plugin pattern

);

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
update_option(
update_option( 'posts_per_page', 9 );

Very minor, but I usually only break things up into multiple lines if there easier to read. In this case, it might easier to keep this on 1 line since it's a pretty simple bit of code.

'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
*/
?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
?>
?>

Just need to add a line here.


<!-- 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"} /-->