Curency switching works fine but it only applies to the products. At checkout, everything else (total, tax, shipping) is displayed in the default currency.

I couldn't find any information how to change that. I tried to make a rule that converts "commerce-line-item:order:commerce-order-total:" but that would't work due to the error "The integrity check failed" on saving the rule.

What did I miss out?

checkout

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

das-peter’s picture

This is odd, if I do the checkout I'm even able to switch the currency and the checkout reflects the change :|
Do you use a customized view in the checkout?

rockylhc’s picture

That's happen to me two, showing the default currency as the total amount

BrianLP’s picture

No, it's the standard checkout view. What I have added is the tax and shipping module.

das-peter’s picture

I just can speculate that one of those modules somehow affects the currency handling.
Could you disable those temporarily and check if the behaviour changes?

das-peter’s picture

Status: Active » Postponed (maintainer needs more info)
BrendanP’s picture

Had the same issue with Commerce Shipping enabled. Disabling shipping fixes this. Commerce shipping values also do not show converted values.

Is this a shipping issue or multicommerce?

das-peter’s picture

Status: Postponed (maintainer needs more info) » Needs work

This needs some further investigation then.
The symptoms look like the shipping module overwrites changes made by multicurrency.
This could be related to the rules configuration e.g. weight of rules, or the way multicurrency / shipping handle the calculations.
As I'm buried in work atm. I don't know when I can spent time working on this issue.

patrickharris’s picture

This was happening to me too, when I used the flat rate shipping module. When I uninstalled flat rate, and created a custom module to do my (simple) shipping rules, things worked almost 100%.

mmncs’s picture

I have the same issue when installing commerce_shipping and I also get this error:

Warning: call_user_func() expects parameter 1 to be a valid callback, function 'rules_events_entity_unchanged' not found or invalid function name in RulesState->get() (line 148 of /home/quickstart/websites/artunika.dk/sites/all/modules/contrib/rules/includes/rules.state.inc).

I created a bug report on commerce_shipping but I'm not sure where it belongs: http://drupal.org/node/1438508

mmncs’s picture

FileSize
58.22 KB

First of all, thanks for a great module - I'm really looking forward to getting this to work.

Just wanted to be sure it wasn't my settings which caused the call_user_func error so I made a clean install with the latest commerce_multicurrency, commerce, commerce_shipping and commerce_stock where I got the same error.

I have noticed that the rules function &get returns null when trying to load the handler and then aborts. This is triggered when clicking the checkout button.

mmncs’s picture

I have tested the module with the following configuration:

Drupal core 7.12
Address Field 7.x-1.0-beta2
Administration menu 7.x-3.0-rc1
Chaos tool suite (ctools) 7.x-1.0-rc1
Commerce Flat Rate 7.x-1.0-beta1
Commerce Multicurrency 7.x-1.0
Commerce PayPal 7.x-1.x-dev (2012-Feb-05)
Commerce Shipping 7.x-2.x-dev (2011-Dec-28)
Commerce Stock 7.x-2.x-dev (2012-Feb-12)
Drupal Commerce 7.x-1.2
Entity API 7.x-1.0-rc1
Module Filter 7.x-1.6
Rules 7.x-2.0
Views 7.x-3.1

And everything seems to work except the warning message:

Warning: call_user_func() expects parameter 1 to be a valid callback, function 'rules_events_entity_unchanged' not found or invalid function name in RulesState->get() (line 148 of /home/quickstart/websites/wollawonka.com/profiles/commerce_kickstart/modules/rules/includes/rules.state.inc).

The warning message occurs when using the checkout link in the shopping cart and when the currency is different from the currency the product was created with. So it is not default currency, but created currency.

I have also found that the order gets loaded twice when one clicks the checkout link in the shopping cart which causes the warning. When clicking the checkout button on the cart page/pane the order load only happens once. Hope this helps.

BrendanP’s picture

