I wrote this code to create a new child product by code
$joomlaPath = VIRTUEMART_ROOT;
define('_JEXEC', 1);
if (file_exists($joomlaPath . '/defines.php')) {
include_once $joomlaPath . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', $joomlaPath);
require_once JPATH_BASE.'/includes/defines.php';
}
require_once JPATH_BASE.'/includes/framework.php';
// Instantiate the application.
$app = JFactory::getApplication('site');
// Initialise the application.
$app->initialise();
#log come utente amministratore
$credentials = array();
$credentials['username'] = VIRTUEMART_ADMIN_USER;
$credentials['password'] = VIRTUEMART_ADMIN_PASSWORD;
if($app->login($credentials) == 1) {
# apertura del db
$db = JFactory::getDBO();
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
$config = VmConfig::loadConfig();
$product = VmModel::getModel('product');
$msgtype = '';
$token=JUtility::getToken();
JRequest::setVar($token, '1', 'post');
#clonazione del template per il servizio
$new_id=$product->createChild((int)VIRTUEMART_SERVICE_PARENT_PRODUCT_ID);
$new_id=(int)$new_id;
if ($new_id) {
$now=date("d-m-Y H:i:s");
$this->VirtuemartCategory=ClassRegistry::init('VirtuemartCategory');
#dati del parent product
$this->VirtuemartProduct=ClassRegistry::init('VirtuemartProduct');
$parent_product=$this->VirtuemartProduct->find('first',array('conditions'=>'VirtuemartProduct.virtuemart_product_id='.VIRTUEMART_SERVICE_PARENT_PRODUCT_ID));
$original_panel=$this->VirtuemartProduct->find('first',array('conditions'=>'VirtuemartProduct.virtuemart_product_id='.
$order['Order']['virtuemart_product_id'],'recursive'=>0));
$s_description=$parent_product['VirtuemartProductsItIt']['product_s_desc'];
$tags['{order_code}']=$order['Order']['code'];
$tags['{order_link}']=Router::url(array('controller'=>'orders','action'=>'view_order',$order['Order']['code']));
#valorizzazione del product clonato
$data=array();
$data['virtuemart_manufacturer_id']=4; #Altro
$data['virtuemart_product_id']=$new_id;
$data['product_parent_id']=VIRTUEMART_SERVICE_PARENT_PRODUCT_ID;
$data['product_sku']=$order['Order']['code'];
if(!empty($original_panel)){
$data['product_name']='Lavorazione ['.$order['Order']['code'].']: '.$original_panel['VirtuemartProductsItIt']['product_name'].' '.$now;
}else {
$data['product_name']='Lavorazione ['.$order['Order']['code'].']: '.$order['Piece']['h'].'x'.$order['Piece']['l'].'x'.$order['Piece']['p'].' '.$now;
}
$data['customtitle']='generato_il_'.$now;
$data['intnotes']='';
$data['mprices']['virtuemart_product_price_id'][0]='';
$data['mprices']['product_currency'][0]=(int)VIRTUEMART_DEFAULT_CURRENCY; #euro
$data['mprices']['product_price'][0]=$cuts_price;
$data['mprices']['override'][0]='';
//$vm_product_category_id=$this->VirtuemartCategory->get_VM_Parent_Category_Id();
//$data['categories']=array($vm_product_category_id);
$data['product_in_stock']=9999;
$data['product_s_desc']=str_replace(array_keys($tags),array_values($tags),$s_description);;
#invia il token come post
$data['token']=$token;
$data[$token]=1;
$data['mprices']['[virtuemart_shoppergroup_id'][0]='';
$data['published']=1;
if(!$product->store($data,true)) {
$error=true;
$msg="Errore nel salvataggio di alcune informazioni";
}
#logout
if($app->logout()){
#aggiunge il servizio al carrello e ritorno a alla pagina del prodotto
$product_pid=$order['Order']['virtuemart_product_id'];
$order_product_pid=$new_id;
$out=array('code'=>0,'msg'=>$msg, 'product_pid'=>$product_pid,'order_product_pid'=>$order_product_pid);
}else {
$error=true;
$msg='Errore nella disconnessione dalla piattaforma';
}
}
}
On production environment ( using LiteSpeed webserver) function createChild gives error ... but I can not figure out what!
At the end of the procedure, therefore, I am just a new generic product , with no new value saved
Locally (using apache webserver), with the same db, everything works fine.
How do I figure out what prevents the saving of the details of the new product created?
In the production environment (that is hosting a) are not too free to experiment
Do you have tips, helpful ideas?
Thanks for the support
Gianluca
are still looking for a real solution...
however, I discovered that the problem seems to be related with some locks that were still pending on db
Someone more experienced than me in the VirtueMart code is able to tell me if the code Joomla / Virtuemart written for the creation of a child product is missing something or is the cause of creating locks?
I would also be useful to know if i should post this in a different forum
Thanks for the help
Gianluca