VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: sandomatyas on May 24, 2016, 14:03:47 PM

Title: Trigger event before checkout
Post by: sandomatyas on May 24, 2016, 14:03:47 PM
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?
Title: Re: Trigger event before checkout
Post by: Milbo on May 27, 2016, 11:09:17 AM
family vmshopper, vmextended
trigger plgVmOnUserOrder
Title: Re: Trigger event before checkout
Post by: sandomatyas on June 20, 2016, 15:36:56 PM
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?
Title: Re: Trigger event before checkout
Post by: Studio 42 on June 20, 2016, 23:48:52 PM
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;.
Title: Re: Trigger event before checkout
Post by: Milbo on June 29, 2016, 10:04:33 AM
Can we change another trigger to solve this issue? and where would you place the new trigger, Patrick?
Title: Re: Trigger event before checkout
Post by: Studio 42 on June 29, 2016, 12:21:17 PM
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));