Photo Shop: Calculation problems Photo Shop: Calculation problems
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Photo Shop: Calculation problems

Started by JohannM, January 05, 2008, 11:46:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JohannM

Hi there

FIRST off all, a HAPPY NEW YEAR to you all ...

I have made (still busy) a nice shopping system for my tattoo company.

Altough I managed to get all the nice effects and results with the calculation of totals and discount, it shows up nice and correct on my photo_shop_cart.php and photo_shop_checkout.php (first stages) pages. (checkout01.jpg).

Problem is when I click on "Confirm Order" on the photo_shop_checkout.php page, the amount being showed and emailed is totally wrong.  I tried both the "$item_price" and "$order_price" to get the amounts, but it show it totally wrong. (checkout02.jpg).

I am attaching my checkout page as well. 

The calculation code in the functions.inc.php page is like: (with some added ones I included):

   $discount_calc = calculate_discount($temp_price, $cd_counter);
   $shipping_calc = calculate_shipping();
                $discount = number_format(($discount_calc),2);
   $shipping = number_format(($shipping_calc),2);
   $tot_price = number_format(($temp_price[1]+$temp_price[0]-$discount_calc+$shipping_calc),2);
   $cd_price = number_format(($temp_price[1]),2);
   $photo_price = number_format($temp_price[0],2);
   $sub_total = number_format(($temp_price[0]-$discount_calc+$shipping_calc),2);

The calclation code in my photo_shop_checkout.php page is like:

   //calculate the discount
   $discount = number_format(calculate_discount($cd_price, $cd_counter),2);
   $shipping_price = number_format(calculate_shipping(),2);

and

//here we do the integration... we just add the buttons, text etc to the msg_box
         $item_price = number_format(($cd_price[0]+$cd_price[1]-$discount),2); // - discount (used for 
                                                paypal, google checkout)
         $order_price = number_format(($cd_price[0]+$cd_price[1]+$shipping_price-$discount),2);
         $msg_box_txt = $lang_photoshop['email_sent'];
         $msg_box_txt .= '<br><br>'.$lang_photoshop['order_id'].' '.$order_id.', '.$lang_photoshop
                                                ['total'].' '.$order_price.' '.$lang_photoshop['USD'];

The problem is the $order_price that does not correspond to the $total_price (like in the 'functions.ini.php' page).

Can anyone assist in this matter ?

I have created a TEST user ( username: "test" and password "test") at http://www.temp-tattoos.co.za/agents/  for those who would like to see.

Thanx in advance

Stramm

oh, yep, a bug when introducing the user defind shipping and discounts

plugins/photo_shop/photo_shop_checkout.php

find
//calculate the discount
below add
$discount_calc = calculate_discount($cd_price, $cd_counter);
$shipping_price_calc = calculate_shipping();


find
$item_price = number_format(($cd_price[0]+$cd_price[1]-$discount),2); // - discount (used for paypal, google checkout)
$order_price = number_format(($cd_price[0]+$cd_price[1]+$shipping_price-$discount),2);

replace with
$item_price = number_format(($cd_price[0]+$cd_price[1]-$discount_calc),2); // - discount (used for paypal, google checkout)
$order_price = number_format(($cd_price[0]+$cd_price[1]+$shipping_price_calc-$discount_calc),2);


please tell me if things work for you after this modifications

JohannM

Stramm

You are a absolute STAR.  Thanx, it worked.

My php knowledge is getting better, but I guess i will take a couple more years to get to the gripp of it.

Thanx again.

JohannM

Stramm

Now the other problem I encountered is that the {PRICE} emailed to the admin and user is also wrong. It shows the original amounts without the discounts and shipping, etc.

JohannM

Problem solved:

function photoshop_email_the_user($message, $subject, $admin = '')
{
   global $CONFIG, $SHOP_CONFIG, $lang_photoshop, $cd_price, $order_id, $discount, $shipping_price, $shipping_price_calc, $discount_calc, $order_price;

Stramm

exactly the same issue
plugins/photo_shop/photo_shop_checkout.php
find
global $CONFIG, $SHOP_CONFIG, $lang_photoshop, $cd_price, $order_id, $discount, $shipping_price;

replace with
global $CONFIG, $SHOP_CONFIG, $lang_photoshop, $cd_price, $order_id, $discount_calc, $shipping_price_calc;


find
'{PRICE}' => number_format(($cd_price[0]+$cd_price[1]+$shipping_price-$discount),2),

replace with
'{PRICE}' => number_format(($cd_price[0]+$cd_price[1]+$shipping_price_calc-$discount_calc),2),

thanks for spotting ;)
most users won't see this bug cause it only appeares when calculating using numbers with more than 3 digits


JohannM

Thanx


