PHP code example of tbondois / odoo-ripcord
1. Go to this page and download the library: Download tbondois/odoo-ripcord library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tbondois / odoo-ripcord example snippets
use Ripoo\OdooClient;
$host = 'example.odoo.com:8080';
$db = 'example-database';
$user = '[email protected] ';
$password = 'yourpassword';
$client = new OdooClient($host, $db, $user, $password);
class RipooClientProvider
{
private $clientFactory;
private $client;
private $scopeConfig;
function __construct(
\Ripoo\OdooClientFactory $clientFactory,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
) {
$this->clientFactory = $clientFactory;
$this->scopeConfig = $scopeConfig;
}
public function createClient() : \Ripoo\OdooClient
{
// TODO secure injections
$odooUrl = $this->scopeConfig->getValue('my/settings/odoo_url');
$odooDb = $this->scopeConfig->getValue('my/settings/odoo_database');
$odooUser = $this->scopeConfig->getValue('my/settings/odoo_user');
$odooPwd = $this->scopeConfig->getValue('my/settings/odoo_pwd');
$this->client = $this->clientFactory->create(
$host,
$odooDb,
$odooUser,
$odooPwd
);
return $this->client;
}
public function getClient() : \Ripoo\OdooClient
{
// You can force nenewing a Client based on createdAt
if (!$this->client) {
$this->client = $this->createClient();
}
return $this->client;
}
}
$client->version();
$criteria = [
['customer', '=', true],
];
$offset = 0;
$limit = 10;
$client->search('res.partner', $criteria, $offset, $limit);
$criteria = [
['customer', '=', true],
];
$client->search_count('res.partner', $criteria);
$ids = $client->search('res.partner', [['customer', '=', true]], 0, 10);
$fields = ['name', 'email', 'customer'];
$customers = $client->read('res.partner', $ids, $fields);
$criteria = [
['customer', '=', true],
];
$fields = ['name', 'email', 'customer'];
$customers = $client->search_read('res.partner', $criteria, $fields, 10);
$data = [
'name' => 'John Doe',
'email' => '[email protected] ',
];
$id = $client->create('res.partner', $data);
// change email address of user with current email address [email protected]
$ids = $client->search('res.partner', [['email', '=', '[email protected] ']], 0, 1);
$client->write('res.partner', $ids, ['email' => '[email protected] ']);
// 'uncustomer' the first 10 customers
$ids = $client->search('res.partner', [['customer', '=', true]], 0, 10);
$client->write('res.partner', $ids, ['customer' => false]);
$ids = $client->search('res.partner', [['email', '=', '[email protected] ']], 0, 1);
$client->unlink('res.partner', $ids);