Hi Jerome,
Thanks for that.
Please correct me if I misunderstood you, but I think this is what you suggested, right?
function onAfterCartProductsLoad(&$cart)
{
if (empty($cart->products))
return;
$config = hikashop_config();
$app = JFactory::getApplication();
$main_currency = (int)$config->get('main_currency', 1);
$currency_id = (int)$app->getUserState(HIKASHOP_COMPONENT.'.currency_id', $main_currency);
$first_product = reset($cart->products);
echo '(old session currency: '.$session_currency.') ';
echo 'session id: '.$cart->products[0]->session_id;
echo ' || ';
echo 'vendor id: '.$first_product ->product_vendor_id;
echo ' || ';
$vendor_currency = $this->getVendorCurrency($first_product ->product_vendor_id);
echo 'vendor currency: '.$vendor_currency;
echo ' || ';
$app->setUserState(HIKASHOP_COMPONENT.'.currency_id', $vendor_currency);
// $app->setUserState( HIKASHOP_COMPONENT.'.payment_data.payment_params.payment_currency', $vendor_currency );
// $new_session_currency = $app->getUserState( HIKASHOP_COMPONENT.'.payment_data.payment_params.payment_currency', 0, 'int' );
//
// echo '(new session currency: '.$new_session_currency.') ';
// echo '<br />';
}
My test case is as follows:
Hikashop main currency: USD (currency id:2)
The product "Milonga 1" set up in Euros (currency id:1) and owned by Vendor with vendor ID = 2
Vendor with vendor ID = 2 has currency in Euros (currency id:1)
Then when I add the product "Milonga 1" to the cart and I'm redirected to the checkout I see as per the attachment.
As you can see the plugin executes two times.
At the begining of the plugin the session currency has no value or value 2 (USD), and at the end of the plugin I set it to the Vendor currency Euros (id:1).
But the display of pricing is still showing as if USD is the cart currency, including the total. So something looks like it is not working.
Any idea? Am I setting the right currency session setting? Is there anything else that could be changing the session currency back to the main shop currency after my plugin?