0

I want to change the price of the order in the cart/checkout page. Let's say I have a product ABC with $100(USD) and I added that in cart. But after adding I want to change the currency to EUR and proceed with the checkout process. I tried to change the currency and amount in order like below:

$order = commerce_order_load(1234);
$amount = 100;
$order->commerce_order_total['und'][0]['amount'] = round($amount,2);
$order->commerce_order_total['und'][0]['currency_code'] = 'EUR';
$order->commerce_order_total['und'][0]['data']['components'][0]['price']['amount'] = round($amount,2);
$order->commerce_order_total['und'][0]['data']['components'][0]['price']['currency_code'] = 'EUR';
commerce_order_save($order);

But when I refresh the checkout or visit cart page, it's still in USD. So I need help in changing the currency of order based on user input in cart/checkout page or based on the field (currency) which admin has created for every product.

1

You cannot directly manipulate the order total like this, as it gets recalculated based on its line items' prices each cart refresh. (That happens on every pageload in checkout and however you've configured it for other routes.)

You should look into the Commerce Multicurrency module instead or else configure your pricing rules / otherwise hook into product sell price calculation to change the currency on the order items (and shipping if present). If those are all the same target currency, the order total will use it, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.