@patrickharris This is my experience too. Off hand could you recommend another shipping module? I'm afraid I don't have the skill to whip up a custom one myself :(

RE this bug, is it worth opening bug with flat rate hipping module? Or is the problem here with the multicurrecy module?

Thanks in advance.

Cheers
Brendan

patrickharris’s picture

I don't think the problem is with flatrate shipping, because I still had problems with my custom one. This custom one works, except when a user checks out in the default currency, and then attempts to alter the currency on the final page, or after shipping has been calculated. Almost always, the currency will then get 'stuck' with the default shipping amount. As a quick fix, I tried to set the default currency to one I wouldn't normally ever use - this fixed the shipping currency issue completely, but caused commerce to start making weird mistakes with calculating product prices. :(

Btw, the guts of my shipping module was just the following:

<?php

/**
 * Implements hook_commerce_shipping_method_info().
 */
function gvs_commerce_shipping_method_info() {
  $shipping_methods = array();

  $shipping_methods['wear_shipping_method'] = array(
    'title' => t('Wear shipping methods'),
    'description' => t('Defines shipping methods for Wear.'),
  );

  return $shipping_methods;
}

/**
 * Implements hook_commerce_shipping_service_info().
 */
function gvs_commerce_shipping_service_info() {
  $shipping_services = array();

  $shipping_services['wear_shipping_service'] = array(
    'title' => t('Wear shipping service'),
    'description' => t('A $20 flat rate service with express delivery available for an additional $15.'),
    'display_title' => t('Shipping'),
    'shipping_method' => 'wear_shipping_method',
    'price_component' => 'shipping',
    'callbacks' => array(
      'rate' => 'gvs_service_rate',
      'details_form' => 'gvs_details_form',
      'details_form_validate' => 'gvs_details_form_validate',
      'details_form_submit' => 'gvs_details_form_submit',
    ),
  );

  return $shipping_services;
}

/**
 * Shipping service callback: returns a base price array for a shipping service
 * calculated for the given order.
 */
function gvs_service_rate($shipping_service, $order) {
  // Get our wear shipping variables
  $gvs_base_rate = variable_get('gvs_base_rate', '20.00');
  $gvs_base_rate = $cents = (integer) ($gvs_base_rate * 100);
  $gvs_free_amount = variable_get('gvs_free_amount', '20.00');
  $gvs_free_amount = $cents = (integer) ($gvs_free_amount * 100);

  $gvs_free = variable_get('gvs_free', 1);

  global $user;
  $order = commerce_cart_order_load($user->uid);
  $order_total =$order->commerce_order_total['und'][0]['amount'];
  $currency_code = $order->commerce_order_total['und'][0]['currency_code'];
  $currency = commerce_currency_load($currency_code);

  // Convert order total to NZD
  $order_total = intval(commerce_multicurrency_conversion($order_total, $currency_code, 'NZD'));
  if($currency_code == 'JPY') {
    $order_total = $order_total * 100;
  }

  // Our base shipping rate in NZD.
  $amount = commerce_multicurrency_conversion($gvs_base_rate, 'NZD', $currency_code);
  if($currency_code == 'JPY') {
    $amount = $amount / 100;
  }
  #$amount = commerce_currency_round(commerce_currency_amount_to_decimal($amount, $currency_code), $currency);

  // Is free shipping turned on? If so, see if it applies to this order
  if($gvs_free && ($gvs_free_amount < $order_total) ) {
    $amount = 0;
  }
  
  return array(
    'amount' => $amount,
    'currency_code' => $currency_code,
    'data' => array(),
  );
}

rockylhc’s picture

#11, same problem here, have you manage to fix it mmncs?

BrendanP’s picture

Hi Folks,

My client may be prepared to offer a bounty for the fixing of the bug with shipping as detailed above. It's dependant on cost as always...) If you interested, please let me know cost and estimated time. You can email me here: me_at_brendanpiater.com

@patrickharris thanks for the feedback and code. That's my next move if it can't be fixed here.

Cheers
Brendan

das-peter’s picture

@BrendanP: Oh that's a nice offer, I really don't have the time to fix it myself but I could add a "wanted poster" on the project page if you'd like.

BrendanP’s picture

@das-peter Thanks, that would be really helpful :)

zyxware’s picture

The shipping module adds shipping rates in the default currency by default. Now commerce_order_calculate_total in commerce module checks for all currencies added to the order and if there are multiple currencies then it picks the default currency to show the order total pane below the order. Now there is an event commerce_shipping_calculate_rate that will be called when shipping rates are collected and the shipping rates are passed as line items to action. You can set an action to change the currency of the shipping rate to the default currency for the user and the problem will be taken care of.

You can create the rule at

admin/commerce/config/shipping/calculation-rules

Then select 'Calculating a shipping rate' as the event and 'Convert the unit price to a different currency' as the action. Set 'commerce_line_item' as the line item and 'site:commerce-currency' as the Currrency for the action.

das-peter’s picture

@zyxware Thanks for the analysis!
I'd say we need to figure out how we actually could make the whole process of creating prices more transparent for the site-builders. The more modules will start dealing with the price the more likely it is that nobody has a clue what exactly goes on.
Debugging rules and hook invokes to figure out which module does when what and why is just PITA.

mitchell’s picture

Title: How to display the selected currency in the checkout panes » Guide: how to display the selected currency in the checkout panes
Status: Needs work » Active
Issue tags: +FAQ

>> Debugging rules and hook invokes to figure out which module does when what and why is just PITA.
Please see #1498908: Internal review of Rules API design.

>> I'd say we need to figure out how we actually could make the whole process of creating prices more transparent for the site-builders. The more modules will start dealing with the price the more likely it is that nobody has a clue what exactly goes on.
Where's a good place for these docs?

garethhallnz’s picture

This has been a real pain but I just found a work around by creating a rule that deletes the shipping rate if the currency changes.
The rule is setup as follows:

Event:
After the user currency has set

Conditions
Shipping line item exists
Execute custom PHP code

if(arg(0) == "checkout" || arg(2) == "review"){
return TRUE;
}

Actions
Delete all shipping line items from an order
Page redirect (to checkout)

Or import the rule

{ "rules_shipping_currency_bug" : {
    "LABEL" : "Shipping-Currency-bug",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "commerce_shipping", "php", "rules", "commerce_multicurrency" ],
    "ON" : [ "commerce_multicurrency_user_currency_set" ],
    "IF" : [
      { "commerce_shipping_compare_shipping_service" : {
          "commerce_order" : [ "site:current-cart-order" ],
          "service" : "wear_shipping_service"
        }
      },
      { "php_eval" : { "code" : "if(arg(0) == \u0022checkout\u0022 || arg(2) == \u0022review\u0022){\r\nreturn TRUE;\r\n}" } }
    ],
    "DO" : [
      { "commerce_shipping_delete_shipping_line_items" : { "commerce_order" : [ "site:current-cart-order" ] } },
      { "redirect" : { "url" : "checkout" } }
    ]
  }
}

