SAME SITUATION as in 6.x-1.x. and posted here: http://drupal.org/node/1461508
Hi folks,
first my thanks to everybody, who has developed this module and to those who are maintaining it.
This is my first commit. I have never worked with GIT, so my patch comes pasted in here.
The Issue:
uc_auction_cart_item(): The implementation of hook_cart_item() is supposed to alter the price of a cart item, that are auctionated (with or without BuyNow-Feature).
This is function uc_auction_cart_item() as it is now:
function uc_auction_cart_item($op, &$item) {
if ($op === 'load') {
if ($info = db_fetch_array(db_query('SELECT ua.high_bid, uab.amount FROM {uc_auction} ua LEFT JOIN {uc_auction_bids} uab ON ua.high_bid = uab.bid WHERE ua.nid = %d', $item->nid))) {
$item->sell_price = $item->price;
if ($info['amount'] !== NULL) {
$item->price = floatval($info['amount']);
}
$item->is_auc = TRUE;
}
else {
$item->is_auc = FALSE;
}
}
}
Please note, that regardless the situation, whether the highest bidder has won or item was placed to cart by using the buynow-button. Due to that:
You can buy (with BuyNow) an item below the BuyNow-Price. The Startprice or the current bid will the prices, depending whether a bid has been placed.
This my suggestion:
function uc_auction_cart_item($op, &$item) {
if ($op == "load") {
// The ways how an Product with Auction or BuyNow can be put in the cart is, when:
// - Auction has expired and the highest bid has won
// - Auction not expired, BuyNow-Feature is enabled, and the item was put in the cart by using BuyNow-Button(Submit)
//
// uc_auction-Module only alters the price, when one of these cases occure.
// Check, whether the auction has ended.
$is_expired = db_result(db_query("SELECT expiry FROM uc_auction WHERE nid = '%d'", $item->nid));
$is_expired = (time() > $is_expired) ? TRUE : FALSE;
// Check, if Auction (and BuyNow-Feature) is enabled (Entry in this table in both cases)
$is_auction = db_fetch_array(db_query('SELECT ua.high_bid, uab.amount FROM {uc_auction} ua LEFT JOIN {uc_auction_bids} uab ON ua.high_bid = uab.bid WHERE ua.nid = %d', $item->nid));
if ($is_auction) {
// We make alterations on item-price only now
$highest_bid = ((int)$is_auction['amount'] > 0) ? floatval($is_auction['amount']) : NULL;
// Check, if the BuyNow-Feature is enabled?
$is_buynow = db_result(db_query("SELECT bought_now FROM uc_auction_now WHERE nid = '%d'", $item->nid));
$item->is_auc = TRUE;
if (is_numeric($is_buynow) AND !$is_expired) {
// Auction is still active. BuyNow will close the auction
$buynow_price = db_result(db_query("SELECT sell_price FROM uc_products WHERE nid = '%d'", $item->nid));
$item->price = floatval($buynow_price);
// Not sure about this line:
$item->sell_price = $item->price;
}
if ($is_auction AND $is_expired) {
// Auction closed and the item was put in the cart of the highest bidder
$item->price = floatval($is_auction['amount']);
// Not sure about this line:
$item->sell_price = 0;
}
} else {
// not our job!
$item->is_auc = FALSE;
}
return;
}Please report or confirm the error and test the code above.
Regards
Comments
Comment #0.0
HydroZ commented$item->sell_price needs to be set as in the current code...
Comment #1
HydroZ commentedComment #2
HydroZ commentedThe whole last day I spent my time on seeking for bugs and testing the above posted patch for
hook_cart_item()This function in uc_auction_now.module
would become obsolete with the above posted patch.
The test succeeded, but PLEASE do some testing by your own, because ubercart is very complex ;)...
This issues affects, and hopefully will fix because I assume they are both caused by inproper price alterations of hook_cart_item(), the issue posted here:
Buy Now very broken
Comment #2.0
HydroZ commentedFirst line added