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

Custom script after updating an order

Started by sandomatyas, October 29, 2018, 21:33:47 PM

Previous topic - Next topic

sandomatyas

I want to create a custom script which is triggered when an order is updated and gets a specific order status.
Which type of plugin and method do I need do that?
I checked VirtueMartModelOrders.updateStatusForOneOrder() and it's maybe plgVmOnUpdateOrderPayment in vmcustom/vmcalculation/vmpayment plugins? This script actually isn't one of them. I need to send some order data to a REST api when the order is set to shipped.
Thanks

GJC Web Design

vmcustom plugin will work

here's a start:



defined('_JEXEC') or die('Restricted access');

if (!class_exists('vmPSPlugin'))
    require(JPATH_VM_PLUGINS . DS . 'vmpsplugin.php');

if (!class_exists( 'VmConfig' ))
require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');


class plgVmCustomVmordersave extends vmPSPlugin {

    // instance of class
    public static $_this = false;

    function __construct(& $subject, $config) {
parent::__construct($subject, $config);
    }

 
function plgVmOnUpdateOrderPayment ($data,$old_order_status){
$status = $this->params->get('status', 'S');
if($data->order_status==$status){
                       //Do your stuff with $data
return;
        }

}else{// not "S"
return;
}

}



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

sandomatyas

Hi GJC

I'm ok with that, I created some other vmcustom plugins before.
But if I'm right, originally VMcustom plugins are for creating custom fields. When I create a vmcustom plugin as you wrote I can select it as a type of a custom field. Shouldn't be there an other plugin type for that case which isn't creates a 'side effect' like that?
Also using plgVmOnUpdateOrderPayment method name suggests me it is fired when a payment method is updated, but it doesn't change here. Or it is just plgVmOnUpdateOrderPayment as triggering a method from payment plugins and plgVmOnUpdateOrderShipment from shipment plugins when the order itself is updating? Yes, it is triggered no matter if the payment/shipment is changed or not, but the question is what is the purpose of this method originally?

I already noticed there are some imports for vmextended plugins too, but I can't find any info what are these plugins for?

So yeah, it works like this but I want to create a proper plugin :)

GJC Web Design

Your question was how to trigger a function when an order goes to Shipped .. this does that...

Plugins depend entirely on the triggers available ...  this is a trigger that is fired every time an order status changes ..
your welcome to search for others
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

sandomatyas

That's fine. But seems weird to me that VM displays my plugin when I try to add a "plug-ins type" custom field.

GJC Web Design

its not weird .. it is a custom plugin .. it just happens that the trigger at that point is only for custom plugins - which is why we use it.

If you can convince Max to call an extended etc at that point then we would use that.

U could actually try a system plugin extending vmplg -- I vaguely remember that these can use plgVm triggers and aren't filtered   -- although may have dreamt this...
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

sandomatyas

Quote from: GJC Web Design on October 30, 2018, 23:06:35 PM
its not weird .. it is a custom plugin .. it just happens that the trigger at that point is only for custom plugins - which is why we use it.

If you can convince Max to call an extended etc at that point then we would use that.

U could actually try a system plugin extending vmplg -- I vaguely remember that these can use plgVm triggers and aren't filtered   -- although may have dreamt this...

There are already several JPluginHelper::importPlugin('vmextended'); calls in the code like in VirtueMartModelInvoice, VirtueMartModelOrders, VirtueMartModelProduct etc
importPlugin for system plugins is only in VirtueMartControllerProductdetails.mailAskquestion()

So okay, I created a vmcustom plugin to do that and already told the customer not to create a cusomfiled with this type :D