Multiple Buy It Now Purchase Charge Fixed (Outstanding and Pay PHP)

Discussion in 'Modding/Theme Help' started by GCW2013, Mar 11, 2013.

  1. GCW2013

    GCW2013 New Member

    Joined:
    Mar 6, 2013
    Messages:
    49
    Likes Received:
    3
    So here's how I managed to sort out the problem with multiple purchases using the Buy It Now option.

    First off I'd like to give thanks and kudos to pani100 with his post, as I'd never have gotten this far as quick. After using his modifications I found that it gave the appearance of working but with page 1 was constantly bringing up the same price + quantity as the first item sold which wouldn't be a problem except for the fact that I created 4 other users to buy the same item and they too, regardless of the quantity purchased were charged the same amount as the original first purchase. So I implemented the second page of code which once modified redirected me to the outstanding.php script.

    So with in mind that the first lot of script was asking every user to pay the price of the first sale I realised that the script was only calling up the fist sale of the particular auction ID regardless of the buyer so after around 20 hours of trial and error with the code I finally found a solution.

    So to make a long story not so long here's what to do: -

    First we make the changes pani100 suggested all in one go:

    Go to pay.php and find:
    PHP:
    case 2// pay for an item 
        
    $query "SELECT w.id, a.title, a.shipping_cost, a.shipping, w.bid, u.paypal_email, u.authnet_id, u.authnet_pass, 
                    u.id As uid, u.nick, a.payment, u.worldpay_id, u.toocheckout_id, u.moneybookers_email  
    And replace with:
    PHP:
    case 2// pay for an item 
            
    $query "SELECT w.id, a.title, a.shipping_cost, a.shipping, w.bid, w.qty, u.paypal_email, u.authnet_id, u.authnet_pass, 
                    u.id As uid, u.nick, a.payment, u.worldpay_id, u.toocheckout_id, u.moneybookers_email  
    Then find:
    PHP:
    $payvalue = ($data['shipping'] == 1) ? $data['shipping_cost'] + $data['bid'] : $data['bid']; 
    And replace with:
    PHP:
    $payvalue = ($data['shipping'] == 1) ? $data['shipping_cost'] + ($data['bid']* $data['qty']) : ($data['bid']* $data['qty']); 
    Then find:
    PHP:
    $payvalue = ($data['shipping'] == 1) ? $data['shipping_cost'] + ($data['bid']* $data['qty']) : ($data['bid']* $data['qty']);  
    Underneath add:
    PHP:
    $payvalueperitem $data['bid']; 
    $shipping_cost = ($data['shipping'] == 1) ? $data['shipping_cost'] : '0'
    $item_quantity $data['qty'];
    Then find:
    PHP:
    // paypal 
            
    'PP_PAYTOEMAIL' => $pp_paytoemail
    Underneath add:
    PHP:
      'PAYVALUEPERITEM' => $payvalueperitem
            
    'SHIPPING_COST' => $system->print_money_nosymbol($shipping_cost), 
                    
    'ITEM_QUANTITY' => $item_quantity,
    Then find:
    PHP:
            $payvalue = ($data['shipping'] == 1) ? $data['shipping_cost'] + $data['bid'] : $data['bid'];
            
    $custoncode $data['id'] . 'WEBID2';
            
    $message sprintf($MSG['581'], $system->print_money($payvalue));
            
    $title $system->SETTINGS['sitename'] . ' - ' $data['title'];
            break;
    And replace with:
    PHP:
            $payvalue = ($data['shipping'] == 1) ? $data['shipping_cost'] + ($data['bid']* $data['qty']) : ($data['bid']* $data['qty']);
        
    $payvalueperitem $data['bid']; 
            
    $paysubtotal = ($data['bid']* $data['qty']); 
            
    $shipping_cost = ($data['shipping'] == 1) ? $data['shipping_cost'] : '0'
            
    $custoncode $data['id'] . 'WEBID2'
            
    $item_quantity $data['qty']; 
            
    $message sprintf($MSG['581'], $system->print_money($payvalue)); 
            
    $title $system->SETTINGS['sitename'] . ' - ' $data['title']; 
            
    $sale intval($_POST['pfwon']); 
                   break;
    Finally find:
    PHP:
    'B_TOUSER' => ($_GET['a'] == 2)
    And replace with:
    PHP:
    'B_TOUSER' => ($_GET['a'] == 2),
        
    'BIDSINGLE' => $data['bid'], 
            
    'BIDSQTY' => $data['qty'], 
            
    'SALE' => $sale
            
    'SUBTOTAL' => $paysubtotal
            
    ));
    Save and close.


    Go to outstanding.php

    Then change the $query to:
    PHP:
    $query "SELECT w.auction As id, w.id As winid, a.title, a.shipping_cost, w.bid, w.qty, w.closingdate FROM " $DBPrefix "winners w
    And change the while ($row = mysql_fetch_assoc($res)) to:
    PHP:
    while ($row mysql_fetch_assoc($res)) 

         
    $DATE $row['closingdate'] + $system->tdiff
        
    $template->assign_block_vars('to_pay', array( 
                
    'URL' => $system->SETTINGS['siteurl'] . 'item.php?id=' $row['id'], 
                
    'TITLE' => $row['title'], 
                
    'SHIPPING' => $system->print_money($row['shipping_cost']), 
                
    'BID' => $system->print_money($row['bid'] * $row['qty']), 
                
    'TOTAL' => $system->print_money($row['shipping_cost'] + ($row['bid'] * $row['qty'])), 
                
    'ID' => $row['id'], 
                
    'QUANTITY' => $row['qty'], 
                            
    'WINID'=> $row['winid'], 
                
    'CLOSINGDATE' => gmdate('d/m/Y'$DATE), 
                
    'B_NOTITLE' => (empty($row['title'])) 
                )); 
    }
    Save and close

    Open pay.tpl (/themes/default/pay.tpl)

    Find:
    PHP:
    <input type="hidden" name="amount" value="{PAY_VAL}">
    And Replace With:
    PHP:
    <input type="hidden" name="amount" value="{PAYVALUEPERITEM}">
    Find:
    PHP:
    <input type="hidden" name="undefined_quantity" value="0">
    And Underneath Place:
    PHP:
    <input type="hidden" name="quantity" value="{ITEM_QUANTITY}">
    Find:
    PHP:
    <input type="hidden" name="no_shipping" value="1">
    And Underneath Place:
    PHP:
    <input type="hidden" name="shipping" value="{SHIPPING_COST}">
    Save and close.

    There were a couple of other codes after this but they were just for aesthetic purposes and irrelevant

    Now if you test the above, if like mine it should persistently redirect you back to the outstanding.php script which would show the correct amount to pay but when you click on pay would only redirect you to the outstanding.php page.

    This is how I finally sorted that problem:

    Go back to pay.php

    Find:
    PHP:
    WHERE a.id " . intval($_POST['pfval']);
    And replace with:
    PHP:
    WHERE w.paid AND w.winner " . $user->user_data['id'] . " AND                
                     
    a.id " . intval($_POST['pfval']);
    And that's that. As far as I can tell that works beautifully but not perfectly. If it is the same buyer buying the exact same item from the exact same seller it will still ask for the first payment first BUT it won't charge EVERY buyer the same price as the first sale, it won't keep bringing you back to the outstanding page and it will include quantities and shipping costs.

    I will keep working on a fix for it to charge all of one seller's items at once.
     
    Last edited: Mar 14, 2013
  2. liran

    liran New Member

    Joined:
    May 17, 2012
    Messages:
    136
    Likes Received:
    2
    just wanted to point out again on the bug of multi buy when your selling lets say 5 pcs and somone buys the last then the auction wont dissapear . and when you will try and enter it you'll see the (somone has bidded more than you message).
     
  3. GCW2013

    GCW2013 New Member

    Joined:
    Mar 6, 2013
    Messages:
    49
    Likes Received:
    3
    I don't have a proper fix for that yet but I do have a 'work-around' which will close the listing if all the items are bought and charge the correct amount based on quantity ordered. The only problem with this work-around is it only shows the buyer as buying a single item at the price of however many items (quantity) were ordered and it still shows the user as being outbid for some reason. I'm still working on it though.

    Go to buy_now.php and find
    PHP:
    if ($Auction['quantity'] == 1
            {                            
                
    $query "UPDATE " $DBPrefix "auctions SET ends = '" $NOW "', num_bids = num_bids + 1, current_bid = " floatval($Auction['buy_now']) . "
                        WHERE id = " 
    $id;
                
    $system->check_mysql(mysql_query($query), $query__LINE____FILE__);
                
    $query "UPDATE " $DBPrefix "counters SET bids = bids + 1";
                
    $system->check_mysql(mysql_query($query), $query__LINE____FILE__);
                
    // so its not over written by the cron
                
    $tmpauc $Auction;
                include 
    'cron.php';
                
    $Auction $tmpauc;
                unset(
    $tmpauc);
            }
    Underneath that add:
    PHP:
    elseif (isset($qty) && $qty == $Auction['quantity']) 
            {                            
                
    $query "UPDATE " $DBPrefix "auctions SET ends = '" $NOW "', num_bids = num_bids + 1, current_bid = " floatval($Auction['buy_now'] * $Auction['quantity']) . "
                        WHERE id = " 
    $id;
                
    $system->check_mysql(mysql_query($query), $query__LINE____FILE__);
          
    $query "UPDATE " $DBPrefix "auctions SET quantity = quantity - " $qty " WHERE id = " $id;
                
    $system->check_mysql(mysql_query($query), $query__LINE____FILE__);
                
    $query "UPDATE " $DBPrefix "counters SET bids = bids + 1";
                
    $system->check_mysql(mysql_query($query), $query__LINE____FILE__);
                
    $tmpauc $Auction;
                include 
    'cron.php';
                
    $Auction $tmpauc;
                unset(
    $tmpauc);
            }
    Like I said it's not a perfect fix yet as the only way I could get the price to match the quantity bought was to use the code: $query = "UPDATE " . $DBPrefix . "auctions SET ends = '" . $NOW . "', num_bids = num_bids + 1, current_bid = " . floatval($Auction['buy_now'] * $Auction['quantity']) . " which multiplies the price by the auction quantity which shows as only 1 item being bought at the quantity price.

    I did move the code to underneath the //check quantity line which worked fine with pulling out the quantities, prices and even ending the auction, unfortunately though it stopped anyone from buying a single item in a single item listing and brought up an sql error.

    I still can't change the "you've been outbid text" I know it's something in the item.php file but not sure. I'll keep working and update when I know more.
     
    Last edited: Mar 14, 2013
  4. gceonline

    gceonline New Member

    Joined:
    Apr 25, 2013
    Messages:
    5
    Likes Received:
    0
    Dear GCW2013,
    please post complete modified files, I have tried to modify my own but it doesn't function :(
    I am very sorry for this bug...
    Thank you in advance
     
  5. GCW2013

    GCW2013 New Member

    Joined:
    Mar 6, 2013
    Messages:
    49
    Likes Received:
    3
    Sorry for the late response, I've been away for a couple of weeks. What is happening exactly when you say you can't get it to work? Have you tried to create a few different accounts and list a few different items at different prices to see if it works? It's not possible that with a new install of this script with my modifications that they can't be working the same as I have them currently working.
     

Share This Page