Reserve Price HOWTO

A place to discuss and receive support for the Web Auction application.

Reserve Price HOWTO

Postby rosekolodny » Thu Feb 12, 2009 3:52 pm

These are the steps I've taken to get a reserve price working in my auction. I'd love some feedback.


FIRST - back everything up! : )

OK - for starters you need a field in your product table named reserve_price (rather self-explanatory), and one in your config table called reserve_not_met. It's just like your custom winner notification email text. Now, go to your includes/functions.inc.php and find the function closeAuction(). Add this line among the other ones that look like it.

Code: Select all
$reserve = $product->val('reserve_price');


Now we have a variable to compare to another variable you see there, $amount. What we're going to do is state that if $amount is less than $reserve, an email will be sent to the high bidder (as of the close of the auction), to let that person know that the reserve price was not met, so nobody won. If $amount is greater than or equal to $reserve, the regular winner email is sent out. I have also changed the admin notification emails. If you scoot down to the bottom of closeAuction(), you will see a block that looks like this:

Code: Select all
if ( !$closeRec->val('email_sent') ){
   
      if ( sendEmail($mail, 'Action Required: You have Won the auction', getAuctionWinnerMessage($closeRec)) ){
      
         $closeRec->setValue('email_sent',1);
      } else {
         return PEAR::raiseError("Failed to send auction win confirmation to winner because of an email error.");
         
      }
   
   }


if ( !$closeRec->val('admin_email_sent') ){
   if( $amount < $reserve ){
      if ( sendAdminEmail('Notification: Auction closed & winner notified', "The auction for product '".$product->getTitle()."' has been won by the user '$username'. \n\nThis user has been notified via email and has been given instructions for claiming his prize.  For more information about the product, see ".$product->getURL('-action=view').".  For user details about the winner, see ".$user->getURL('-action=view'))){
         $closeRec->setValue('admin_email_sent', 1);
      } else {
         $closeRec->save();
         return PEAR::raiseError("Failed to send email confirmation to admin about the winner.  No action required though, because the email was successfully sent to the user.");   
      }
   }


Here's the new code. I would comment out the old code instead of replacing it outright. That way it's easy to restore to original.


Code: Select all
if ( !$closeRec->val('email_sent') ){
      if ( $amount < $reserve ){
         if ( sendEmail($mail, 'Auction Ended; Reserve Not Met', getReserveNotMetMessage($closeRec)) ){
         $closeRec->setValue('email_sent',1);
      } else {
         return PEAR::raiseError("Failed to send auction win confirmation to winner because of an email error.");
         }
      }

      if ( $amount >= $reserve ){
         if ( sendEmail($mail, 'Action Required: You have Won the auction', getAuctionWinnerMessage($closeRec)) ){
         $closeRec->setValue('email_sent',1);
      } else {
         return PEAR::raiseError("Failed to send auction win confirmation to winner because of an email error.");
         }
      }
   }

if ( !$closeRec->val('admin_email_sent') ){

   if( $amount < $reserve ){
      if ( sendAdminEmail('Auction Closed - Reserve Not Met', "The auction for product '".$product->getTitle()."' is over. '$username' was the highest bidder. \n\nThis user has been notified via email.  For more information about the product, see ".$product->getURL('-action=view').".  For user details, see ".$user->getURL('-action=view'))){
         $closeRec->setValue('admin_email_sent', 1);
      } else {
         $closeRec->save();
         return PEAR::raiseError("Failed to send email confirmation to admin about the winner.  No action required though, because the email was successfully sent to the user.");   
      }
   }
   
if ( $amount >= $reserve ) {
   if ( sendAdminEmail('Notification: Auction closed & winner notified', "The auction for product '".$product->getTitle()."' has been won by the user '$username'. \n\nThis user has been notified via email and has been given instructions for claiming his prize.  For more information about the product, see ".$product->getURL('-action=view').".  For user details about the winner, see ".$user->getURL('-action=view'))){
         $closeRec->setValue('admin_email_sent', 1);
      } else {
         $closeRec->save();
         return PEAR::raiseError("Failed to send email confirmation to admin about the winner.  No action required though, because the email was successfully sent to the user.");   
      }
   }
}



Almost done. The email that we send to the user is actually referenced in a different place in this same file. I copied and pasted the original, getAuctionWinnerMessage() and called the new one getReserveNotMetMessage(). Then I made some small changes, including the inclusion of our custom message field. Add this to your includes/functions.inc.php file. I stuck mine right next to the original one, so it would be easy to find. Silly me!
Code: Select all
function getReserveNotMetMessage($closeRec){
   $product =& df_get_record('products', array('product_id'=>$closeRec->val('product_id')));
   $product_url = $product->getURL('-action=view');
   $product_title = $product->getTitle();
   $bid_amount = '$'.number_format($closeRec->val('bid_amount'),2);
   $reserve_not_met = getConf('reserve_not_met');
   
   return <<<END
The reserve in the auction for '$product_title' was not met.  Your bid for $bid_amount was the highest, but nobody won.
For more information about this product visit $product_url .

$reserve_not_met
END;
   

}



Things that still need to be done:

1. Make the reports show whether or not the reserve was met.

2. Define a reserve_price__permissions() method in the products delegate class to allow all access to admins and no access otherwise.


And keep a backup of all your files. What if I'm wrong?

Beth
rosekolodny
 
Posts: 9
Joined: Sat Feb 07, 2009 11:25 pm

Return to Web Auction Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved