VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Coding Central => Topic started by: sbou on March 02, 2016, 18:17:07 PM

Title: Trigger plgVmOnStoreProduct
Post by: sbou on March 02, 2016, 18:17:07 PM
Hi,

In the plugin plugins/vmcustom/specification/specification.php i can see a function probably call by a trigger:

function plgVmOnStoreProduct($data,$plugin_param){


But i don't see how is trigged this function.

I'm looking for a trigger in virtuemart onStoreProduct i need for a custom component.

Stéphane

Title: Re: Trigger plgVmOnStoreProduct
Post by: GJC Web Design on March 02, 2016, 23:34:32 PM
yes-- I've been confused/sad about this one

only available from administrator\components\com_virtuemart\models\customfields.php if a custom field is set

I don't know why

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 ));
         }
      }
Title: Re: Trigger plgVmOnStoreProduct
Post by: Studio 42 on March 03, 2016, 02:54:33 AM
Salut Stéphane,
plgVmOnStoreProduct permit to save in an external table for eg.
I use a hidden customfield_params in product  form that on save this is triggered and use another input name for the other fields
eg
<input type="hidden" name="customfield_params[45][255]">
<input type="text" name="my_plugin_name[45][255][position]" value="default">
<input type="text" name="my_plugin_name[45][255][date]" value="default">
.....
Title: Re: Trigger plgVmOnStoreProduct
Post by: GJC Web Design on March 03, 2016, 10:20:05 AM
nice!!!!!

excellent sideways thinking..  kudos and bookmarked  :)
Title: Re: Trigger plgVmOnStoreProduct
Post by: sbou on March 03, 2016, 10:36:36 AM
Hi Studio42,

I need to synchronize another table when the product stock or price change.
What do you think it's the best way to do this.

There are no trigger on product update.

Stéphane
Title: Re: Trigger plgVmOnStoreProduct
Post by: GJC Web Design on March 03, 2016, 10:41:28 AM
that's what he saying

use a hidden (dummy) customfield_params in the product form to call the customfields trigger
haven't tried...
Title: Re: Trigger plgVmOnStoreProduct
Post by: Studio 42 on March 03, 2016, 12:28:55 PM
If you need to trigger it in all products, then do not check for the plugin in onProductEdit function but use a static value in the plugin to prevent multiple add
set the hidden fields one time.
And use plgVmOnStoreProduct to get your values.

Another way is to use a Joomla system checking "task" and "option" input, but the problem is that the ID is only set after and VM redirect, so you can only check for updates and not for a new product.
Title: Re: Trigger plgVmOnStoreProduct
Post by: sbou on March 08, 2016, 13:42:04 PM
Hi,

I follow your idee and make a customvm plugin.

I use plgVmOnProductEdit to display some info i need to configure
and plgVmOnStoreProduct to trigger database save information when product is saved.

It's work fine when i save the product in virtuemart product page.

But the trigger are not send :
- when i update an order in backend manually
- when the product is purchased in front-end.

The idee is to save data in another table when the product quantidy is changed (backend or cart completed)

Stéphane


Stéphane
Title: Re: Trigger plgVmOnStoreProduct
Post by: GJC Web Design on March 08, 2016, 13:46:17 PM
investigate

plgVmOnUpdateSingleItem($data, $order) 
&& 
plgVmConfirmedOrder ($cart, $order)
Title: Re: Trigger plgVmOnStoreProduct
Post by: sbou on March 08, 2016, 14:12:40 PM
Thanks i was on plgVmGetProductStockToUpdateByCustom