VirtueMart V3.2.12
I have a small query if someone can suggest -
I am trying to get VirtueMart cart's complete value in my own method, that might be used in APIs or something. So from the basic thing things like getting the cart, I have already done VirtueMartCart::getCart(); that provides me all the selected cart data in an instance. This provides the selected payment/shipment cost in its indexes along with taxes. Also, I can manipulate my whole cart with it.
Now I am trying to get shipment and payment cost of each available method on the cart. I checked that VM uses 'plgVmDisplayListFEShipment' trigger to render each shipment/payment cost data, and this method returns complete HTML. On digging I found different third-party plugins make their own HTML and return to it with "radio" buttons, as a shipment plugin could have multiple services within a single shipment method. Whilst VM standard shipment method calls 'displayListFE' of 'vmPSPlugin' class which is an abstract class. So I can not take it instance within my controller or model as I have not extended it.
So is there any method which can provide all available shipment/payment method costs directly?
Also please suggest what method should be used to set 'cart currency' and 'shop language'.
Thanks in advance!
you can load 1 plugin only
JPluginHelper::importPlugin ('vmshipment', 'my_plugin');
$dispatcher = JDispatcher::getInstance ();
You have to loop each plugin to call the method plgVmDisplayListFEShipment to get each result.
Quote from: Studio 42 on March 08, 2018, 18:55:14 PM
you can load 1 plugin only
JPluginHelper::importPlugin ('vmshipment', 'my_plugin');
$dispatcher = JDispatcher::getInstance ();
You have to loop each plugin to call the method plgVmDisplayListFEShipment to get each result.
But it will return html, as plgVmDisplayListFEShipment return a well form html including radio buttons.
Also please suggest what method should be used to set 'cart currency' and 'shop language'.
If you want display same list as the original cart then use same code as original cart view.
Check the file \components\com_virtuemart\views\cart\view.html.php to see how it work and the cart controller
ok, I have checked it and it returns HTML only. I assume there is no other way around then as 'plgVmDisplayListFEShipment' is the only method that has cart shipment prices.
Can you please help me suggesting some method from which I can set cart currency and shop language? For language I tried setting it from VmConfig::set('vmlang', 'fr_fr'); Though as I am using it via API call, it returns me only default language data. Also, unable to find any method for setting cart currency.
For language, you need to set it on load, if you run admin, language cannot be changed, so you need to call it with a front link.
Currrency can be set on setting the currency in the link using virtuemart_currency_id.
For eg : index.php?option=com_yourcomponent&virtuemart_currency_id=1&lang=fr should set the right currency and language when you load the Virtuemart config.
Quote from: Studio 42 on March 19, 2018, 17:25:10 PM
For language, you need to set it on load, if you run admin, language cannot be changed, so you need to call it with a front link.
Hmm? You can always change the language with vmLanguage::setLanguage('de-DE') for example.
In general, you do a $cart = VirtueMartCart::getCart(); use vmdebug('my cart',$cart); to see the cart object.
Then you do something with the $cart, for example you can set the currency, or the order language. Then you can store it $cart->setCartIntoSession(true,true);
Thanks for joining Max. I have yet applied to try your stated suggestion, I am sure it would work and I will check to implement them first whenever I will be in that part of code again in my API.
Currently, I have used:
$app = JFactory::getApplication();
$app->setUserState('virtuemart_currency_id', $virtuemartCurrencyId);
And yes it worked like a charm as it changes cart currency every time. Also, I have tried
$app->setUserState('application.lang', 'en');
Though the language changes one time and didn't change on resetting this. I will work with your suggestions as well.
One suggestion, as you can see my first question was to get shipment/payment prices in return for a method call(I am able to get complete HTML only), it would have been great if this could be possible in VirtueMart.