garethhallnz’s picture

FYI

The rule in #21 breaks when you run cron, then when you rule updated.php it works again. Bug can be found here http://drupal.org/node/1544038

rockylhc’s picture

asd

amitvin’s picture

Use Commerce Shipping 7.x-2.x-dev 2012-Jun-18 with Commerce Multicurrency 7.x-1.1

Replace the existing lines with the following lines uder the specified files

commerce_shipping\includes\commerce_shipping.checkout_pane.inc
Line number 243 : $rate = commerce_currency_format($total_price['amount'], commerce_multicurrency_get_user_currency_code(), $line_item_wrapper->value());

commerce_shipping\commerce_shipping.module
Line number 575: '!price' => commerce_currency_format($line_item_wrapper->commerce_unit_price->amount->value(), commerce_multicurrency_get_user_currency_code()),

Hope this works for you too, Cheers!!!

rphillipsfeynman’s picture

I'm more or less having the same problem. I'm using the following versions of Commerce Shipping and Commerce Flat Rate:

- Commerce Shipping 7.x-2.0-beta1 2011-Dec-15 (with the 7.x-2.0-dev version I got the error "Undefined index: shipping_details in commerce_shipping_pane_checkout_form_validate()" that I could not fix)
- Commerce Flat Rate 7.x-1.0-beta1 2011-Dec-15

