pouc Posted February 11, 2014 Share Posted February 11, 2014 (edited) Bonjour , Est-ce que vous sauriez pourquoi prestashop renvoi un fichier xmp au lieu d'un fichier xml exemple: Avec en corps : <prestashop><address><id_customer>89</id_customer><id_country>8</id_country><alias>Adresse de livraison</alias><firstname>-</firstname><lastname>FLETest</lastname><address1>11 rue Arthur III</address1><postcode>44200</postcode><city>Nantes</city></address></prestashop> Réponse de Prestashop: <xmp style="text-align: left;">Array( [object] => Address Object ( [id_customer] => 89 [id_manufacturer] => [id_supplier] => [id_warehouse] => [id_country] => 8 [id_state] => [country] => [alias] => Adresse de livraison [company] => [lastname] => FLETest [firstname] => - [address1] => 11 rue Arthur III [address2] => [postcode] => 44200 [city] => Nantes [other] => [phone] => [phone_mobile] => [vat_number] => [dni] => [date_add] => 2014-02-11 10:49:44 [date_upd] => 2014-02-11 10:49:44 [deleted] => [_includeVars:protected] => Array ( [addressType] => table ) [_includeContainer:protected] => [webserviceParameters:protected] => Array ( [objectsNodeName] => addresses [fields] => Array ( [id_customer] => Array ( [xlink_resource] => customers ) [id_manufacturer] => Array ( [xlink_resource] => manufacturers ) [id_supplier] => Array ( [xlink_resource] => suppliers ) [id_warehouse] => Array ( [xlink_resource] => warehouse ) [id_country] => Array ( [xlink_resource] => countries ) [id_state] => Array ( [xlink_resource] => states ) ) ) [id] => 110 [id_lang:protected] => [id_shop:protected] => [id_shop_list] => [get_shop_from_context:protected] => 1 [table:protected] => address [identifier:protected] => id_address [fieldsRequired:protected] => Array ( [0] => id_country [1] => alias [2] => lastname [3] => firstname [4] => address1 [5] => city ) [fieldsSize:protected] => Array ( [alias] => 32 [company] => 64 [lastname] => 32 [firstname] => 32 [address1] => 128 [address2] => 128 [postcode] => 12 [city] => 64 [other] => 300 [phone] => 32 [phone_mobile] => 32 [dni] => 16 ) [fieldsValidate:protected] => Array ( [id_customer] => isNullOrUnsignedId [id_manufacturer] => isNullOrUnsignedId [id_supplier] => isNullOrUnsignedId [id_warehouse] => isNullOrUnsignedId [id_country] => isUnsignedId [id_state] => isNullOrUnsignedId [alias] => isGenericName [company] => isGenericName [lastname] => isName [firstname] => isName [vat_number] => isGenericName [address1] => isAddress [address2] => isAddress [postcode] => isPostCode [city] => isCityName [other] => isMessage [phone] => isPhoneNumber [phone_mobile] => isPhoneNumber [dni] => isDniLite [deleted] => isBool [date_add] => isDateFormat [date_upd] => isDateFormat ) [fieldsRequiredLang:protected] => Array ( ) [fieldsSizeLang:protected] => Array ( ) [fieldsValidateLang:protected] => Array ( ) [tables:protected] => Array ( ) [image_dir:protected] => [image_format:protected] => jpg [def:protected] => Array ( [table] => address [primary] => id_address [fields] => Array ( [id_customer] => Array ( [type] => 1 [validate] => isNullOrUnsignedId [copy_post] => ) [id_manufacturer] => Array ( [type] => 1 [validate] => isNullOrUnsignedId [copy_post] => ) [id_supplier] => Array ( [type] => 1 [validate] => isNullOrUnsignedId [copy_post] => ) [id_warehouse] => Array ( [type] => 1 [validate] => isNullOrUnsignedId [copy_post] => ) [id_country] => Array ( [type] => 1 [validate] => isUnsignedId [required] => 1 ) [id_state] => Array ( [type] => 1 [validate] => isNullOrUnsignedId ) [alias] => Array ( [type] => 3 [validate] => isGenericName [required] => 1 => 32 ) [company] => Array ( [type] => 3 [validate] => isGenericName => 64 ) [lastname] => Array ( [type] => 3 [validate] => isName [required] => 1 => 32 ) [firstname] => Array ( [type] => 3 [validate] => isName [required] => 1 => 32 ) [vat_number] => Array ( [type] => 3 [validate] => isGenericName ) [address1] => Array ( [type] => 3 [validate] => isAddress [required] => 1 => 128 ) [address2] => Array ( [type] => 3 [validate] => isAddress => 128 ) [postcode] => Array ( [type] => 3 [validate] => isPostCode => 12 ) [city] => Array ( [type] => 3 [validate] => isCityName [required] => 1 => 64 ) [other] => Array ( [type] => 3 [validate] => isMessage => 300 ) [phone] => Array ( [type] => 3 [validate] => isPhoneNumber => 32 ) [phone_mobile] => Array ( [type] => 3 [validate] => isPhoneNumber => 32 ) [dni] => Array ( [type] => 3 [validate] => isDniLite => 16 ) [deleted] => Array ( [type] => 2 [validate] => isBool [copy_post] => ) [date_add] => Array ( [type] => 5 [validate] => isDateFormat [copy_post] => ) [date_upd] => Array ( [type] => 5 [validate] => isDateFormat [copy_post] => ) ) [classname] => Address ) [update_fields:protected] => ) [cookie] => Cookie Object ( [_content:protected] => Array ( [id_lang] => 1 [id_currency] => 1 [date_add] => 2014-01-22 18:49:48 [id_customer] => 49 [customer_lastname] => Coste [customer_firstname] => Jean-Dominique [passwd] => c82127ce15cbb624e4c03e89a7dc83ed [logged] => 1 => [is_guest] => [id_guest] => 232 [id_connections] => 501 [id_cart] => 13 [id_country] => 8 [id_state] => 0 [postcode] => [last_visited_category] => 7 [checksum] => 361385976 ) [_name:protected] => d016c4f59c9c5afccdfacac7a5eaeabb [_expire:protected] => 1393840184 [_domain:protected] => [_path:protected] => / [_cipherTool:protected] => Rijndael Object ( [_key:protected] => tI0t7Jmv9I1WqN5MrM5gAivpuHxjv1t8 [_iv:protected] => �/{���� ?�J�此 ) [_modified:protected] => [_allow_writing:protected] => 1 [_salt:protected] => NYaiG3TD [_standalone:protected] => ) [cart] => [altern] => 1)</xmp><br /><xmp style="text-align: left;">Array( [object] => Address Object ( [id_customer] => 89 [id_manufacturer] => [id_supplier] => [id_warehouse] => [id_country] => 8 [id_state] => [country] => [alias] => Adresse de livraison [company] => [lastname] => FLETest [firstname] => - [address1] => 11 rue Arthur III [address2] => [postcode] => 44200 [city] => Nantes [other] => [phone] => [phone_mobile] => [vat_number] => [dni] => [date_add] => 2014-02-11 10:49:44 [date_upd] => 2014-02-11 10:49:44 [deleted] => [_includeVars:protected] => Array ( [addressType] => table ) [_includeContainer:protected] => [webserviceParameters:protected] => Array ( [objectsNodeName] => addresses [fields] => Array ( [id_customer] => Array ( [xlink_resource] => customers ) [id_manufacturer] => Array ( [xlink_resource] => manufacturers ) [id_supplier] => Array ( [xlink_resource] => suppliers ) [id_warehouse] => Array ( [xlink_resource] => warehouse ) [id_country] => Array ( [xlink_resource] => countries ) [id_state] => Array ( [xlink_resource] => states ) ) ) [id] => 110 [id_lang:protected] => [id_shop:protected] => [id_shop_list] => [get_shop_from_context:protected] => 1 [table:protected] => address [identifier:protected] => id_address [fieldsRequired:protected] => Array ( [0] => id_country [1] => alias [2] => lastname [3] => firstname [4] => address1 [5] => city ) [fieldsSize:protected] => Array ( [alias] => 32 [company] => 64 [lastname] => 32 [firstname] => 32 [address1] => 128 [address2] => 128 [postcode] => 12 [city] => 64 [other] => 300 [phone] => 32 [phone_mobile] => 32 [dni] => 16 ) [fieldsValidate:protected] => Array ( [id_customer] => isNullOrUnsignedId [id_manufacturer] => isNullOrUnsignedId [id_supplier] => isNullOrUnsignedId [id_warehouse] => isNullOrUnsignedId [id_country] => isUnsignedId [id_state] => isNullOrUnsignedId [alias] => isGenericName [company] => isGenericName [lastname] => isName [firstname] => isName [vat_number] => isGenericName [address1] => isAddress [address2] => isAddress [postcode] => isPostCode [city] => isCityName [other] => isMessage [phone] => isPhoneNumber [phone_mobile] => isPhoneNumber [dni] => isDniLite [deleted] => isBool [date_add] => isDateFormat [date_upd] => isDateFormat ) [fieldsRequiredLang:protected] => Array ( ) [fieldsSizeLang:protected] => Array ( ) [fieldsValidateLang:protected] => Array ( ) [tables:protected] => Array ( ) [image_dir:protected] => [image_format:protected] => jpg [def:protected] => Array ( [table] => address [primary] => id_address [fields] => Array ( [id_customer] => Array ( [type] => 1 [validate] => isNullOrUnsignedId [copy_post] => ) [id_manufacturer] => Array ( [type] => 1 [validate] => isNullOrUnsignedId [copy_post] => ) [id_supplier] => Array ( [type] => 1 [validate] => isNullOrUnsignedId [copy_post] => ) [id_warehouse] => Array ( [type] => 1 [validate] => isNullOrUnsignedId [copy_post] => ) [id_country] => Array ( [type] => 1 [validate] => isUnsignedId [required] => 1 ) [id_state] => Array ( [type] => 1 [validate] => isNullOrUnsignedId ) [alias] => Array ( [type] => 3 [validate] => isGenericName [required] => 1 => 32 ) [company] => Array ( [type] => 3 [validate] => isGenericName => 64 ) [lastname] => Array ( [type] => 3 [validate] => isName [required] => 1 => 32 ) [firstname] => Array ( [type] => 3 [validate] => isName [required] => 1 => 32 ) [vat_number] => Array ( [type] => 3 [validate] => isGenericName ) [address1] => Array ( [type] => 3 [validate] => isAddress [required] => 1 => 128 ) [address2] => Array ( [type] => 3 [validate] => isAddress => 128 ) [postcode] => Array ( [type] => 3 [validate] => isPostCode => 12 ) [city] => Array ( [type] => 3 [validate] => isCityName [required] => 1 => 64 ) [other] => Array ( [type] => 3 [validate] => isMessage => 300 ) [phone] => Array ( [type] => 3 [validate] => isPhone ) [phone_mobile] => Array ( [type] => 3 [validate] => isPhoneNumber => 32 ) [dni] => Array ( [type] => 3 [validate] => isDniLite => 16 ) [deleted] => Array ( [type] => 2 [validate] => isBool [copy_post] => ) [date_add] => Array ( [type] => 5 [validate] => isDateFormat [copy_post] => ) [date_upd] => Array ( [type] => 5 [validate] => isDateFormat [copy_post] => ) ) [classname] => Address ) [update_fields:protected] => ) [cookie] => Cookie Object ( [_content:protected] => Array ( [id_lang] => 1 [id_currency] => 1 [date_add] => 2014-01-22 18:49:48 [id_customer] => 49 [customer_lastname] => Coste [customer_firstname] => Jean-Dominique [passwd] => c82127ce15cbb624e4c03e89a7dc83ed [logged] => 1 => [is_guest] => [id_guest] => 232 [id_connections] => 501 [id_cart] => 13 [id_country] => 8 [id_state] => 0 [postcode] => [last_visited_category] => 7 [checksum] => 361385976 ) [_name:protected] => d016c4f59c9c5afccdfacac7a5eaeabb [_expire:protected] => 1393840184 [_domain:protected] => [_path:protected] => / [_cipherTool:protected] => Rijndael Object ( [_key:protected] => tI0t7Jmv9I1WqN5MrM5gAivpuHxjv1t8 [_iv:protected] => �/{���� ?�J�此 ) [_modified:protected] => [_allow_writing:protected] => 1 [_salt:protected] => NYaiG3TD [_standalone:protected] => ) [cart] => [altern] => 1)</xmp><br /><?xml version="1.0" encoding="UTF-8"?><prestashop xmlns:xlink=""><address> <id><![CDATA[110]]></id> <id_customer xlink:href=""><![CDATA[89]]></id_customer> <id_manufacturer></id_manufacturer> <id_supplier></id_supplier> <id_warehouse></id_warehouse> <id_country xlink:href=""><![CDATA[8]]></id_country> <id_state></id_state> <alias><![CDATA[Adresse de livraison]]></alias> <company></company> <lastname><![CDATA[FLETest]]></lastname> <firstname><![CDATA[-]]></firstname> <vat_number></vat_number> <address1><![CDATA[11 rue Arthur III]]></address1> <address2></address2> <postcode><![CDATA[44200]]></postcode> <city><![CDATA[Nantes]]></city> <other></other> <phone></phone> <phone_mobile></phone_mobile> <dni></dni> <deleted></deleted> <date_add><![CDATA[2014-02-11 10:49:44]]></date_add> <date_upd><![CDATA[2014-02-11 10:49:44]]></date_upd></address></prestashop> Merci. Edited March 4, 2014 by pouc (see edit history) Link to comment Share on other sites More sharing options...
Prestaspirit Posted February 11, 2014 Share Posted February 11, 2014 Bonjour, Je serais curieux de voir votre code mais une chose est sur ce n'est pas prestashop qui vous renvoi la première partie de la réponse, prestashop renvoi seulement la partie xml, vous avez surement du code qui transforme ce retour. Link to comment Share on other sites More sharing options...
pouc Posted February 11, 2014 Author Share Posted February 11, 2014 Et d’où pourrait provenir ce code vous pensez? Link to comment Share on other sites More sharing options...
Prestaspirit Posted February 11, 2014 Share Posted February 11, 2014 Ma boule de cristal ne m'indique rien pour le moment mais peut être qu'avec votre code le brouillard va ce dissiper Link to comment Share on other sites More sharing options...
pouc Posted February 11, 2014 Author Share Posted February 11, 2014 c'est pas faux!! Pour la petite histoire c'est une entreprise externe qui réalise le transfert de la BDD client vers prestashop qui ont créée un module pour que chaque client ayant été ajouté par eux puisse être notifié. Ensuite ayant fais une modification sur la page admincustomer pour filtrer les clients par employés en suivant ce topic :http://www.prestashop.com/forums/topic/164166-filtre-sur-liste-clients-dans-ladmin/ est ce que vous pensez que sa pourrait agir sur le problème? Et du coup quel partie du code je devrais vous envoyer? Link to comment Share on other sites More sharing options...
Prestaspirit Posted February 11, 2014 Share Posted February 11, 2014 Non je ne pesne pas que ce soit lié enfin à priori non. le code que vous indiquez est un retour de l'api prestashop, le code interressant est celui qui affiche ce retour et les quelques lignes ci-dessus qui pourrait modifier ce retour Link to comment Share on other sites More sharing options...
pouc Posted February 11, 2014 Author Share Posted February 11, 2014 Ok du coup j'ai trouvé deux fichier je sais pas trop lequel pourrait être le bon, je vous copie le code d'un et si ce n'est pas ça je vous transmettrais le deuxième. <?php//require_once 'config.php';// if (session_status() !== PHP_SESSION_ACTIVE) {session_start();}/*if(!isset($_SESSION) || empty($_SESSION)) { session_start();}*/if(!session_id()) { session_start();}define('__PS_EXTERNALID__', 'ps_externalid');define('__SF_OBJECTTYPE__', 'sf_objecttype');define('__Attributes__', 'attributes');define('__SF_ID__', 'sf_id');define('__PRODUCT__', 'Product');define('__OPPORTUNITY__', 'Opportunity');define('__OPPORTUNITYLINEITEM__', 'OpportunityLineItem');define('__OPPLIATTR_QUANTITY__', 'Quantity');define('__OPPLIATTR_TOTAL_PRICE__', 'TotalPrice');define('__OPPLIATTR_TOTAL_WT__', 'total_wt');define('__OPPLIATTR_ID_PRODUCT__', 'id_product');define('__OPPLIATTR_OPPORTUNITY__', 'Opportunity');define('__OPPLIATTR_PRICEBOOKENTRYID__', 'PRICEBOOKENTRYID');function InsertId($ps_externalid, $sf_objecttype, $sf_id, $attributes = null, $ParentExternalID = null){ if($sf_id != null && $sf_id != ''){ $sql = 'INSERT into `' . _DB_PREFIX_ . 'sf_connector` ('; $sql .= '`ps_externalid`, '; $sql .= '`sf_objecttype`, '; $sql .= '`sf_id`, '; $sql .= '`attributes`, '; $sql .= '`ps_parentexternalid`'; $sql .= ') VALUES ('; $sql .= '\'' . pSQL($ps_externalid) . '\''; $sql .= ',\'' . pSQL($sf_objecttype) . '\''; $sql .= ',\'' . pSQL($sf_id) . '\''; $sql .= ',\'' . pSQL($attributes) . '\''; $sql .= ',\'' . pSQL($ParentExternalID) . '\''; $sql .= ')'; $sql .= ' ON DUPLICATE KEY UPDATE '; $sql .= '`attributes` = \'' . pSQL($attributes) . '\''; if($sf_id != null && $sf_id != '') $sql .= ',`sf_id` = \'' . pSQL($sf_id) . '\''; $sql .= ',`ps_parentexternalid` = \'' . pSQL($ParentExternalID) . '\';'; // lll($sql); $response = Db::getInstance()->Execute($sql); // ppp('### Apres execution requete'); // ppp($response); // ppp(DB::getInstance()->getMsgError()); return $response; } return false;}function DeleteId($ps_externalid, $sf_objecttype){ $sql = 'DELETE FROM `' . _DB_PREFIX_ . 'sf_connector` WHERE '; $sql .= '`ps_externalid` = \'' . $ps_externalid . '\''; $sql .= ' AND `sf_objecttype` = \'' . $sf_objecttype . '\''; // lll($sql); $response = Db::getInstance()->Execute($sql); return $response;}function getValues($ps_externalid, $sf_objecttype){ $sql='SELECT `ps_externalid`, `sf_objecttype`, `sf_id`, `attributes`, `ps_parentexternalid` FROM `' . _DB_PREFIX_ . 'sf_connector` WHERE `ps_externalid` = \'' . $ps_externalid . '\' AND `sf_objecttype` = \'' . $sf_objecttype . '\''; $response = Db::getInstance()->ExecuteS($sql); return $response;}function SF_log($message){ // if(defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_){ $message_str = 'PrestashopConnector ' . str_replace('}', ')', str_replace('{', '(', serialize($message))); Logger::addLog($message_str, 2); // $fp = fopen(_PS_MODULE_DIR_.'/salesforceconnector/logs.txt', 'a+'); // fwrite($fp, '[2] '.Tools::safeOutput($message_str)); // fclose($fp); // }}/*** Authenticate into Salesforce with params defined in file config.php*/function SF_authenticate($ForceAuthenticate = false){ //ppp( "<br/>Session[acces_token] : " . $_SESSION['access_token']); //ppp( "<br/>Session[instance_url] : " . $_SESSION['instance_url']); // If accestoken and instance URL are stored in session, no login is necessary; if( isset($_SESSION['access_token']) && $_SESSION['access_token'] != '' && isset($_SESSION['instance_url']) && $_SESSION['instance_url'] != '' && !$ForceAuthenticate) return true; $token_url = Configuration::get('SF_CONNECT_LOGIN_URI') . Configuration::get('SF_CONNECT_AUTH_SERVICE'); $params = "grant_type=password&client_id=" . Configuration::get('SF_CONNECT_CLIENT_ID') . "&client_secret=" . Configuration::get('SF_CONNECT_CLIENT_SECRET') . "&username=" . Configuration::get('SF_CONNECT_USERNAME') . "&password=" . Configuration::get('SF_CONNECT_PASSWORD'); //ppp( "<br/>params : $params <br/>token_url=$token_url <br/>"); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $token_url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $params); $json_response = curl_exec($curl); // Get Status $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); $response = json_decode($json_response, true); // Close the curl curl_close($curl); if ( (int)($status/100) != 2 || $status <= 0) { SF_log('Error Connecting Salesforce : ' . serialize($response)); return false; } if (!isset($response['access_token']) || $response['access_token'] == "" || !isset($response['instance_url']) || $response['instance_url'] == "") { SF_log('Error Connecting Salesforce : ' . serialize($response)); } else{ $_SESSION['access_token'] = $response['access_token']; $_SESSION['instance_url'] = $response['instance_url']; } return true;}/*** Set the options into curl, execute the curl, output errors or send the response into an array*/function SF_executeCURL($curl, $service, $ArrayHeader = null, $NbCalls = 0){ if(!isset($_SESSION['instance_url']) || $_SESSION['instance_url'] == null || $_SESSION['instance_url'] == '') SF_authenticate(); // ppp($curl); // ppp($service); // ppp($ArrayHeader); // ppp($NbCalls); // Define the access_token in the header if exists $access_token = $_SESSION['access_token']; $instance_url = $_SESSION['instance_url']; if($ArrayHeader == null) $ArrayHeader = array(); if(isset($access_token) && $access_token != "") array_push($ArrayHeader, "Authorization: OAuth $access_token"); curl_setopt($curl, CURLOPT_URL, $instance_url . Configuration::get('SF_CONNECT_DATA_SERVICE') . $service); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_HTTPHEADER, $ArrayHeader); // Execute curl $json_response = curl_exec($curl); // Get Status $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); $response = json_decode($json_response, true); // ppp("#### SF_executeCURL: response ="); // ppp($response); // ppp("#### SF_executeCURL: status ="); // ddd($status); // Close the curl curl_close($curl); if ( (int)($status/100) != 2 || $status <= 2) { if(isset($response[0]) && isset($response[0]['errorCode']) && $response[0]['errorCode'] == 'INVALID_SESSION_ID' && $NbCalls <= 0){ SF_authenticate(true); SF_executeCURL($curl, $service, $ArrayHeader, 1); } else{ SF_log($response); return $response; } } return $response;}function SF_getProductById($PS_ProductId){ $service = "/query?q=Select+Id,+Name,+isActive+From+Product2+where+" . Configuration::get('SF_PROD_FIELD_MAPPING') . "+%3D+%27" . $PS_ProductId . "%27+LIMIT+1"; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); $result = SF_executeCURL($curl, $service); return $result;}/*** Upsert a product*/function SF_UpsertProduct($product, $id_shop=null){ $product_id = $product->id; if($product_id == null || $product_id == "") return false; // ddd("Error - No Product Id !"); $service = "/sobjects/Product2/" . Configuration::get('SF_PROD_FIELD_MAPPING') . "/" . getSFProductExternalId($product_id, $id_shop); $description = str_replace(CHR(13).CHR(10), ' ', strip_tags($product->description[Configuration::get('PS_LANG_DEFAULT')])); if(strlen($description) > 90) $description = substr(strip_tags($description), 0, 90) . '...'; // ppp($product); $category = Configuration::get('PS_INSTANCE_NAME'); $sous_category = ''; if(isset($product->id_category_default) && $product->id_category_default != null){ $obj_sous_category = new Category($product->id_category_default, Configuration::get('PS_LANG_DEFAULT')); // ppp($obj_category); if($obj_sous_category !=null){ $sous_category = $obj_sous_category->name; if(isset($obj_sous_category->id_parent) && $obj_sous_category->id_parent <> null){ $obj_category = new Category($obj_sous_category->id_parent, Configuration::get('PS_LANG_DEFAULT')); if($obj_category !=null) $category = $obj_category->name; } } } // ppp($category); $json_product = array( "Name" => $product->name[Configuration::get('PS_LANG_DEFAULT')], "Description" => $description,/* "Product_Name_EN__c" => $product->name[1], "Product_Name_BR__c" => $product->name[2], "Product_Name_DE__c" => $product->name[3], "Product_Name_SP__c" => $product->name[4], "Product_Name_FR__c" => $product->name[5], "Product_Name_IT__c" => $product->name[6], "Product_Decription_EN__c" => $product->description[1], "Product_Decription_BR__c" => $product->description[2], "Product_Decription_DE__c" => $product->description[3], "Product_Decription_SP__c" => $product->description[4], "Product_Decription_FR__c" => $product->description[5], "Product_Decription_IT__c" => $product->description[6],*/ 'IsActive' => ($product->active == 1), "ProductCode" => $product->reference, "Family" => ($category!='' && $category!='GAMME'?$category:$sous_category), "Sous_Famille__c" => ($category!=''&&$category!='GAMME'?$sous_category:'') ); // ppp($json_product); $curl = curl_init(); $Header = array("Content-Type: application/json"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($json_product)); $response = SF_executeCURL($curl, $service, $Header); // ddd($response); unset($curl); // ppp('###Response from upsert product :'); // ppp($response); // If insert Product OK : add the standard price and add in the prestashop PriceBook if (isset($response["id"]) || sizeOf($response) == 0){ $isNew = false; // Verify if the standard price exists $service = "/query?q=Select+Id,+Name,+Product2." . Configuration::get('SF_PROD_FIELD_MAPPING') . ",+UnitPrice,+Pricebook2Id+From+PricebookEntry+where+Product2." . Configuration::get('SF_PROD_FIELD_MAPPING') . "+%3D+%27" . getSFProductExternalId($product_id, $id_shop) . "%27+AND+Pricebook2.isStandard+%3Dtrue+AND+isActive+%3Dtrue+AND+isDeleted+%3Dfalse+LIMIT+1"; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); $result = SF_executeCURL($curl, $service); // ppp('### SF_UpsertProduct'); // ppp($service); // ddd($result); $StandardPriceExists = false; if( isset($result['totalSize']) && $result['totalSize'] > 0 || isset($result['done']) && $result['done'] = true && sizeOf($result['records']) > 0 ) $StandardPriceExists = true; unset($curl); // If there is No StandardPrice, insert it if(!$StandardPriceExists){ // ppp( "<BR/>The Standard Price does not exists : insert it"); // Get the Pricebook standard prices $service = "/query?q=Select+Id,+Name+From+Pricebook2+where+isStandard+%3Dtrue+AND+isDeleted+%3Dfalse+ORDER+BY+isActive+DESC+LIMIT+1"; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); $response = SF_executeCURL($curl, $service); $StandardPriceBookId = ''; if( isset($response['totalSize']) && $response['totalSize'] > 0 && isset($response['done']) && $response['done'] == true && sizeOf($response['records']) > 0 ) $StandardPriceBookId = $response['records'][0]["Id"]; else return false; $json_StandardPrice = '{ "IsActive" : true, "Pricebook2Id" : "' . $StandardPriceBookId . '", "UnitPrice" : "' . ($product->unit_price == null ? 0 : $product->unit_price) . '", "UseStandardPrice" : false, "Product2" : {"' . Configuration::get('SF_PROD_FIELD_MAPPING') . '":"' . getSFProductExternalId($product->id, $id_shop) . '"} }'; $service = "/sobjects/PricebookEntry/"; // ppp( "<BR/>Service : " . $service . "<BR/> json :"); // ppp($json_StandardPrice); $curl = curl_init(); $Header = array("Content-Type: application/json"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json_StandardPrice); $response = SF_executeCURL($curl, $service, $Header); // ppp('### SF_UpsertProduct : insertion dans catalgue ini'); // ppp($service); // ppp($json_StandardPrice); // ddd($response); } // ppp( "<BR/>Verify if the PriceBookEntry exists"); // Verify if the PriceBookEntry exists $service = "/query?q=Select+Id,+Name,+Product2." . Configuration::get('SF_PROD_FIELD_MAPPING') . ",+UnitPrice,+Pricebook2Id+From+PricebookEntry+where+Product2." . Configuration::get('SF_PROD_FIELD_MAPPING') . "+%3D+%27" . getSFProductExternalId($product_id, $id_shop) . "%27+AND+Pricebook2Id+%3D+%27" . Configuration::get('SF_CONNECT_SF_PRICE_BOOK_ID') . "%27+LIMIT+1"; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); $result = SF_executeCURL($curl, $service); $PriceBookEntryId = ''; $isNew = false; if( !isset($result['totalSize']) || $result['totalSize'] < 0 || !isset($result['done']) || $result['done'] <> true || sizeOf($result['records']) <= 0 ) $isNew = true; else $PriceBookEntryId = $result['records'][0]['Id']; unset($curl); // PricebookEntry $json_PriceBookEntry = '{ "IsActive" : true, "UnitPrice" : "' . ($product->unit_price == null ? 0 : $product->unit_price) . '", "UseStandardPrice" : false'; if($isNew) $json_PriceBookEntry .= ',"Pricebook2Id" : "' . Configuration::get('SF_CONNECT_SF_PRICE_BOOK_ID') . '", "Product2" : {"' . Configuration::get('SF_PROD_FIELD_MAPPING') . '":"' . getSFProductExternalId($product->id, $id_shop) . '"}'; $json_PriceBookEntry .= '}'; $service = "/sobjects/PricebookEntry/" . $PriceBookEntryId; // ppp( "<BR/>Service PricebookEntry : " . $service . "<BR/> json :"); // ppp($json_PriceBookEntry); $curl = curl_init(); $Header = array("Content-Type: application/json"); if($isNew) curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); else curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json_PriceBookEntry); $response = SF_executeCURL($curl, $service, $Header); if(isset($response['id']) && $response['id'] != null && $response['id'] != '') InsertId(getSFProductExternalId($product_id, $id_shop), __PRODUCT__, $response['id']); // ppp('### SF_UpsertProduct : insertion finale'); // ppp($service); // ddd($response); // ppp( "<BR/><BR/>Res Upsert ProcebookEntryId : "); // ppp($response); } return $response;}/*** Delete a product on Salesforce*/function SF_DeleteProduct($product){ $product_id = $product->id; $id_product = getSFProductExternalId($product_id); if($product_id == null || $product_id == "") return false; // ddd("Error - No Product Id !"); $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); $service = "/sobjects/Product2/" . Configuration::get('SF_PROD_FIELD_MAPPING') . "/" . $id_product; $result = SF_executeCURL($curl, $service, $Header); deleteId($id_product, __PRODUCT__); return $result;}function SF_getOpportunityByOrderId($OrderId){ $AccField = Configuration::get('SF_ACC_FIELD_ID_SF'); if($AccField == null || $AccField != '') $AccField = Configuration::get('SF_ACC_FIELD_MAPPING'); $service = "/query?q=Select+Id,+Name,+StageName,+Probability,+CloseDate,+Amount,+LeadSource,+Account." . $AccField . "+From+Opportunity+where+" . Configuration::get('SF_OPP_FIELD_MAPPING') . "+%3D+%27" . $OrderId . "%27+LIMIT+1"; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); $result = SF_executeCURL($curl, $service); // ppp($result ); if( !isset($result['totalSize']) || $result['totalSize'] < 0 || !isset($result['done']) || $result['done'] <> true ){ // Error : Return false // ppp( "Error in SF_getOpportunityByOrderId : "); // ppp($result); // ppp(( "<BR/>SF_getOpportunityByOrderId : Return false"); return false; } // ppp( "<BR/>SF_getOpportunityByOrderId : Return result"); //ppp( "Res in SF_getOpportunityByOrderId : "); // ppp($result); return $result;}/*** Upsert an apportunity*///TODO !! Supprimer le parametre jsonfunction SF_UpsertOpportunity($opportunityId, $attributes = null, $json=null){ $result = false; if($opportunityId != null){ if($attributes != null){ $Name = null; $Account = null; $StageName = null; $Probability = null; $CloseDate = null; $LeadSource = null; $sf_id = null; $ValeursEnBase = getValues($opportunityId, __OPPORTUNITY__); // lll('###Valeurs en base :'); // lll($ValeursEnBase); $NameEnBase = null; $AccountEnBase = null; $StageNameEnBase = null; $ProbabilityEnBase = null; $CloseDateEnBase = null; $LeadSourceEnBase = null; if(isset($ValeursEnBase[0])){ if(isset($ValeursEnBase[0][__Attributes__]) && $ValeursEnBase[0][__Attributes__] != ''){ $AttributesEnBase = unserialize($ValeursEnBase[0][__Attributes__]); if(isset($AttributesEnBase['Name'])) $NameEnBase = $AttributesEnBase['Name']; if(isset($AttributesEnBase['Account'])) $AccountEnBase = $AttributesEnBase['Account']; if(isset($AttributesEnBase['StageName'])) $StageNameEnBase = $AttributesEnBase['StageName']; if(isset($AttributesEnBase['Probability'])) $ProbabilityEnBase = $AttributesEnBase['Probability']; if(isset($AttributesEnBase['CloseDate'])) $CloseDateEnBase = $AttributesEnBase['CloseDate']; if(isset($AttributesEnBase['LeadSource'])) $LeadSourceEnBase = $AttributesEnBase['LeadSource']; } if(isset($ValeursEnBase[0]['sf_id'])) $sf_id = $ValeursEnBase[0]['sf_id']; } // lll('###sf_id en base :'); // lll($sf_id); $json_opp = ''; if(isset($attributes['Name']) && $attributes['Name'] != null && $attributes['Name'] != '' && $attributes['Name'] != $NameEnBase) $json_opp .= ($json_opp!=''?',':'') . '"Name" : "' . $attributes['Name'] . '"'; if(isset($attributes['Account']) && $attributes['Account'] != null && $attributes['Account'] != '' && $attributes['Account'] != $AccountEnBase) // Attention : le compte est un objet lié, pas de "" pour la valeur !! $json_opp .= ($json_opp!=''?',':'') . '"Account" : ' . $attributes['Account'] ; if(isset($attributes['StageName']) && $attributes['StageName'] != null && $attributes['StageName'] != '' && $attributes['StageName'] != $StageNameEnBase) $json_opp .= ($json_opp!=''?',':'') . '"StageName" : "' . $attributes['StageName'] . '"'; if(isset($attributes['Probability']) && $attributes['Probability'] != null && $attributes['Probability'] != '' && $attributes['Probability'] != $ProbabilityEnBase) $json_opp .= ($json_opp!=''?',':'') . '"Probability" : "' . $attributes['Probability'] . '"'; if(isset($attributes['CloseDate']) && $attributes['CloseDate'] != null && $attributes['CloseDate'] != '' && $attributes['CloseDate'] != $CloseDateEnBase) $json_opp .= ($json_opp!=''?',':'') . '"CloseDate" : "' . $attributes['CloseDate'] . '"'; if(isset($attributes['LeadSource']) && $attributes['LeadSource'] != null && $attributes['LeadSource'] != '' && $attributes['LeadSource'] != $LeadSourceEnBase) $json_opp .= ($json_opp!=''?',':'') . '"LeadSource" : "' . $attributes['LeadSource'] . '"'; /* // On crée le json s'il y a des valeurs qui changent if($Name != null) $json_opp .= '"Name" : "' . $Name . '",'; if($Account != null) $json_opp .= '"Account" : "' . $Account . '",'; if($StageName != null) $json_opp .= '"StageName" : "' . $StageName . '",'; if($Probability != null) $json_opp .= '"Probability" : "' . $Probability . '",'; if($CloseDate != null) $json_opp .= '"CloseDate" : "' . $CloseDate . '",'; if($LeadSource != null) $json_opp .= '"LeadSource" : "' . $LeadSource . '",'; */ // SF_log('###json_opp = ///' . $json_opp . '///Fin json Opp'); // lll('###Changement dans le json json_opp = ' . $json_opp . ' /// Fin du json_opp'); if($json_opp != ''){ $json_opp = '{' . $json_opp . '}'; $service = "/sobjects/Opportunity/" . Configuration::get('SF_OPP_FIELD_MAPPING') . "/" . $opportunityId; $curl = curl_init(); $Header = array("Content-Type: application/json"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json_opp); $result = SF_executeCURL($curl, $service, $Header); if(isset($result['id']) && $result['id'] != null && $result['id'] != ''){ $sf_id = $result['id']; InsertId($opportunityId, __OPPORTUNITY__, $sf_id, serialize($attributes), null); } // lll('### result upsert Opp : '); // lll($result); return $result; } } else if($json != null){ $service = "/sobjects/Opportunity/" . Configuration::get('SF_OPP_FIELD_MAPPING') . "/" . $opportunityId; $curl = curl_init(); $Header = array("Content-Type: application/json"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); $result = SF_executeCURL($curl, $service, $Header); if(isset($result['id']) && $result['id'] != null && $result['id'] != '') InsertId($opportunityId, __OPPORTUNITY__, $result['id'], null, null); return $response; } } /* Array ( [0] => Array ( [ps_externalid] => 1_25 [sf_objecttype] => Opportunity [sf_id] => 006A000000MTAJDIA5 [attributes] => [ps_parentexternalid] => ) ) "Name" => $OppName, "Account" => '{"' . Configuration::get('SF_ACC_FIELD_MAPPING') . '":"' . $account_ext_id . '"}', "StageName" => $stagename, "Probability" => $probability, "CloseDate" => $closedate, "LeadSource" => "Prestashop" "StageName" => $stagename, "Probability" => $probability, "CloseDate" => $closedate $service = "/sobjects/Opportunity/" . Configuration::get('SF_OPP_FIELD_MAPPING') . "/" . $opportunityId; $curl = curl_init(); $Header = array("Content-Type: application/json"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); $result = SF_executeCURL($curl, $service, $Header); if(isset($result['id']) && $result['id'] != null && $result['id'] != '') InsertId($opportunityId, __OPPORTUNITY__, $result['id']); */ return false;}function SF_GetAllOpportunityLineItemFromOpporunity($Opp_id){ $sql = "SELECT `ps_externalid`, `sf_objecttype`, `sf_id`, `attributes`, `ps_parentexternalid` FROM `" . _DB_PREFIX_ . "sf_connector` WHERE `ps_parentexternalid` = '" . $Opp_id . "' and `sf_objecttype` = '" . __OPPORTUNITYLINEITEM__ . "'"; $results = Db::getInstance()->ExecuteS($sql); // lll('### results requete SF_GetAllOpportunityLineItemFromOpporunity : '); // lll($results); // ppp($results); $response = array(); $response_records = array(); $nb = 0; foreach ($results as $row){ $nb++; /*$quantity = 0; $total_wt = 0; $id_product = 0; if(isset($row[__Attributes__]) && $row[__Attributes__] != null && $row[__Attributes__] != ''){ $attributes = explode (';', $row[__Attributes__]); foreach($attributes as $attr){ if(strpos($attr, __OPPLIATTR_QUANTITY__.':') !== false) $quantity = floatval(substr(strrchr($attr, ':'), 1)); else if(isset($attributes[__OPPLIATTR_TOTAL_WT__])) $total_wt = floatval(substr(strrchr($attr, ':'), 1)); else if(isset($attributes[__OPPLIATTR_ID_PRODUCT__])) $id_product = floatval(substr(strrchr($attr, ':'), 1)); } } if(isset($row['ps_externalid'])) $external_id = $row['ps_externalid']; if(isset($row['sf_id'])) $sf_id = $row['sf_id']; $response_row = array( __OPPLIATTR_QUANTITY__ => $quantity, __OPPLIATTR_TOTAL_WT__ => $total_wt, __OPPLIATTR_ID_PRODUCT__ => $id_product, Configuration::get('SF_OPPLINEITEM_FIELD_MAPPING') => $external_id, __SF_ID__ => $sf_id );*/ $attributes = null; $sf_id = null; $external_id = null; if(isset($row['ps_externalid'])) $external_id = $row['ps_externalid']; if(isset($row[__Attributes__]) && $row[__Attributes__] != null && $row[__Attributes__] != '') $attributes = unserialize($row[__Attributes__]); if(isset($row['sf_id'])) $sf_id = $row['sf_id']; $response_row = array( Configuration::get('SF_OPPLINEITEM_FIELD_MAPPING') => $external_id, __Attributes__ => $attributes, __SF_ID__ => $sf_id ); array_push($response_records, $response_row); } $response['totalSize'] = $nb; $response['records'] = $response_records; // lll($response); return $response; /* $service = "/query?q=SELECT+Id,+Quantity,+TotalPrice,+" . Configuration::get('SF_OPPLINEITEM_FIELD_MAPPING') . "+FROM+OpportunityLineItem+WHERE+Opportunity." . Configuration::get('SF_OPP_FIELD_MAPPING') . "+%3D+%27" . $Opp_id . "%27"; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); $result = SF_executeCURL($curl, $service); return $result; */}function SF_DeleteOpportunityLineItemById($OppLineItem_id){ $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); $service = "/sobjects/OpportunityLineItem/". Configuration::get('SF_OPPLINEITEM_FIELD_MAPPING') . "/" . $OppLineItem_id; $result = SF_executeCURL($curl, $service, null); DeleteId($OppLineItem_id, __OPPORTUNITYLINEITEM__); // DeleteId return $result;}function SF_GetOpportunityLineItemById($id_ProductLine, $id_product){ $service = "/query?q=SELECT+Id,+Quantity,+TotalPrice+FROM+OpportunityLineItem+WHERE+" . Configuration::get('SF_OPPLINEITEM_FIELD_MAPPING') . "+%3D+%27" . $id_ProductLine . "%27+LIMIT+1";//+and+PricebookEntry.PrestaShopID__c+%3D+%27" . $id_product . "%27+LIMIT+1"; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); $result = SF_executeCURL($curl, $service); return $result;}/*** Upsert an apportunity Line Item*/function SF_UpsertOpportunityLineItem($json, $id_ProductLine, $id_product, $AddPriceBookId, $Attributes=null, $ParentExternalID =null){ if($json == null){ $IdProduitEnBase = null; $QuantityEnBase = null; $ToTalPriceEnBase = null; $OpportunityEnBase = null; $json_opplineItem = ''; $OppLineItemsEnBase = getValues($id_ProductLine, __OPPORTUNITYLINEITEM__); // La ligne de produit a deja été insérée : On récupère ses attributs if($OppLineItemsEnBase != null && isset($OppLineItemsEnBase[0])){ $ValuesEnBase = $OppLineItemsEnBase[0]; if(isset($ValuesEnBase[__Attributes__]) && $ValuesEnBase[__Attributes__] != null && $ValuesEnBase[__Attributes__] !=''){ $AttributesEnBase = unserialize($ValuesEnBase[__Attributes__]); if(isset($AttributesEnBase[__OPPLIATTR_ID_PRODUCT__])) $IdProduitEnBase = $AttributesEnBase[__OPPLIATTR_ID_PRODUCT__]; if(isset($AttributesEnBase[__OPPLIATTR_QUANTITY__])) $QuantityEnBase = $AttributesEnBase[__OPPLIATTR_QUANTITY__]; if(isset($AttributesEnBase[__OPPLIATTR_TOTAL_PRICE__])) $ToTalPriceEnBase = $AttributesEnBase[__OPPLIATTR_TOTAL_PRICE__]; if(isset($AttributesEnBase[__OPPLIATTR_OPPORTUNITY__])) $OpportunityEnBase = $AttributesEnBase[__OPPLIATTR_OPPORTUNITY__]; } } // SF_log('###Attributes[__OPPLIATTR_ID_PRODUCT__] = ///' . $Attributes[__OPPLIATTR_ID_PRODUCT__] . '///Fin Attributes[__OPPLIATTR_ID_PRODUCT__]'); // On vérifie s'il y a des changements par rapport à ce qui est déjà en base et on crée le json if(isset($Attributes[__OPPLIATTR_QUANTITY__]) && $Attributes[__OPPLIATTR_QUANTITY__] != $QuantityEnBase) $json_opplineItem .= ($json_opplineItem!=''?',':'') . '"Quantity":' . $Attributes[__OPPLIATTR_QUANTITY__]; if(isset($Attributes[__OPPLIATTR_TOTAL_PRICE__]) && $Attributes[__OPPLIATTR_TOTAL_PRICE__] != $ToTalPriceEnBase) $json_opplineItem .= ($json_opplineItem!=''?',':'') . '"' . __OPPLIATTR_TOTAL_PRICE__ . '":"' . $Attributes[__OPPLIATTR_TOTAL_PRICE__].'"'; if(isset($Attributes[__OPPLIATTR_ID_PRODUCT__]) && $Attributes[__OPPLIATTR_ID_PRODUCT__] != $IdProduitEnBase){ $TabProductEnBase = getValues($Attributes[__OPPLIATTR_ID_PRODUCT__], __PRODUCT__); // SF_log('### TabProductEnBase[0] = ' . $TabProductEnBase[0]); // SF_log('### TabProductEnBase[0][sf_id] = ' . $TabProductEnBase[0]['sf_id']); if($TabProductEnBase != null && isset($TabProductEnBase[0]) && isset($TabProductEnBase[0]['sf_id'])){ $json_opplineItem .= ($json_opplineItem!=''?',':'') . '"'. __OPPLIATTR_PRICEBOOKENTRYID__ . '":"' . $TabProductEnBase[0]['sf_id'] . '"'; } } if(isset($Attributes[__OPPORTUNITY__]) && $Attributes[__OPPORTUNITY__] != $OpportunityEnBase) $json_opplineItem .= ($json_opplineItem!=''?',':'') . '"' . __OPPLIATTR_OPPORTUNITY__ . '":' . $Attributes[__OPPORTUNITY__]; // SF_log('###json_opplineItem = ///' . $json_opplineItem . '///Fin json OpplineItem'); if($json_opplineItem != ''){ $json_opplineItem = '{' . $json_opplineItem . '}'; // Upsert the OppLineItem $service = "/sobjects/OpportunityLineItem/" . Configuration::get('SF_OPPLINEITEM_FIELD_MAPPING') . "/" . $id_ProductLine; $curl = curl_init(); $Header = array("Content-Type: application/json"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json_opplineItem); $result = SF_executeCURL($curl, $service, $Header); // lll('### result upsert OpplineItem pour id_ProductLine = ' . $id_ProductLine); // lll($result); $new_sf_id = null; if(isset($result['id']) && $result['id'] != null && $result['id'] != ''){ $new_sf_id = $result['id']; InsertId($id_ProductLine, __OPPORTUNITYLINEITEM__, $new_sf_id, serialize($Attributes), $ParentExternalID); } } return true; } //ppp( "<br/><h1>Debut SF_UpsertOpportunityLineItem</h1><br/>"); //ppp($json); // Else : JSON != null : On n'utilise pas la base locale // Get the PricebookEntryId $service = "/query?q=SELECT+Id+FROM+PricebookEntry+WHERE+Pricebook2Id+%3D+%27" . Configuration::get('SF_CONNECT_SF_PRICE_BOOK_ID') . "%27+and+Product2." . Configuration::get('SF_PROD_FIELD_MAPPING') . "+%3D+%27" . $id_product . "%27+LIMIT+1"; // ppp( "<BR/>Service PricebookEntryId : " . $service); $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET"); $result = SF_executeCURL($curl, $service); // ppp('### SF_UpsertOpportunityLineItem :'); // ppp($service); // ppp($result); if( !isset($result['totalSize']) || $result['totalSize'] <= 0 || !isset($result['records']) || !isset($result['records'][0]) || !isset($result['records'][0]['Id'])){ // ppp( "<br/>Erreur en récupérant le PricebookEntryId :<br/>"); // ppp($result); return false; } $pricebookEntryId = $result['records'][0]['Id']; unset($curl); // Set the Opportunity ProductLine Item $service = "/sobjects/OpportunityLineItem/" . Configuration::get('SF_OPPLINEITEM_FIELD_MAPPING') . "/" . $id_ProductLine; if($AddPriceBookId){ $json_Entry = substr($json, 0, strlen($json) - 1); $json_Entry = $json_Entry . ', "PricebookEntryId":"' . $pricebookEntryId . '"}'; } else $json_Entry = $json; //ppp( "<br/>JsonopportunityLineItem : <br/>" . $json_Entry . "<br/>"); $curl = curl_init(); $Header = array("Content-Type: application/json"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json_Entry); $result = SF_executeCURL($curl, $service, $Header); if(isset($result['id']) && $result['id'] != null && $result['id'] != '') InsertId($id_ProductLine, __OPPORTUNITYLINEITEM__, $result['id'], $Attributes, $ParentExternalID); //ppp(( "<br/><h1>Fin SF_UpsertOpportunityLineItem</h1><br/>"); return $result;}/*** Delete an Opportunity on Salesforce*/function SF_DeleteOpportunity($opportunity_id){ if($Opportunity_id == null || $Opportunity_id == "") return false; // ddd("Error - No Opportunity Id !"); $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); $service = "/sobjects/Opportunity/" . Configuration::get('SF_OPP_FIELD_MAPPING') . "/" . $opportunity_id; $result = SF_executeCURL($curl, $service, $Header); DeleteId($opportunity_id, __OPPORTUNITY__); return $result;}/*** Upsert an account*/function SF_UpsertAccount($json, $Account_id){ // ppp( "<br/><h1>Debut Upsert Account</h1><br/>"); if($Account_id == null || $Account_id == "") return false; // ddd("Error - No Account Id !"); $service = "/sobjects/Account/" . Configuration::get('SF_ACC_FIELD_MAPPING') . "/" . str_replace("+", "%2B", str_replace(".", "%2E", $Account_id)); // SF_log($service); // ppp("JsonAccount : "); // ppp($json); $curl = curl_init(); $Header = array("Content-Type: application/json"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); $result = SF_executeCURL($curl, $service, $Header); // if(isset($result['id']) && $result['id'] != null && $result['id'] != '') // InsertId($Account_id, __ACCOUNT__, $result['id']); // ppp( "<br/><h1>Fin Upsert Account</h1><br/>"); return $result;}function SF_UpsertContact($json, $Contact_id){ if($Contact_id == null || $Contact_id == "") return false; $service = "/sobjects/Contact/" . Configuration::get('SF_CONTACT_FIELD_MAPPING') . "/" . str_replace("+", "%2B", str_replace(".", "%2E", $Contact_id)); $curl = curl_init(); $Header = array("Content-Type: application/json"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); $result = SF_executeCURL($curl, $service, $Header); // if(isset($result['id']) && $result['id'] != null && $result['id'] != '') // InsertId($Contact_id, __CONTACT__, $result['id']); return $result;}function getSFProductExternalId($id_product, $id_shop = null){ if($id_shop != null) return $id_shop . '_' . $id_product; else return '1_' . $id_product;}function getSFAccountExternalId($id_customer, $id_shop, $email = null){ // return $id_shop . '_' . $id_customer; if(isset($email) && $email != null) return $email; // Pour prestashop : rechercher l'adresse mail else{ $customer_mail; $Customers = Db::getInstance()->executeS('SELECT id_customer, id_shop, email FROM ' . _DB_PREFIX_ . 'customer WHERE id_customer = ' . $id_customer . ' AND id_shop = ' . $id_shop . ' LIMIT 1'); foreach ($Customers as $Customer){ if(isset($Customer['email']) && $Customer['email'] != null && $Customer['email'] != '') $customer_mail = $Customer['email']; } } if(isset($customer_mail) && $customer_mail != null && $customer_mail != '') return $customer_mail; else if(isset($id_shop) && $id_shop != null) return $id_shop . '_' . $id_customer; else return '1_' . $id_customer;}function getSFOpportunityExternalId($id_cart, $id_shop){ if(isset($id_shop) && $id_shop != null) return $id_shop . '_' . $id_cart; else return '1_' . $id_cart;}function getSFContactExternalId($id_contact, $id_shop){ if(isset($id_shop) && $id_shop != null) return $id_shop . '_' . $id_contact; else return '1_' . $id_contact;}function getSFOpporunityLineItemExternalId($OpportunityId, $ProductLineId){ return $OpportunityId . '_' . $ProductLineId;}function lll($to_log){ error_log(print_r($to_log, true));}function isVersion_1_4(){ return(!strcmp(substr(_PS_VERSION_, 0, 3), '1.4'));/* if(!strcmp(substr(_PS_VERSION_, 0, 3), '1.4')){ ppp( 'vrai'); return true; } else{ ppp( 'pas de isVersion_1_4 : current version =' . substr(_PS_VERSION_, 0, 3)); ppp(strcmp(substr(_PS_VERSION_, 0, 3), '1.4')); // ppp(isdefined(_PS_VERSION_)); return false; }*/}function isVersion_1_5(){ return(!strcmp(substr(_PS_VERSION_, 0, 3), '1.5'));} Link to comment Share on other sites More sharing options...
pouc Posted February 11, 2014 Author Share Posted February 11, 2014 Au final problème résolu, l'entreprise extérieur à désactivé son api et tout fonctionne. Merci pour votre aide!! =) Baptiste Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now