Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DOC

Openerp7.0 with PHP using xml-rpc(read,search and write method)

In previous blog i have discussed about the xml-rpc connection using PHP.

now i am going to discuss about  read, write and search methods.

$dbname = 'dbname';
$user = 'admin';
$pwd = 'pwd';
// it's a demo openerp server url
$url = 'http://demo.openerp.com:8069';
$sock = new xmlrpc_client("http://demo.openerp.com:8069/xmlrpc/common");
$client = new xmlrpc_client("http://demo.openerp.com:8069/xmlrpc/object");

// for $user_id we have already done in previous blog...
$partner_id = 1; 
$id_list[0]= new xmlrpcval($partner_id, 'int');
$key = array(new xmlrpcval('name', 'string')); 

$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($dbname, "string"));
$msg->addParam(new xmlrpcval($user_id, "int"));
$msg->addParam(new xmlrpcval($pwd, "string"));
$msg->addParam(new xmlrpcval("res.partner", "string"));
$msg->addParam(new xmlrpcval("read", "string")); 
$msg->addParam(new xmlrpcval($id_list, "struct")); // sending id which is to be read
$msg->addParam(new xmlrpcval($key, "struct")); // sending an array of field
$resp = $client->send($msg);
$val = $resp->value();
$ids = $val->scalarval();		
$id = $ids[0]->me;
// here we get the customer name
$customer_name = $id["struct"]["name"]->me["string"];
$key = array(new xmlrpcval
            (array(new xmlrpcval('name' , "string"), // field name
                   new xmlrpcval('=',"string"), // operator
                   new xmlrpcval('your company',"string")),"array"             ),
        );   

 $msg = new xmlrpcmsg('execute');
 $msg->addParam(new xmlrpcval($dbname, "string"));
 $msg->addParam(new xmlrpcval($user_id, "int"));
 $msg->addParam(new xmlrpcval($pwd, "string"));
 $msg->addParam(new xmlrpcval('res.partner', "string"));
 $msg->addParam(new xmlrpcval("search", "string"));
 $msg->addParam(new xmlrpcval($key, "array"));

 $resp = $client->send($msg);
 $val = $resp->value();
 $ids = $val->scalarval(); // here we will get the return ids
$id_list[0]= new xmlrpcval($partner_id, 'int');// array of openerp customer id

$customer_data = array( 
        'name'=>new xmlrpcval('Openerp customer', "string"),
	'email'=>new xmlrpcval('[email protected]', "string")
	);
 $msg = new xmlrpcmsg('execute');
 $msg->addParam(new xmlrpcval($dbname, "string"));
 $msg->addParam(new xmlrpcval($user_id, "int"));
 $msg->addParam(new xmlrpcval($pwd, "string"));
 $msg->addParam(new xmlrpcval('res.partner', "string"));
 $msg->addParam(new xmlrpcval("write", "string"));
 $msg->addParam(new xmlrpcval($id_list, "array"));
 $msg->addParam(new xmlrpcval($customer_data, "struct"));
 $resp = $client->send($msg);
 $val = $resp->value();
 $record = $val->scalarval();
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


1 comments

  • Yoko Kimo
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home