Author Topic: Custom plugin doesn't save data  (Read 664 times)

testy

  • Beginner
  • *
  • Posts: 16
  • A beginner
Custom plugin doesn't save data
« 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?

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10133
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Custom plugin doesn't save data
« Reply #1 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
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

testy

  • Beginner
  • *
  • Posts: 16
  • A beginner
Re: Custom plugin doesn't save data
« Reply #2 on: February 02, 2021, 17:20:52 pm »
Thank you for the tip. I added the line as you mentioned, but nothing happens.

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10133
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Custom plugin doesn't save data
« Reply #3 on: February 02, 2021, 23:13:51 pm »
so that trigger isn't called by a delete...  chk again in the products model
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4448
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Custom plugin doesn't save data
« Reply #4 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

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10133
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: Custom plugin doesn't save data
« Reply #5 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
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

testy

  • Beginner
  • *
  • Posts: 16
  • A beginner
Re: Custom plugin doesn't save data
« Reply #6 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.

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4448
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Custom plugin doesn't save data
« Reply #7 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