News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Returning false from plgVmOnUpdateOrderShipment does nothing

Started by velosipedist, July 27, 2016, 02:17:12 AM

Previous topic - Next topic

velosipedist

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.

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

GJC Web Design

@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?
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Kuubs

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...

Milbo

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
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/