After reading the articles
- https://dev.virtuemart.net/projects/virtuemart/wiki/Developing_a_module_or_plugin_for_VirtueMart_2
- https://dev.virtuemart.net/projects/virtuemart/wiki/Product_Plugins
and editing a copy of the plugin 'textinput' I've created a custom plugin. It installs without errors, but the plugin doesn't save anything in the table when I delete a product.
Filename: vmdeleteimages.php
defined('_JEXEC') or die('Restricted access');
if (!class_exists('plgVmCustomDeleteImages')) require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
// Get the plugin library
jimport ('joomla.plugin.plugin');
class plgVmCustomDeleteImages extends vmCustomPlugin
{
function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
$this->loadLanguage();
}
function plgVmOnDeleteProduct()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$columns = array('naam');
$values = array('custom.message');
$query
->insert($db->quoteName('#__aa'))
->columns($db->quoteName($columns))
->values(implode(',', $values));
$db->setQuery($query);
$db->execute();
}
}
Filename: vmdeleteimages.xml
<?xml version="1.0" encoding="UTF-8" ?>
<extension version="1.5" type="plugin" group="vmcustom" >
<name>vmdeleteimages</name>
<creationDate>February 2021</creationDate>
<author>Me</author>
<authorUrl>https://test.com</authorUrl>
<copyright>Copyright (C) 2021. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<version>1.0</version>
<description>plugin vmdeleteimages</description>
<files>
<filename plugin="vmdeleteimages">vmdeleteimages.php</filename>
<folder>language</folder>
</files>
<params addpath="/administrator/components/com_virtuemart/elements">
<param type="vmjpluginwarning" />
</params>
</extension>
The xml example on http://dev.virtuemart.net/projects/virtuemart/wiki/Product_Plugins uses <install> instead of <extension>, but that gives an error when installing the plugin.
The trigger is correct I guess. I found it on https://forum.virtuemart.net/index.php?topic=101629.msg476096#msg476096
I'm not quite sure if the plugins is called when a product is deleted or if it's in the code lines.
What did I miss?
add something like
print 'Debug Line '.__LINE__.'$this->guests <pre>'; print_r ('FIRED'); print "</pre><br />\n";die();
after function plgVmOnDeleteProduct()
{
to see if it triggers
Thank you for the tip. I added the line as you mentioned, but nothing happens.
so that trigger isn't called by a delete... chk again in the products model
You can only use plgVmOnDeleteProduct if you have a customfield declared in the product, so it does not work on each deleted product
For your case, you need perhaps to create a standard system plugin and check the view+component+id .. but this is not safe because if you mass delete, it does not work
or add a dummy empty custom field to all products
or request that the trigger is enabled for any delete event
Thank you for your suggestions. A colleague came up with another solution: a Joomla plugin that adds a form field. Fill this field with a value when someone clicks on the Delete button. If this value is posted you know which items to delete.
Quote from: testy on February 26, 2021, 10:20:26 AM
Thank you for your suggestions. A colleague came up with another solution: a Joomla plugin that adds a form field. Fill this field with a value when someone clicks on the Delete button. If this value is posted you know which items to delete.
This is similar to the answer but solve not the problem when you mass delete products