VirtueMart Forum

VirtueMart 2 + 3 => Plugins: Payment, Shipment and others => Topic started by: testy on February 02, 2021, 10:48:55 am

Title: Custom plugin doesn't save data
Post by: testy on February 02, 2021, 10:48:55 am
After reading the articles
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

Code: [Select]
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

Code: [Select]
<?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?
Title: Re: Custom plugin doesn't save data
Post by: GJC Web Design on February 02, 2021, 12:25:20 pm
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
Title: Re: Custom plugin doesn't save data
Post by: testy on February 02, 2021, 17:20:52 pm
Thank you for the tip. I added the line as you mentioned, but nothing happens.
Title: Re: Custom plugin doesn't save data
Post by: GJC Web Design on February 02, 2021, 23:13:51 pm
so that trigger isn't called by a delete...  chk again in the products model
Title: Re: Custom plugin doesn't save data
Post by: Studio 42 on February 03, 2021, 00:01:08 am
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
Title: Re: Custom plugin doesn't save data
Post by: GJC Web Design on February 03, 2021, 15:19:44 pm
or add a dummy empty custom field to all products

or request that the trigger is enabled for any delete event
Title: Re: Custom plugin doesn't save data
Post by: 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.
Title: Re: Custom plugin doesn't save data
Post by: Studio 42 on March 03, 2021, 11:54:36 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