News:

Support the VirtueMart project and become a member

Main Menu

Error in vmcustomplugin.php on line 187.

Started by prombez, January 20, 2012, 10:31:26 AM

Previous topic - Next topic

prombez

Joomla: Joomla! 1.7.3 Stable [ Ember ] 14-Nov-2011 14:00 GMT
VM: 2.0
Use custom field - type Plugins
Plugin = Custom product specification

On save product - PHP Fatal error:  Cannot access protected property VmTableData::$_db
File: /administrator/components/com_virtuemart/plugins/vmcustomplugin.php
Old (not work)
$custom_id = $values['virtuemart_custom_id'];
if( !empty($custom_id) && !empty($product_id) ){
$_qry = 'SELECT `id` FROM `#__virtuemart_product_custom_plg_'.$this->_name.'` WHERE `virtuemart_product_id`='.(int)$product_id.' and `virtuemart_custom_id`='.(int)$custom_id ;
$this->_vmpItable->_db->setQuery($_qry);
$id = $this->_vmpItable->_db->loadResult();
}

// $this->_vmpItable->setError($_qry,'$_qry');

if ( !empty($id) ) {
$this->_vmpItable->id = $id;
$returnCode = $this->_vmpItable->_db->updateObject($this->_vmpItable->_tbl, $this->_vmpItable, 'id', false);
} else {
$returnCode = $this->_vmpItable->_db->insertObject($this->_vmpItable->_tbl, $this->_vmpItable, 'id');
}

if (!$returnCode) {
$this->_vmpItable->setError(get_class($this) . '::store failed - ' . $this->_vmpItable->_db->getErrorMsg());
return false;
}
else
return true;

New:
                        $db = & JFactory::getDBO();
$custom_id = $values['virtuemart_custom_id'];
if( !empty($custom_id) && !empty($product_id) ){
$_qry = 'SELECT `id` FROM `#__virtuemart_product_custom_plg_'.$this->_name.'` WHERE `virtuemart_product_id`='.(int)$product_id.' and `virtuemart_custom_id`='.(int)$custom_id ;
$db->setQuery($_qry);
$id = $db->loadResult();
}

// $this->_vmpItable->setError($_qry,'$_qry');

if ( !empty($id) ) {
$this->_vmpItable->id = $id;
$returnCode = $db->updateObject($this->_tablename, $this->_vmpItable, 'id', false);
} else {
$returnCode = $db->insertObject($this->_tablename, $this->_vmpItable, 'id');
}

if (!$returnCode) {
$db->setError(get_class($this) . '::store failed - ' . $db->getErrorMsg());
return false;
}
else
return true;