Author Topic: Custom script after updating an order  (Read 328 times)

sandomatyas

  • Jr. Member
  • **
  • Posts: 232
Custom script after updating an order
« on: October 29, 2018, 21:33:47 pm »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8433
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.14
Re: Custom script after updating an order
« Reply #1 on: October 29, 2018, 23:04:36 pm »
vmcustom plugin will work

here's a start:

Code: [Select]

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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

sandomatyas

  • Jr. Member
  • **
  • Posts: 232
Re: Custom script after updating an order
« Reply #2 on: October 30, 2018, 09:00:10 am »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8433
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.14
Re: Custom script after updating an order
« Reply #3 on: October 30, 2018, 11:40:25 am »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

sandomatyas

  • Jr. Member
  • **
  • Posts: 232
Re: Custom script after updating an order
« Reply #4 on: October 30, 2018, 21:02:35 pm »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 8433
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.14
Re: Custom script after updating an order
« Reply #5 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...
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

sandomatyas

  • Jr. Member
  • **
  • Posts: 232
Re: Custom script after updating an order
« Reply #6 on: October 31, 2018, 07:15:31 am »
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