roykin/override/classes/Customer.php
2017-06-14 11:41:31 +02:00

108 lines
6.1 KiB
PHP
Executable File

<?php
class Customer extends CustomerCore
{
public $id_erp;
public $representant;
public static $definition = array(
'table' => 'customer',
'primary' => 'id_customer',
'fields' => array(
'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5', 'copy_post' => false),
'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128),
'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 32),
'last_passwd_gen' => array('type' => self::TYPE_STRING, 'copy_post' => false),
'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate'),
'newsletter' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'newsletter_date_add' => array('type' => self::TYPE_DATE,'copy_post' => false),
'ip_registration_newsletter' => array('type' => self::TYPE_STRING, 'copy_post' => false),
'optin' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'website' => array('type' => self::TYPE_STRING, 'validate' => 'isUrl'),
'company' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'),
'siret' => array('type' => self::TYPE_STRING, 'validate' => 'isSiret'),
'ape' => array('type' => self::TYPE_STRING, 'validate' => 'isApe'),
'outstanding_allow_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'copy_post' => false),
'show_public_prices' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'id_risk' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
'max_payment_days' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'note' => array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'size' => 65000, 'copy_post' => false),
'is_guest' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
'id_shop_group' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
'id_default_group' => array('type' => self::TYPE_INT, 'copy_post' => false),
'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false),
// ADD ERP INPUT
'id_erp' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'copy_post' => false),
'representant' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'copy_post' => false),
),
);
public static function getCustomerIdByIdErp($id_erp)
{
$id_customer = Db::getInstance()->getValue(
'SELECT `id_customer`
FROM `'._DB_PREFIX_.'customer`
WHERE `id_erp` =' .(int) $id_erp
);
if ($id_customer) {
return new Customer($id_customer);
}
return false;
}
public function getAdressErp()
{
$id = Db::getInstance()->getValue('
SELECT `id_address`
FROM `'._DB_PREFIX_.'address`
WHERE `id_customer` = '.(int) $this->id.'
AND `is_erp` = 1
');
if (!$id) {
return false;
}
return new Address($id);
}
private static $_customer_groups_cat_reduc = array();
public function getGroupsCategoriesReduction()
{
$id_customer = $this->id;
if (isset(self::$_customer_groups_cat_reduc[$id_customer])) {
return self::$_customer_groups_cat_reduc[$id_customer];
}
self::$_customer_groups_cat_reduc[$id_customer] = array();
$result = Db::getInstance()->executeS('
SELECT cg.`id_group`, gr.`id_category`
FROM '._DB_PREFIX_.'customer_group cg
JOIN '._DB_PREFIX_.'group_reduction gr ON gr.id_group = cg.id_group
WHERE cg.`id_customer` = '.(int)$this->id
);
foreach ($result as $group) {
if (!isset(self::$_customer_groups_cat_reduc[$id_customer][$group['id_group']])) {
self::$_customer_groups_cat_reduc[$id_customer][$group['id_group']] = array();
}
self::$_customer_groups_cat_reduc[$id_customer][$group['id_group']][] = (int)$group['id_category'];
}
if(!isset(self::$_customer_groups_cat_reduc[$id_customer][Configuration::get('PS_CUSTOMER_GROUP')])) {
self::$_customer_groups_cat_reduc[$id_customer][Configuration::get('PS_CUSTOMER_GROUP')] = array();
}
return self::$_customer_groups_cat_reduc[$id_customer];
}
}