The solution proposed by #24 only affects the shipping information as a pane in the checkout form but does nothing to the view with the order review. That is, the view keeps showing the products total prices in the selected currency and the "Subtotal", "Shipping rate" and "Order Total" are in the default currency specified in the settings of Commerce Multicurrency. I realized that the problem disappears when I specify the base rate in the Commerce Flat Rate service I created in a different currency than the default one. I could specify the base rate in a different currency and the problem would be solved if it wasn't for the inconvenient that the exchange rate changes everyday. I hope some one can shed light on this. I've done my very best trying to figure out the origin of the problem and fix it but I am afraid my limited knowledge of Drupal won't let me do more than I've done already.

storytellerjeff’s picture

Priority: Normal » Critical

Just an additional note, as the Commerce Invoice (1.0-alpha3+9-dev) and Commerce Invoice Receipt (1.x-dev) modules both use the view to populate their invoice forms, they are both experiencing the same problem (and thus being rendered with line items and totals in two different currencies).

Like rphillipsfeynman, I tried #24 (and #21) and it didn't fix the issue. This seems a pretty critical issue, as this bug adds a lot of confusion to the checkout process. I do want to add that it's a great module and definitely needed! But, it pretty much can't be enabled as long as two different currencies are showing at the same time in the checkout review table.

Lukas von Blarer’s picture

dotline’s picture

This works for me
Commerce 7.x-1.3
Commerce Multicurrency 7.x-1.1+3-dev
Flat Rate 7.x-1.x-dev
Shipping 7.x-2.0-beta1+19-dev

storytellerjeff’s picture

I'm still experiencing the issue on the checkout review page, with no caching on and the same modules installed.

Commerce 7.x-1.3
Commerce Multicurrency 7.x-1.1+3-dev
Commerce Flat Rate 7.x-1.x-dev
Commerce Shipping 7.x-2.0-beta1+19-dev

dotline, were you experiencing the problem and then it resolved after upgrading/changing the version of one of those modules?

Lukas von Blarer’s picture

#21 did the trick. Thank you!

How can we get this fixed?

storytellerjeff’s picture

Any update on this critical problem?

I'm using Commerce 7.x-1.4 and Multicurrency 7.x-1.x - dev (with a relatively fresh install) and this bug is alive and well. And the solution at #21 has no effect.

rphillipsfeynman’s picture

Well, I was pissed off with this and found a solution but I guess not the best one since I had to hack the code of the Commerce Shipping and Commerce Order modules. Here it is what I did:

1.- Following the instructions of #24 I replaced in file commerce_shipping.checkout_pane.inc:

LINE: $rate = commerce_currency_format($total_price['amount'], $total_price['currency_code'], $line_item_wrapper->value());
BY: $rate = commerce_currency_format(commerce_multicurrency_conversion($total_price['amount'], $total_price['currency_code'], commerce_multicurrency_get_user_currency_code()), commerce_multicurrency_get_user_currency_code(), $line_item_wrapper->value());
INSTEAD OF: $rate = commerce_currency_format($total_price['amount'], commerce_multicurrency_get_user_currency_code(), $line_item_wrapper->value());

