私はこのようなことをしました。私は迅速で(むしろ)汚いが実用的な解決策を持っています:
<?php
function createOffer($account_id,$subject,$offerlanguage, $totalamount,$date_submission,$date_decision,$date_start,$assigned_user_id,$quotestage,$winningchance,$description,$productarray){
global $adb;
$endpointUrl = "[your URL]/webservice.php";
$userName="admin";
$userAccessKey = '[your accesskey]';
$httpc = new HTTP_CLIENT();
//getchallenge request must be a GET request.
$httpc->GET($endpointUrl."?operation=getchallenge&username=".$userName);
$response = $httpc->currentResponse();
//decode the json encode response from the server.
$jsonResponse = Zend_JSON::decode($response['body']);
//check for whether the requested operation was successful or not.
if($jsonResponse['success']==false)
//handle the failure case.
die('getchallenge failed:'.$jsonResponse['error']['errorMsg']);
//operation was successful get the token from the reponse.
$challengeToken = $jsonResponse['result']['token'];
//create md5 string concatenating user accesskey from my preference page
//and the challenge token obtained from get challenge result.
$generatedKey = md5($challengeToken.$userAccessKey);
//getchallenge request must be a GET request.
$httpc->post("$endpointUrl",
array('operation'=>'login', 'username'=>$userName, 'accessKey'=>$generatedKey), true);
$response = $httpc->currentResponse();
//decode the json encode response from the server.
$jsonResponse = Zend_JSON::decode($response['body']);
//operation was successful get the token from the reponse.
if($jsonResponse['success']==false)
//handle the failure case.
die('login failed:'.$jsonResponse['error']['errorMsg']);
//login successful extract sessionId and userId from LoginResult to it can used for further calls.
$sessionId = $jsonResponse['result']['sessionName'];
$userId = $jsonResponse['result']['userId'];
$currency_id=1;
$params = array('description'=>$description,'subject'=>$subject,'quotestage'=>$quotestage,'assigned_user_id'=>'2x'.$assigned_user_id,'account_id'=>'3x'.$account_id,'cf_682'=>$offerlanguage,'currency_id'=>'21x'.$currency_id,'taxtype'=>'group','cf_683'=>$date_submission,'cf_684'=>$date_decision,'cf_685'=>$date_start,'cf_766'=>$winningchance);
$urlArgs = "?&total=".$totalamount;
//encode the object in JSON format to communicate with the server.
$objectJson = Zend_JSON::encode($params);
//name of the module for which the entry has to be created.
$moduleName = 'Quotes';
//sessionId is obtained from loginResult.
$params = array("sessionName"=>$sessionId, "operation"=>'create', "element"=>$objectJson, "elementType"=>$moduleName);
//Create must be POST Request.
$httpc->post($endpointUrl.$urlArgs, $params, true);
$response = $httpc->currentResponse();
//decode the json encode response from the server.
$jsonResponse = Zend_JSON::decode($response['body']);
$savedObject = $jsonResponse['result'];
$id = $savedObject['id'];
$id=str_replace("13x", "", $id);
echo $id." offer: ".$subject." created for amount ".$totalamount." for customer: ".$account_id." assigned to: ".$assigned_user_id;
return $id;
}
ご覧のとおり、カスタム フィールドもいくつかあるので、それらをどのように処理したかがわかります。
この関数は次のように呼び出すことができます。
createOffer($account_id, $subject, $offerlanguage, $totalamount, $date_submission, $date_decision, $date_start, $assigned_user_id, $quotestage, $winningchance, $description, $productarray)
次に、製品も追加する必要があります。これは、見積もりごとにより多くの製品がある可能性があるため、別の関数を介して最も簡単であることがわかりました...
<?php
function createProducts($productarray,$id) {
$counter = 1;
foreach ($productarray as $prod) {
$query ="insert into vtiger_inventoryproductrel(id, productid, sequence_no, quantity, listprice) values(?,?,?,?,?)";
$qparams = array($id,$prod['prod'],$counter,$prod['pcs'],$prod['price']);
$productadded=$adb->pquery($query,$qparams);
$counter=$counter+1;
}
}
次のように使用します。
$prodlist = array();
array_push($prodlist,array('prod'=>"prod1",'pcs'=>2,'price'=>1000));
array_push($prodlist,array('prod'=>"prod2",'pcs'=>2,'price'=>100));
createProducts($prodlist,10);
私のロジックは次のようになります。
- createOffer 関数を使用して見積もりを作成します。新しく作成された見積もりの ID を返します
- 次に、製品の配列を作成し (ここには非常に基本的なデータしかありません)、見積もりの ID を参照して追加します。
おそらく最も美しいソリューションではありませんが、機能します。