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

Plugin development

Started by ermes, October 12, 2015, 19:45:25 PM

Previous topic - Next topic

ermes

Hi developers, what event is trigged on product saving? And how i can use it in plugin developing? My plugin is a vmcustom plugin (it extends vmCustomPlugin) for vm 3.x. Tnx!!

Studio 42

#1
Quote from: ermes on October 12, 2015, 19:45:25 PM
Hi developers, what event is trigged on product saving? And how i can use it in plugin developing? My plugin is a vmcustom plugin (it extends vmCustomPlugin) for vm 3.x. Tnx!!
JPluginHelper::importPlugin('vmcustom');
$dispatcher = JDispatcher::getInstance();
if (isset($datas['customfield_params']) and is_array($datas['customfield_params'])) {
foreach ($datas['customfield_params'] as $key => $plugin_param ) {
$dispatcher->trigger('plgVmOnStoreProduct', array($datas, $plugin_param ));
}
}


In your plugin : function plgVmOnStoreProduct($datas, $plugin_param)

Note ! this is not working correctly when you remove your plugin from list.
When you remove all plugin in a product 'customfield_params' is empty and you cannot use this to check if the plugin was removed ! And if you remove your own plugin, you have to check in another plugin for product ID and not return.
The only way is to set a "customfield_params" array reference outside the customfield HTML table, then you can check and/or delete.

If you use only standard customfield params and no additional table and checks, this work correctly.

Patrick.

ermes

Ok, now i can modify $plugin_param before save, but i don't know how to pass it at function (?) that save data into db.

This is my piece of code:

function plgVmOnStoreProduct($data, $plugin_param){
$plugin_param['json'] = json_encode($plugin_param['json_row']);
return $this->OnStoreProduct($data,$plugin_param);
}


I have to encode in JSON some data and store it into $plugin_param['json'].


Studio 42

WHy you want recall OnStoreProduct ?
Is this function in your plugin ?
If you need specific convertion or table then you have to write it yourself. This have nothing to do with VM.

ermes

Sorry, i'm not explained very well. I need to manipulate the data before store it into db. With plgVmOnStoreProduct function i can intercept $plugin_param and work on it, but i can't save it. I have already resolved with an sql query (in plgVmOnStoreProduct) but i not like it.

How can i save data intercepted via plgVmOnStoreProduct?

Studio 42

If you need to full intercepted all data, then write a system plugin. This is always called and before any other plugin/component.
you can chek here for the trigger :
https://docs.joomla.org/Plugin/Events/System

onAfterInitialise is the usable event for your case and you can manipulate the request data before VM get this.