I have written shipment plugin that may cancel order status changing for certain reasons.
I expect that returning false on plgVmOnUpdateOrderShipment should prevent order saving, as it happens in false return from plgVmOnUpdateOrderPayment.
But for version 3.0.16 administrator\components\com_virtuemart\models\orders.php has following implementation:
// ... line 768
JPluginHelper::importPlugin('vmshipment');
$_dispatcher = JDispatcher::getInstance(); //Should we add this? $inputOrder
$_returnValues = $_dispatcher->trigger('plgVmOnUpdateOrderShipment',array(&$data,$old_order_status));
// Payment decides what to do when order status is updated
JPluginHelper::importPlugin('vmpayment');
$_dispatcher = JDispatcher::getInstance(); //Should we add this? $inputOrder
$_returnValues = $_dispatcher->trigger('plgVmOnUpdateOrderPayment',array(&$data,$old_order_status));
foreach ($_returnValues as $_returnValue) {
if ($_returnValue === true) {
break; // Plugin was successfull
} elseif ($_returnValue === false) {
return false; // Plugin failed
}
// Ignore null status and look for the next returnValue
}
First $_returnValues just rewritten with next event results.
I suppose that both event result sets should be merged and if any of them contains false, then order saving will be canceled.
Thank you, interesting.
Yes, I plan for vm3.2 or vm4 to combine the triggers. We would need to add the foreach also for the shipment trigger, but I fear problems with older plugins.
@velosipedist
Could u give an example when it would be useful to block a confirm by this function?
The conditions routine is triggered on every cart change so where would this further check be used?
I am using a shipment plugin to send my order to an external service. But I want to only update the order status if this service sends an status 200 (succeeeded) back. Now I tried using the return false if the error code is not 200 so the status wont get updated but that is still not working? Is that correct?
How can I make sure the order wont get changed?
public function plgVmOnUpdateOrderShipment($data,$old_status,$inputOrder){
$new_status=$inputOrder['order_status'];
$method = $this->getVmPluginMethod ($data->virtuemart_shipmentmethod_id);
$this->method=$method;
//var_dump($new_status);
if (!$this->selectedThisElement ($method->shipment_element)) {
return ;
}
if($old_status==$method->order_status){ // already order is created
// return ;
}
if($new_status==$method->order_status){
if(!$this->sendOrderToPaazl($data->virtuemart_order_id,$method)){
return false;
} else {
return true;
};
}
}
Or do i need to update the order status back to the old order status? With the updateStatusForOneOrder function?
EDIT: Unfortunately this runs before the status gets updated, so the initial status change overrides this one in the shipment. (So I change it to C in the admin, this plugin sets it to P, because the SendOrderToPaazl returns false, but instead of ending it there it eventually changes it to C regardless. Does anyone know how to make this work.. I just want the order to not change when the SendOrderToPaazl returns false or error 200...
i was also working on that problem. Lets find together the new core code we need here, maybe I did already for the payments you may checkout vm4.2. I sent you a pn