News:

Support the VirtueMart project and become a member

Main Menu

Custom plugin doesn't save data

Started by Ro Bert, February 02, 2021, 10:48:55 AM

Previous topic - Next topic

Ro Bert

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


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?

GJC Web Design

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
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Ro Bert

Thank you for the tip. I added the line as you mentioned, but nothing happens.

GJC Web Design

so that trigger isn't called by a delete...  chk again in the products model
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

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

GJC Web Design

or add a dummy empty custom field to all products

or request that the trigger is enabled for any delete event
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Ro Bert

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.

Studio 42

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