Jump to content

If I Change Currency And $Cart->Update(); -> $Total Is Wrong. Why?


mmsh

Recommended Posts

Hello,

I have an issue with PS 1.4.x

 

e.g. in pounds the total amount from the cart is £923.21

with the current conversion rate 1.388889

 

in EUR it should be 923.21 * 1.388889 = 1282,24 (rounded 2) 

 

BUT If I do:

$cookie->id_currency = 1; //1 for EUR
$cart->id_currency = $cookie->id_currency;
$cart->update();
//and then...
$amount = number_format($cart->getOrderTotal(true, 3), 2, '.', '');

The final $total is WRONG

at the end is € 1276.86 instead of the correct 1282.24

 

Why? Where is the error?

Thanks

Link to comment
Share on other sites

Another cart (DEBUG CONSOLE)

BEFORE

$cart	Smarty_Variable Object (3)
->value = Cart Object (14)
   ->id = 2899
   ->id_address_delivery = "5"
   ->id_address_invoice = "5"
   ->id_currency = "3"
   ->id_customer = "3"
   ->id_guest = "998683"
   ->id_lang = "1"
   ->id_carrier = "14"
   ->recyclable = "1"
   ->gift = "0"
   ->gift_message = ""
   ->date_add = "2015-12-09 10:08:27"
   ->secure_key = "5b5c81dbecc7b7e1d9603752071321b7"
   ->date_upd = "2015-12-09 17:17:15"
->nocache = false
->scope = "Smarty root"


$total	Smarty_Variable Object (3)
->value = "£896.32"
->nocache = false
->scope = "Smarty root"

AFTER $cart->update();

$cart	Smarty_Variable Object (3)
->value = Cart Object (14)
   ->id = 2899
   ->id_address_delivery = "5"
   ->id_address_invoice = "5"
   ->id_currency = 1
   ->id_customer = "3"
   ->id_guest = "998683"
   ->id_lang = "1"
   ->id_carrier = "14"
   ->recyclable = "1"
   ->gift = "0"
   ->gift_message = ""
   ->date_add = "2015-12-09 10:08:27"
   ->secure_key = "5b5c81dbecc7b7e1d9603752071321b7"
   ->date_upd = "2015-12-09 17:19:41"
->nocache = false
->scope = "Smarty root"

$total	Smarty_Variable Object (3)
->value = "1 239,67 €"
->nocache = false
->scope = "Smarty root"

completely wrong... that 1 239,67 should be 896.32 * 1.388889 = 1 244,89

Please, where is the error? Thanks for your help

Link to comment
Share on other sites

another issue (the main, indeed)

If I set a voucher and do

...
$cart->update();
$amount = number_format($cart->getOrderTotal(true, 3), 2, '.', ''); 

$total from cart is treated WITHOUT the voucher...as the previous total

How to include the voucher inside the updated cart ?

Edited by mmsh (see edit history)
Link to comment
Share on other sites

I tried to do:

$discounts=$cart->getDiscounts(false,true);
//print_r($discounts); OK, discount array
//if ($discounts) {
$voucher= $discounts[0]['id_discount']; //retrieves correctly the id_discount eg. 9
//echo "<br />id discount is $voucher <br />";
$voucher=$voucher+1; //the +1 id (eg. 10) is already prepared converted in EUR

//}
$cookie->id_currency = 1; //EUR
$cart->id_currency = $cookie->id_currency;
$cart->update(); //now cart is in EUR
$cart->addDiscount($voucher); //should add the chosen voucher to the cart (?)
//$cart->update();		

it doesn't work...the $total from $cart->getOrderTotal(....);

is still wrong...

 

it's a real mess....anyone who can help?

Edited by mmsh (see edit history)
Link to comment
Share on other sites

FOUND the issue for the cart update...

there is the additional_shipping_cost field which is not updated when you change currency...so I need to it manually when needed

 

then, for $cart->addDiscount($voucher); instead,

it seems that it doesn't update the cart until I refresh the page...

anyone can help?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...