VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: vmfyelloq19 on July 25, 2024, 20:30:52 PM

Title: Programatically pre-set shipping method?
Post by: vmfyelloq19 on July 25, 2024, 20:30:52 PM
Friends,

I'd like so pre-set a shipping method (based on some very specific conditions not imporatnt here).
The idea is that the shipping method is pre-set when the customers checks out, while still allowing to change it.

I have prepared a system plugin for this but I have trouble selecting the proper event.
Several events looked promising, like plgVmOnSelectedCalculatePriceShipment(), but I could not get it to work by now.

Any hints?
Title: Re: Programatically pre-set shipping method?
Post by: Jumbo! on July 25, 2024, 21:39:29 PM
You may want to consider using the "plgVmOnCheckoutCheckStock" event. In this event, the first argument passed is the cart object, which you can use to modify the "virtuemart_shipmentmethod_id" property. Remember not to return anything in the listener function.

Also, keep in mind that a system plugin in Joomla 4 and 5 won't listen to events that do not start with the "on" prefix. To address this, you can add the following function in the plugin's constructor to listen to the "plgVmOnCheckoutCheckStock" event.

$this->registerLegacyListener('plgVmOnCheckoutCheckStock');
Title: Re: Programatically pre-set shipping method?
Post by: vmfyelloq19 on July 29, 2024, 16:55:38 PM
Hi Jumbo,

thank you for your suggestion. I was under the impression I could not change the cart from here but re-checking after your post shows it does just fine. Seems One Page Checkout byPV is ignoring my changes. So I might need to investigate there (or drop OPC completely, as I'd probalby do for other reasons anyway)

Thanks again!