I have the same issues with the "My Orders" and "Admin" pages.  It don't show the correct number format and totals.

Stramm

already answered that question in your other post... is this issue solved?

JohannM

#8
Stramm, sorry for being stupid, but what post was that ?

I also encounter that the discount I configured is either allocating it to the Total of Photo's Amount or the total of CD Amount, if a customer order both photos and cd's, the discount calculation is wrong.

Please help !

in my functions.inc.php

//calculate and format total, discount, shipping
function photoshop_format_price($temp_price, $cd_counter, $error='', $template){
global $lang_photoshop, $SHOP_CONFIG;

$out =array();
$discount_calc = calculate_discount($temp_price, $cd_counter);
$shipping_calc = calculate_shipping();
      $discount = number_format(($discount_calc),2);
$shipping = number_format(($shipping_calc),2);
$tot_price = number_format(($temp_price[1]+$temp_price[0]+$shipping_calc-$discount_calc),2);
$cd_price = number_format(($temp_price[1]),2);
$photo_price = number_format($temp_price[0],2);

$photocd_price = number_format(($temp_price[1]+$temp_price[0]),2);
//$sub_total = number_format(($temp_price[1]+$temp_price[0]-$discount_calc),2); //JOHANN FIXED SUB-TOTAL CULCULATION
$sub_total = number_format(($temp_price[1]+$temp_price[0]-$discount),2); //JOHANN FIXED SUB-TOTAL CULCULATION


if(USER_GROUP == 'Registered'){
$discountpercent = '10';
}

if(USER_GROUP == 'Sponsor25'){
$discountpercent = '25';
}

if(USER_GROUP == 'Sponsor50'){
$discountpercent = '50';
}

//JOHANN TO FIC FORMAT OF CART IN HTML VIEW

if ($cd_price > 0) {
$cd_price2 = "{$lang_photoshop['on_cd']}: {$cd_counter['cd']} {$lang_photoshop['pics']} :: $cd_price{$lang_photoshop['USD']}&nbsp;<br />";
} else $cd_price2 = '';


if ($photo_price > 0) {
$photo_price2 = "{$lang_photoshop['for_print']}: {$cd_counter['photo']} {$lang_photoshop['pics']} :: $photo_price{$lang_photoshop['USD']}&nbsp;<br />";
} else $photo_price2 = '';

$sub_total = "{$lang_photoshop['subtotal']}: {$sub_total} {$lang_photoshop['USD']}&nbsp;<br />";


if ($tot_price > 0) {
if ($SHOP_CONFIG['ship']) {
$total_price = "{$lang_photoshop['shipping']} :: ".$shipping."{$lang_photoshop['USD']}&nbsp;<br>";
} else $total_price = "";

if ($discount > 0) {
$total_price .= "<hr size=\"1\" width=\"200\" align=\"right\" />&nbsp;";
$total_price .= "{$lang_photoshop['discount']} - {$discountpercent}% :: {$discount}{$lang_photoshop['USD']}&nbsp;";

}

$total_price .= "<hr size=\"1\" width=\"200\" align=\"right\" />&nbsp;";
$total_price .= "{$lang_photoshop['total']}: {$tot_price}{$lang_photoshop['USD']}&nbsp;";

} else $tot_price = '';

$out['html'] = <<<EOT
<tr>
<td colspan="6" align="center">
<hr size="1" />
</td>
</tr>
<tr>
<td colspan="6" align="right">
{$photo_price2}
{$cd_price2}{$error}
{$total_price}

</td>
</tr>
EOT;


//calculate discounts, user defined
function calculate_discount($temp_price, $cd_counter){

$discount = '';
//variables that can be used
$cd_counter['photo'];  //number of pics for print
$cd_counter['cd']; //number of pics on CD
$temp_price[1]; //price for the CD
$temp_price[0]; //price for the pics

if(USER_GROUP == 'Registered'){
if($cd_counter['photo'] >= 1)
$discount = 0.10 * $temp_price[0];
}

if (USER_GROUP == 'Registered'){
if($cd_counter['cd'] >= 1)
$discount = 0.10 * $temp_price[1];
}

if(USER_GROUP == 'Sponsor25'){
if($cd_counter['photo'] >= 1)
$discount = 0.25 * $temp_price[0];
}

if (USER_GROUP == 'Sponsor50'){
if($cd_counter['photo'] >= 1)
$discount = 0.50 * $temp_price[0];
}

if(USER_GROUP == 'Sponsor25'){
if($cd_counter['cd'] >= 1)
$discount = 0.25 * $temp_price[1];
}

if (USER_GROUP == 'Sponsor50'){
if($cd_counter['cd'] >= 1)
$discount = 0.50 * $temp_price[1];
}

return $discount;
}