Skip to content

Commit

Permalink
Merge branch 'main' into bd/25-dynamic-bid-pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
bd-viget committed Dec 19, 2023
2 parents 27d0354 + 8ae1471 commit cd9cf2f
Show file tree
Hide file tree
Showing 17 changed files with 496 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Displays a user login and registration form for GoodBids.",
"icon": "feedback",
"category": "goodbids",
"textdomain": "goodbids",
"keywords": ["custom", "sign", "up", "register", "registration", "form", "users", "authentication"],
"acf": {
"mode": "preview"
Expand Down
1 change: 1 addition & 0 deletions client-mu-plugins/goodbids/blocks/bid-now/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Displays a bid now button for the current Auction.",
"icon": "money-alt",
"category": "goodbids",
"textdomain": "goodbids",
"keywords": ["bid", "purchase", "donate", "button", "submit", "cart"],
"acf": {
"mode": "preview"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "reward-product-gallery",
"title": "Reward Product Gallery",
"description": "Displays the reward product gallery images",
"icon": "format-gallery",
"category": "goodbids",
"textdomain": "goodbids",
"keywords": ["custom", "gallery", "product", "reward", "auction"],
"acf": {
"mode": "preview"
},
"supports": {
"jsx": false
}
}
29 changes: 29 additions & 0 deletions client-mu-plugins/goodbids/blocks/reward-product-gallery/block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Initialize the WooCommerce Gallery Script
*
* @since 1.0.0
*
* @return void
*/


add_action(
'wp_enqueue_scripts',
function () {
if ( is_singular( 'gb-auction' ) ) {
if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) {
wp_enqueue_script( 'zoom' );
}
if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
wp_enqueue_script( 'flexslider' );
}
if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
wp_enqueue_script( 'photoswipe-ui-default' );
wp_enqueue_style( 'photoswipe-default-skin' );
add_action( 'wp_footer', 'woocommerce_photoswipe' );
}
wp_enqueue_script( 'wc-single-product' );
}
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Block: Reward Product Gallery
*
* @global array $block
*
* @since 1.0.0
* @package GoodBids
*/

global $product;
$reward_id = goodbids()->auctions->get_reward_product_id( goodbids()->auctions->get_auction_id() );
$reward = wc_get_product( $reward_id );
if ( $reward ) {
$product = $reward;
}
?>


<section <?php block_attr( $block ); ?>>
<?php
if ( $product ) {
wc_get_template( 'single-product/product-image.php' );
} else {
printf(
'<p style="text-align: center;">%s</p>',
esc_html__( 'No Auction Product selected', 'goodbids' )
);
}
?>
</section>
15 changes: 15 additions & 0 deletions client-mu-plugins/goodbids/blocks/reward-product/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "reward-product",
"title": "Reward Product",
"description": "Displays the reward product information",
"icon": "awards",
"category": "goodbids",
"textdomain": "goodbids",
"keywords": ["custom", "product", "reward", "auction"],
"acf": {
"mode": "preview"
},
"supports": {
"jsx": false
}
}
43 changes: 43 additions & 0 deletions client-mu-plugins/goodbids/blocks/reward-product/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Block: Reward Product
*
* @global array $block
*
* @since 1.0.0
* @package GoodBids
*/

$goal = goodbids()->auctions->get_goal( goodbids()->auctions->get_auction_id() );
$estimated_value = goodbids()->auctions->get_estimated_value( $auction_id );
$expected_high_bid = goodbids()->auctions->get_expected_high_bid( $auction_id );
?>


<section <?php block_attr( $block ); ?>>
<?php
// Goal
if ( $goal ) {
printf(
'<p style="text-align: center;">%s</p>',
esc_html__( $goal, 'goodbids' )
);
}

// Estimated Value
if ( $estimated_value ) {
printf(
'<p style="text-align: center;">%s</p>',
esc_html__( $estimated_value, 'goodbids' )
);
}

// Expected High Bid
if ( $expected_high_bid ) {
printf(
'<p style="text-align: center;">%s</p>',
esc_html__( $expected_high_bid, 'goodbids' )
);
}
?>
</section>
60 changes: 47 additions & 13 deletions client-mu-plugins/goodbids/src/classes/Auctions/Auctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public function __construct() {

// Clear metric transients on new Bid Order.
$this->maybe_clear_metric_transients();

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

/**
Expand Down Expand Up @@ -133,7 +136,7 @@ function () {
'label' => __( 'Auction', 'goodbids' ),
'description' => __( 'GoodBids Auction Custom Post Type', 'goodbids' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'revisions' ),
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'revisions' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
Expand Down Expand Up @@ -170,7 +173,10 @@ private function get_template(): array {
'woocommerce_auction_default_template',
[
[
'acf/bid-now',
'core/pattern',
[
'slug' => 'goodbids/template-auction',
],
],
]
);
Expand All @@ -183,7 +189,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 @@ -192,6 +198,7 @@ function () {
);
}


/**
* Returns the Auction post type slug.
*
Expand All @@ -210,7 +217,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'] ) ) { // phpcs:ignore
Expand All @@ -231,7 +238,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 @@ -294,14 +301,14 @@ 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
*/
public function get_setting( string $meta_key, int $auction_id = null ): mixed {
if ( ! $auction_id ) {
$auction_id = get_the_ID();
if ( null === $auction_id ) {
$auction_id = $this->get_auction_id();
}

return get_field( $meta_key, $auction_id );
Expand All @@ -316,7 +323,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 @@ -329,7 +336,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 @@ -386,7 +393,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 @@ -430,7 +437,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 @@ -797,4 +804,31 @@ function ( $column, $post_id ) {
2
);
}

/**
* 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
);
}
}
8 changes: 8 additions & 0 deletions client-mu-plugins/goodbids/src/classes/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use GoodBids\Admin\Admin;
use GoodBids\Auctions\Auctions;
use GoodBids\Frontend\Patterns;
use GoodBids\Network\Sites;
use GoodBids\Plugins\ACF;
use GoodBids\Plugins\WooCommerce;
Expand Down Expand Up @@ -67,6 +68,12 @@ class Core {
*/
public WooCommerce $woocommerce;

/**
* @since 1.0.0
* @var Patterns
*/
public Patterns $patterns;

/**
* Constructor
*
Expand Down Expand Up @@ -224,6 +231,7 @@ function () {
$this->admin = new Admin();
$this->auctions = new Auctions();
$this->woocommerce = new WooCommerce();
$this->patterns = new Patterns();
}
);
}
Expand Down
Loading

0 comments on commit cd9cf2f

Please sign in to comment.