Author Topic: [bug] Clone product with custom plugin (VM 2.0.7 - 2.0.12)  (Read 1738 times)

usovdm

  • 3rd party VirtueMart Developer
  • Beginner
  • *
  • Posts: 16
[bug] Clone product with custom plugin (VM 2.0.7 - 2.0.12)
« on: October 09, 2012, 11:38:59 am »
In version 2.0.7 there was a problem with cloning products with 3rd party custom plugins. It is actual and at present.

WHAT:
1. Custom plugin table and languages (translations) table using class VmTableData (extend JTable)
2. function JTable->reset() create a static variable $cache
3. When copying product at first customfields are copied, and then traslations. But when copied translations, VmTableData object already have static $cache and returned wrong DB fields from cache. Therefore we see error such as: "vmError: VmTableData::store failed - Unknown column 'XXX' in 'field list'..."

IDEAS
I think that it's a logic error. We shouldn't use one class VmTableData for customfields and translations.

MY SOLUTION
1. Redeclare function createPluginTableObject in plugin class. For my extension I have this code, where I replace VmTableData class for my class:
Code: [Select]
function createPluginTableObject ($tableName, $tableFields, $primaryKey, $tableId, $loggable = FALSE) {

$db = JFactory::getDBO ();
if(!class_exists('VmTable'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmtable.php');
if(!class_exists('VmTableData'))require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'vmtabledata.php');
// $table = new VmTableData($tableName, $tableId, $db);
$table = VmTable::getInstance('PlgVmCustomParam','Table');
foreach ($tableFields as $field) {
$table->$field = 0;
}
if ($primaryKey !== 0) {
$table->setPrimaryKey ($primaryKey);
}
if ($loggable) {
$table->setLoggable ();
}
if (!$this->_tableChecked) {
$this->onStoreInstallPluginTable ($this->_psType);
$this->_tableChecked = TRUE;
}
return $table;
}
2. Create second class in plugin file. Example of my extension:
Code: [Select]
class TablePlgVmCustomParam extends VmTableData{
var $id = 0;
var $virtuemart_product_id = 0;
var $virtuemart_custom_id = 0;
var $param = '';
var $value = '';
var $intvalue = 0;
var $ordering = 0;
var $published = 0;
var $created_on = null;
var $created_by = 0;
var $modified_on = null;
var $modified_by = 0;
var $locked_on = null;
var $locked_by = 0;

function __construct($db) {
parent::__construct('#__virtuemart_product_custom_plg_param', 'id', $db);
}
}


P.S. Developers, please give us a trigger event "plgVmOnCloneProduct" for copying plugins values.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9937
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [bug] Clone product with custom plugin (VM 2.0.7 - 2.0.12)
« Reply #1 on: October 17, 2012, 11:34:37 am »
Please contact me via skype, interesting ideas, and maybe the reason. But I do not really understand your solution.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/