Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: Photo Shop: Calculation problems  (Read 7952 times)

0 Members and 1 Guest are viewing this topic.

JohannM

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 252
Photo Shop: Calculation problems
« on: January 05, 2008, 11:46:50 pm »

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
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Photo Shop: Calculation problems
« Reply #1 on: January 06, 2008, 09:36:25 am »

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

plugins/photo_shop/photo_shop_checkout.php

find
Code: [Select]
//calculate the discountbelow add
Code: [Select]
$discount_calc = calculate_discount($cd_price, $cd_counter);
$shipping_price_calc = calculate_shipping();

find
Code: [Select]
$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
Code: [Select]
$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

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 252
Re: Photo Shop: Calculation problems
« Reply #2 on: January 06, 2008, 01:39:52 pm »

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.
Logged

JohannM

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 252
Re: Photo Shop: Calculation problems
« Reply #3 on: January 06, 2008, 01:54:01 pm »

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.
Logged

JohannM

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 252
Re: Photo Shop: Calculation problems
« Reply #4 on: January 06, 2008, 02:09:28 pm »

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;
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Photo Shop: Calculation problems
« Reply #5 on: January 06, 2008, 02:10:07 pm »

exactly the same issue
plugins/photo_shop/photo_shop_checkout.php
find
Code: [Select]
global $CONFIG, $SHOP_CONFIG, $lang_photoshop, $cd_price, $order_id, $discount, $shipping_price;
replace with
Code: [Select]
global $CONFIG, $SHOP_CONFIG, $lang_photoshop, $cd_price, $order_id, $discount_calc, $shipping_price_calc;

find
Code: [Select]
'{PRICE}' => number_format(($cd_price[0]+$cd_price[1]+$shipping_price-$discount),2),
replace with
Code: [Select]
'{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

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 252
Re: Photo Shop: Calculation problems
« Reply #6 on: January 06, 2008, 03:23:43 pm »

Thanx


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

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Photo Shop: Calculation problems
« Reply #7 on: January 06, 2008, 03:28:26 pm »

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

JohannM

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 252
Re: Photo Shop: Calculation problems
« Reply #8 on: July 30, 2008, 04:32:25 am »

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

Code: [Select]
//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;
}
« Last Edit: July 30, 2008, 07:05:26 am by Joachim Müller »
Logged
Pages: [1]   Go Up
 

Page created in 0.031 seconds with 20 queries.