VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: welrachid on August 31, 2018, 14:08:21 PM

Title: plgVmOnUpdateOrderShipment - getting vmconfig params for plugin
Post by: welrachid on August 31, 2018, 14:08:21 PM
Hi guys
i want to make use of plgVmOnUpdateOrderShipment to make sure that i always get a trigger when an order get statuschanged.
I need to make some action based on this and these are set up in the vm shipment plugin configuration:
  <vmconfig>
   <fields name="params">
      <fieldset name="orderstatuses">
         <field name="order_status_a" type="textarea" label="order_status_a" description="order_status_a" default=""/>
         ...etc...
      </fieldset>
   </fields>
  </vmconfig>

However whenever the plgVmOnUpdateOrderShipment method does not have any data on the params i have saved in the setup of the plugin

I've been looking into the code and looks like there are 3 triggers whenever a order status change is happening.
shipment,
payment,
coupon each have a plgVm method that is triggered
Payment seems to be stopping if some condition in the returnvalues is met.
Therefore i choose to make my plugin as a shipment plugin.

The problem is however that the saved plugin-parameters ( /administrator/index.php?option=com_virtuemart&view=shipmentmethod ) are not loaded anywhere and i have no idea how to retrieve the info to be able to take action on them.

Can anyone guide me the correct direction?

Thanks
Title: Re: plgVmOnUpdateOrderShipment - getting vmconfig params for plugin
Post by: GJC Web Design on August 31, 2018, 14:43:34 PM
something like

   $plugin2 = JPluginHelper::getPlugin('vmshipment', 'weight_countries');//this is the vmshipping plugin
   $paramsgjc2 = new JRegistry($plugin2->params);// the params
Title: Re: plgVmOnUpdateOrderShipment - getting vmconfig params for plugin
Post by: welrachid on August 31, 2018, 18:44:33 PM
okay
so you think i should make the plugin so that the param settings should be done in joomla general, not in the actual plugin-instance within VM?

Title: Re: plgVmOnUpdateOrderShipment - getting vmconfig params for plugin
Post by: GJC Web Design on September 01, 2018, 01:07:34 AM
Don't understand

this gets the params from any plugin from anywhere.. you can use as needed
Title: Re: plgVmOnUpdateOrderShipment - getting vmconfig params for plugin
Post by: Jörgen on September 01, 2018, 13:23:47 PM
Quote from: GJC Web Design on August 31, 2018, 14:43:34 PM
something like

   $plugin2 = JPluginHelper::getPlugin('vmshipment', 'weight_countries');//this is the vmshipping plugin
   $paramsgjc2 = new JRegistry($plugin2->params);// the params

Sorry to add to the confusion. This does not seem to get the params from a <vmconfig> section , it just accesses params declared in a <config> section of a xml file. I may be missing something, but that is what I can experience so far.

Jörgen @ Kreativ Fotografi
Title: Re: plgVmOnUpdateOrderShipment - getting vmconfig params for plugin
Post by: GJC Web Design on September 01, 2018, 14:34:45 PM
this could well be true-- never tested .. but I don't understand what params are required from where to be used where..  :(
Title: Re: plgVmOnUpdateOrderShipment - getting vmconfig params for plugin
Post by: Jörgen on September 01, 2018, 18:38:16 PM
The joomla params are "global" the vmconfig params can be specific for example each order row and need more keys to find the right one. Makes it a lot trickier to find the right one when you out of context in a module or component looking for custom field data.
Jörgen @ Kreativ Fotografi
Title: Re: plgVmOnUpdateOrderShipment - getting vmconfig params for plugin
Post by: welrachid on September 02, 2018, 09:03:16 AM
Hi guys.
Thanks for your time.

As Jörgen writes they code above gives me the joomla plugin-parameters which are global
What i would like to do is get a vm plugin instance parameters for each instance of the plugin.

See it like this:
I have a plugin called url-callback that i would like to add depending on which shopper it is.

So order status "E" i want it to call url1 if shopper is X and url2 if shopper is Y.

Normally i would have a $method (in the other triggers) but right here i dont have this.. so i was just wondering how do i determine which one "im currently in"
Title: Re: plgVmOnUpdateOrderShipment - getting vmconfig params for plugin
Post by: welrachid on September 06, 2018, 20:06:07 PM
Hi again.
So i thought i wanted to update you on the current solution on working on.

I actually make a sql directly to the db to get the info i want, then i decode the encoded plugin parameters..

   function plgVmOnUpdateOrderShipment($data, $old_order_status) {
      $db = JFactory::getDBO();
      $shipment_element = strtolower(str_ireplace("plgVmShipment","",get_class($this)));      
      $sql = 'SELECT * FROM `#__virtuemart_shipmentmethods` WHERE published=1 AND `shipment_element` LIKE "'.$shipment_element.'" order by ordering ASC';
      $db->setQuery( $sql );
      $shipments = $db->loadObjectList();
      $params =array();
      foreach($shipments as $shipment_plugin_data){
         $params_lines = explode("|",$shipment_plugin_data->shipment_params);
         foreach($params_lines as $line){
            if(!empty($line)){
               $param_data = explode("=",$line,2);
               $params[$param_data[0]] = substr($param_data[1],1,-1);
            }
         }
         $order_status_param = isset($params['order_status_'.strtolower($data->order_status)])?$params['order_status_'.strtolower($data->order_status)]:"";
                }
   }

Hopefully someone out there might be looking for a similar solution.