[bug] Clone product with custom plugin (VM 2.0.7 - 2.0.12)

Started by usovdm, October 09, 2012, 11:38:59 AM

Previous topic - Next topic

usovdm

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:
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:
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

Please contact me via skype, interesting ideas, and maybe the reason. But I do not really understand your solution.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/