Saturday, 03 August 2013 22:50

how to add products in virtuemart in joomla

Written by 
Rate this item
(0 votes)

Virtuemart 2 for joomla is a very good extension to sell products
through website.To add product manually by code, they have doc on
how to use the Api to achieve this, but it may be hard to implement
there Api to add product.So i show here how to do that without using
Api but the simpla way using sql queries -

$database = JFactory::getDBO();
$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')");

$productid = $database->insertid();

$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->setQuery("INSERT INTO `#__virtuemart_product_categories` (`id`, `virtuemart_product_id`,`virtuemart_category_id`, `ordering`) values('', '".$productid."','".$categoryid."', '0')");

$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')."')");

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

Read 2572 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments