Skip to content

Commit

Permalink
[N/A] Auction Bug Fix / Delete User Scenario (#812)
Browse files Browse the repository at this point in the history
* [N/A] Get Product bug fix

* [N/A] Make sure the last order User is still valid

* [N/A] Get Last User ID method

* [N/A] Compare Last Bidder ID

* [N/A] Adjustments to Payload

* [N/A] Fixes New plugin references in config.json

* [N/A] Oops!
  • Loading branch information
bd-viget authored Mar 19, 2024
1 parent f7e5a9b commit 6c2bcca
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
4 changes: 2 additions & 2 deletions client-mu-plugins/goodbids/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"advanced-custom-fields-pro/acf.php",
"delete-me",
"miniorange-oauth-oidc-single-sign-on/mo_oauth_settings.php",
"tidio-live-chat",
"top-bar",
"tidio-live-chat/tidio-elements.php",
"top-bar/topbar.php",
"user-switching",
"wp-mail-smtp-pro/wp_mail_smtp.php",
"woocommerce",
Expand Down
31 changes: 25 additions & 6 deletions client-mu-plugins/goodbids/src/classes/Auctions/Auction.php
Original file line number Diff line number Diff line change
Expand Up @@ -1076,17 +1076,36 @@ public function get_last_bid(): ?WC_Order {
* @return ?WP_User
*/
public function get_last_bidder(): ?WP_User {
$last_bid = $this->get_last_bid();
$last_bidder_id = $this->get_last_bidder_id();

if ( ! $last_bid ) {
if ( ! $last_bidder_id ) {
return null;
}

if ( ! $last_bid->get_user() ) {
$last_bidder = get_user_by( 'ID', $last_bidder_id );

if ( ! $last_bidder ) {
return null;
}

return $last_bidder;
}

/**
* Get the ID of the user who is the last bidder.
*
* @since 1.0.0
*
* @return ?int
*/
public function get_last_bidder_id(): ?int {
$last_bid = $this->get_last_bid();

if ( ! $last_bid ) {
return null;
}

return $last_bid->get_user();
return $last_bid->get_user_id();
}

/**
Expand All @@ -1097,8 +1116,8 @@ public function get_last_bidder(): ?WP_User {
* @return bool
*/
public function is_current_user_winning(): bool {
$last_bidder = $this->get_last_bidder();
return $last_bidder?->ID === get_current_user_id();
$last_bidder_id = $this->get_last_bidder_id();
return $last_bidder_id === get_current_user_id();
}

/**
Expand Down
7 changes: 6 additions & 1 deletion client-mu-plugins/goodbids/src/classes/Auctions/Bids.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,12 @@ public function get_variation( int $auction_id ): ?WC_Product {
return null;
}

return wc_get_product( $bid_variation_id );
$product = wc_get_product( $bid_variation_id );
if ( ! $product ) {
return null;
}

return $product;
}

/**
Expand Down
35 changes: 29 additions & 6 deletions client-mu-plugins/goodbids/src/classes/Utilities/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ class Payload {
*/
private ?WC_Order $last_bid = null;

/**
* The Last Bidder User ID
*
* @since 1.0.0
* @var ?int
*/
private ?int $last_bidder_id = null;

/**
* The Last Bidder User object
*
Expand Down Expand Up @@ -217,7 +225,7 @@ private function get_payload_item( string $item ): mixed {
'freeBidsAllowed' => $this->auction->are_free_bids_allowed(),
'isLastBidder' => $this->is_user_last_bidder( $this->get_user_id() ),
'lastBid' => $this->get_last_bid_amount(),
'lastBidder' => $this->get_last_bidder(),
'lastBidder' => $this->get_last_bidder_id(),
'requestTime' => current_datetime()->format( 'c' ),
'rewardClaimed' => $this->has_user_claimed_reward(),
'rewardUrl' => goodbids()->rewards->get_claim_reward_url( $this->auction_id ),
Expand Down Expand Up @@ -294,12 +302,27 @@ private function get_last_bid_amount(): ?float {
*
* @return ?int
*/
private function get_last_bidder(): ?int {
private function get_last_bidder_id(): ?int {
if ( ! $this->last_bidder_id ) {
$this->last_bidder_id = $this->auction->get_last_bidder_id();
}

return $this->last_bidder_id;
}

/**
* Get the last bidder User object
*
* @since 1.0.0
*
* @return ?WP_User
*/
private function get_last_bidder(): ?WP_User {
if ( ! $this->last_bidder ) {
$this->last_bidder = $this->auction->get_last_bidder();
}

return $this->last_bidder?->ID;
return $this->last_bidder;
}

/**
Expand All @@ -312,11 +335,11 @@ private function get_last_bidder(): ?int {
* @return bool
*/
private function is_user_last_bidder( int $user_id ): bool {
if ( ! $this->last_bidder ) {
$this->last_bidder = $this->auction->get_last_bidder();
if ( ! $this->last_bidder_id ) {
$this->last_bidder_id = $this->auction->get_last_bidder_id();
}

return $this->last_bidder?->ID === $user_id;
return $this->last_bidder_id === $user_id;
}

/**
Expand Down

0 comments on commit 6c2bcca

Please sign in to comment.