i have some code that im editing for an auction website, the thing is that i need the $all_unpaid = false if the bid_amount is zero, I tried several tweaks but no results, perhaps some1 can have some suggestions?
function direct_payment_multiple ($invoice_id, $items_array, $dp_array, $buyer_id)
{
$output = false;
$nb_sub_arrays = count($dp_array);
if ($nb_sub_arrays)
{
$array_result = $dp_array[0];
for ($i=1; $i<$nb_sub_arrays; $i++)
{
$array_result = @array_intersect($array_result, $dp_array[$i]);
}
$all_unpaid = true;
for ($i=0; $i<$nb_sub_arrays; $i++)
{
$all_unpaid = (!$items_array[$i]['direct_payment_paid'] && !$items_array[$i]['flag_paid'] && $items_array[$i]['bid_amount'] > 0) ? $all_unpaid : false;
}
$same_currency = true;
$currency = $items_array[0]['currency'];
for ($i=0; $i<$nb_sub_arrays; $i++)
{
$same_currency = ($currency == $items_array[$i]['currency']) ? $same_currency : false;
}
}
$output = (is_array($array_result) && $all_unpaid) ? true : false;
return $output;
}
some overview, this auction website allows users to place a bid of 0.00, if no-one outbids them then they get the item for free, however if someone does outbid them then regular code applies
hey @TecBrat, i deleted this line
$all_unpaid = (!$items_array[$i]['direct_payment_paid'] && !$items_array[$i]['flag_paid'] && $items_array[$i]['bid_amount'] > 0) ? $all_unpaid : false;
and replaced it with this
$all_unpaid =true;
if ((!$items_array[$i]['direct_payment_paid'] && !$items_array[$i]['flag_paid'] )
|| !$items_array[$i]['bid_amount'] > 0)
{
$all_unpaid =false;
}
however it seems to do the same as b4
i changed it to this
$all_unpaid =true;
if (($items_array[$i]['direct_payment_paid'] || $items_array[$i]['flag_paid'] )
|| $items_array[$i]['bid_amount'] > 0)
{
$all_unpaid =false;
}
still appears to be the same as b4
currently this is what im working with
function direct_payment_multiple ($invoice_id, $items_array, $dp_array, $buyer_id)
{
$output = false;
$nb_sub_arrays = count($dp_array);
if ($nb_sub_arrays)
{
$array_result = $dp_array[0];
for ($i=1; $i<$nb_sub_arrays; $i++)
{
$array_result = @array_intersect($array_result, $dp_array[$i]);
}
$all_unpaid = true;
for ($i=0; $i<$nb_sub_arrays; $i++)
{
$all_unpaid =true; if (($items_array[$i]['direct_payment_paid'] || $items_array[$i]['flag_paid'] ) || $items_array[$i]['bid_amount'] > 0)
{
$all_unpaid =false;
}
}
$same_currency = true;
$currency = $items_array[0]['currency'];
for ($i=0; $i<$nb_sub_arrays; $i++)
{
$same_currency = ($currency == $items_array[$i]['currency']) ? $same_currency : false;
}
}
$output = (is_array($array_result) && $all_unpaid) ? true : false;
return $output;
}
this line:
is a good example of why I prefer this style:
I think I translated that correctly as
…
I tested this script at http://www.tecbrat.com/conditional_testing.php
Try it with a few different query strings to see what happens.
http://www.tecbrat.com/conditional_testing.php?direct_payment_paid=1&flag_paid=0&bid_amount=50
http://www.tecbrat.com/conditional_testing.php?direct_payment_paid=0&flag_paid=1&bid_amount=50
http://www.tecbrat.com/conditional_testing.php?direct_payment_paid=1&flag_paid=1&bid_amount=50
http://www.tecbrat.com/conditional_testing.php?direct_payment_paid=0&flag_paid=0&bid_amount=0
http://www.tecbrat.com/conditional_testing.php?direct_payment_paid=0&flag_paid=0&bid_amount=50