News:

Support the VirtueMart project and become a member

Main Menu

Trigger event before checkout

Started by sandomatyas, May 24, 2016, 14:03:47 PM

Previous topic - Next topic

sandomatyas

I manage a webshop which uses some external data feed to update the stock. The sync srcipt runs hourly.
I want to run a script right before storing the order to check again if the product stock is available in the external feed.
Is there a way to do that?

Milbo

family vmshopper, vmextended
trigger plgVmOnUserOrder
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sandomatyas

#2
Hi Milbo,
Thank you for your answer.
I checked it but this method is triggered in the _createOrder method of VirtueMartModelOrders class so I think it's too late for me. I want to check it before the order creation process because if the product is out of stock I want to redirect the user back to the cart with a message. Or have I missed something?

Studio 42

Hi,
you can use create an empty shipment plugin with only this function
plgVmOnCheckoutCheckDataShipment, this is the last trigger before real confirm.
in plgVmConfirmedOrder  the order is already created.
I have(had) the same problem and had to trick a little to find a way without adding my own trigger because checkoutData() do not give from where you call it, so you need to verify other values, to find out if you are in ConfirmedOrder or not .I use if( !$cart->_dataValidated) return;.

Milbo

Can we change another trigger to solve this issue? and where would you place the new trigger, Patrick?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Studio 42

#5
I don't think we need a new trigger.
in cart helper
function confirmDone() {
...
$this->checkoutData(false, true);

...
public function checkoutData($redirect = true,$onConfirm = false) {
....

$retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataShipment', array(  $this, $onConfirm));
....

$retValues = $dispatcher->trigger('plgVmOnCheckoutCheckDataPayment', array( $this, $onConfirm));
}


or if adding a new generic trigger (for customs, userfields ...) always in public function checkoutData :

$retValues = $dispatcher->trigger('plgVmOnCheckoutCheckData', array(  $this, $onConfirm));