$database->setQuery("INSERT INTO `#__virtuemart_products` (`virtuemart_product_id`, `virtuemart_vendor_id`,`product_parent_id`,`product_available_date`,`published`,`created_on`, `created_by`,`modified_on`, `modified_by`, `locked_on`, `locked_by`) values('', '1', '0','".JFactory::getDate()->toFormat()."','1', '".JFactory::getDate()->toFormat()."', '".$user->id."', '".JFactory::getDate()->toFormat()."', '".$user->id."', '0000-00-00 00:00:00', '0')");
$database->query();
$productid = $database->insertid();
if($productid>0)
{
$database->setQuery("INSERT INTO `#__virtuemart_product_prices` (`virtuemart_product_price_id`, `virtuemart_product_id`,`product_price`,`product_currency`,`created_on`, `created_by`,`modified_on`, `modified_by`, `locked_on`, `locked_by`) values('', '".$productid."','50.00000','144','0000-00-00 00:00:00','".$user->id."', '".JFactory::getDate()->toFormat()."', '".$user->id."', '0000-00-00 00:00:00', '0')");
$database->query();
$database->setQuery("INSERT INTO `#__virtuemart_product_categories` (`id`, `virtuemart_product_id`,`virtuemart_category_id`, `ordering`) values('', '".$productid."','".$categoryid."', '0')");
$database->query();
$database->setQuery("INSERT INTO `#__virtuemart_products_en_gb` (`virtuemart_product_id`,`product_s_desc`, `product_desc`,`product_name`,`metadesc`,`metakey`,`customtitle`,`slug`) values('".$productid."', 'ticket item','ticket item', 'support_ticket#".JRequest::getVar('tktid')."','ticket item','ticket item','ticket item','support#".JRequest::getVar('tktid')."')");
$database->query();
}
Details: In the above code i first insert required columns in vm product
table - virtuemart_products.If that successful, then i enter rows in other tables which is related with that virtuemart product.Some variables above i
set by my own which you need to do carefully when you assign.
If it helps to save your time, dont forget to share and like