and in file commerce_shipping.module:
LINE: '!price' => commerce_currency_format($line_item_wrapper->commerce_unit_price->amount->value(), $line_item_wrapper->commerce_unit_price->currency_code->value()),
BY: '!price' => commerce_currency_format(commerce_multicurrency_conversion($line_item_wrapper->commerce_unit_price->amount->value(), $line_item_wrapper->commerce_unit_price->currency_code->value(), commerce_multicurrency_get_user_currency_code()), commerce_multicurrency_get_user_currency_code()),
INSTEAD OF: '!price' => commerce_currency_format($line_item_wrapper->commerce_unit_price->amount->value(), commerce_multicurrency_get_user_currency_code()),

Otherwhise, I only got the currency code change.

2.- I changed in function commerce_line_items_total($line_items, $types = array()) in file commerce_line_item.module,

THIS: elseif (in_array(commerce_default_currency(), array_keys($currencies))) {
// Otherwise use the site default currency if it's in the array.
$currency_code = commerce_default_currency();
}
BY: elseif (in_array(commerce_default_currency(), array_keys($currencies))) {
// Otherwise use the site default currency if it's in the array.
$currency_code = commerce_multicurrency_get_user_currency_code();
}

3.- I changed in function commerce_order_calculate_total($order) in file commerce_order.module,

THIS: elseif (in_array(commerce_default_currency(), array_keys($currencies))) {
// Otherwise use the site default currency if it's in the order.
$currency_code = commerce_default_currency();
}
BY: elseif (in_array(commerce_default_currency(), array_keys($currencies))) {
// Otherwise use the site default currency if it's in the order.
$currency_code = commerce_multicurrency_get_user_currency_code();
}

This works for me. Perhaps someone with more knowledge of Drupal could take a look at this and propose a better solution. Hope it works for you as well.

Jovean’s picture

I recently (an hour ago) used this Rule to resolve this issue:

{ "rules_convert_shipping" : {
    "LABEL" : "Convert Shipping",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_line_item", "commerce_shipping" ],
    "ON" : [ "commerce_shipping_calculate" ],
    "IF" : [
      { "entity_has_field" : {
          "entity" : [ "site:current-cart-order" ],
          "field" : "commerce_customer_shipping"
        }
      }
    ],
    "DO" : [
      { "commerce_line_item_unit_price_currency_code" : {
          "commerce_line_item" : [ "commerce_line_item" ],
          "currency_code" : "CHF"
        }
      },
      { "commerce_line_item_unit_price_currency_convert" : {
          "commerce_line_item" : [ "commerce_line_item" ],
          "currency_code" : [ "site:commerce-currency" ]
        }
      }
    ]
  }
}

Of course, change "CHF" to the currency code of your site's default currency.

marcelodornelas’s picture

Hi, I run into the same problem and it can be fixed by adding a rule to 'admin/commerce/config/shipping/calculation-rules'

The rule should have the action: "Convert the unit price to a different currency".

The rule has 2 parameters:

Parameter: Line item: [commerce_line_item], Currency: [site:commerce-currency]

{ "rules_test_rule" : {
"LABEL" : "Convert shipping to a different currency",
"PLUGIN" : "reaction rule",
"TAGS" : [ "shipping" ],
"REQUIRES" : [ "commerce_line_item", "commerce_shipping" ],
"ON" : [ "commerce_shipping_calculate_rate" ],
"DO" : [
{ "commerce_line_item_unit_price_currency_convert" : {
"commerce_line_item" : [ "commerce_line_item" ],
"currency_code" : [ "site:commerce-currency" ]
}
}
]
}
}

das-peter’s picture

I've just pushed updated default rules: http://drupalcode.org/project/commerce_multicurrency.git/commit/eb9be8d

If the Commerce Shipping module is enabled a reaction rule with currency conversion is created.

colan’s picture

Status: Active » Needs review
colan’s picture

Status: Needs review » Fixed

Actually, marking this as fixed as there have been no complaints for a while, and this is already in the latest release.

Automatically closed -- issue fixed for 2 weeks with no activity.