roykin/erp/ErpTools.php
Thibault UBUNTU daaa4ab9be fix
2016-03-24 16:34:45 +01:00

80 lines
1.8 KiB
PHP

<?php
class ErpTools
{
public static function alreadyExists($id_customer_erp)
{
return (boolean) Db::getInstance()->getValue('
SELECT `id_customer`
FROM `ps_customer`
WHERE `id_erp` = ' . (int) $id_customer_erp
);
}
public static function productAlreadyExists ($id_product_erp)
{
return (boolean) Db::getInstance()->getValue('
SELECT `id_product`
FROM `ps_product`
WHERE `id_erp` = ' . (int) $id_product_erp
);
}
public static function getCountryIdForPresta($id_country_odoo)
{
/**
* Association country Odoo - Prestashop
* 76 > France
* 21 > Belgique
* 44 > Suisse
* 114 > Japon
* 137 > Maroc
* 13 > Autriche
*/
$assoc_country = array(
76 => 8,
21 => 3,
44 => 19,
114 => 11,
137 => 152,
13 => 2,
);
if (isset($assoc_country[$id_country_odoo])) {
return $assoc_country[$id_country_odoo];
} else {
return false;
}
}
public static function validateRecordCustomer($record)
{
if (empty($record['city'])) {
return false;
}
if (empty($record['phone'])) {
return false;
}
if(!Validate::isPhoneNumber($record['phone'])) {
return false;
}
return true;
}
public static function logError($record)
{
Db::getInstance()->execute('
INSERT INTO
`ps_erp_log` (`data`, `date_add`)
VALUES (
'.json_encode($record).',
NOW()
)'
);
return true;
}
}