News:

Support the VirtueMart project and become a member

Main Menu

Dispatch event is missing.

Started by hradigital, March 09, 2017, 00:51:11 AM

Previous topic - Next topic

hradigital

Being working on an implementation of VirtueMart, I've realized that a dispatch event is missing when editing/saving a product in the database.

When a product is deleted, an event is dispatch (plgVmOnDeleteProduct) with the product's ID, but not when one is created/edited.
The correct event name for this would be (plgVmOnStoreProduct), to follow the same naming convention, but as it is already being used, I suggest (plgVmOnEditProduct).

To dispatch this new event, new code should be added to the product.php Model class, in the store() method.
With current VirtueMart version I have, it should be placed on line 2033, just above the return statement of the store() method.
The could could be as follows:

JPluginHelper::importPlugin('vmcustom');
$dispatcher = JDispatcher::getInstance ();
$dispatcher->trigger('plgVmOnEditProduct', [$data]);


Final code, with previous and following statements is as follows.
$cache = JFactory::getCache('com_virtuemart_cat_manus','callback');
$cache->clean();

JPluginHelper::importPlugin('vmcustom');
$dispatcher = JDispatcher::getInstance ();
$dispatcher->trigger('plgVmOnEditProduct', [$data]);

return $product_data->virtuemart_product_id;


PS: Before finding this problem, I saw a lot of people trying to find a solution for this as well.
Hope this small contribution helps your product, even if a little bit.

hradigital

The supplied $data array, could be the $product (record).
Developers should choose which one fits better for this functionality.