Skip to content

Commit

Permalink
[#823] Make sure Bid increments correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
bd-viget committed Mar 22, 2024
1 parent 92aa8c1 commit 77bd93a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions client-mu-plugins/goodbids/src/classes/Auctions/Auction.php
Original file line number Diff line number Diff line change
Expand Up @@ -1329,16 +1329,26 @@ public function extend(): bool {
public function increase_bid(): bool {
$bids = goodbids()->bids; // Easier to reference.

$bid_product = $bids->get_product( $this->get_id() );
$bid_variation = $bids->get_variation( $this->get_id() );
$bid_product = $bids->get_product( $this->get_id() );

if ( ! $bid_product || ! $bid_variation ) {
Log::error( 'Auction missing Bid Product or Variation', compact( 'this' ) );
if ( ! $bid_product ) {
Log::error( 'Auction missing Bid Product', [ 'auction' => $this->get_id() ] );
return false;
}

$bid_variation = $bids->get_variation( $this->get_id() );

if ( $bid_variation ) {
$current_price = floatval( $bid_variation->get_price( 'edit' ) );

// Disallow backorders on previous variation.
$bid_variation->set_backorders( 'no' );
$bid_variation->save();
} else {
$current_price = $this->get_last_bid_value();
}

$increment_amount = $this->get_bid_increment();
$current_price = floatval( $bid_variation->get_regular_price( 'edit' ) );
$new_price = $current_price + $increment_amount;

// Add support for new variation.
Expand All @@ -1355,10 +1365,6 @@ public function increase_bid(): bool {
// Set the Bid variation as a meta of the Auction.
$this->set_bid_variation_id( $new_variation->get_id() );

// Disallow backorders on previous variation.
$bid_variation->set_backorders( 'no' );
$bid_variation->save();

return true;
}

Expand Down

0 comments on commit 77bd93a

Please sign in to comment.