public function __construct($id_empreendimento)
 {
     $this->debug = false;
     $ConfiguracaoDao = new ConfiguracaoDao();
     $config = $ConfiguracaoDao->getConfiguracoes($id_empreendimento);
     if (empty(getKeyArr($config, 'prestashop_ws_auth_key')) || empty(getKeyArr($config, 'prestashop_shop_path'))) {
         throw new Exception('PrestaShop não configurado');
     }
     $this->ps_shop_path = getKeyArr($config, 'prestashop_shop_path');
     $this->ps_ws_auth_key = getKeyArr($config, 'prestashop_ws_auth_key');
     $this->webService = new PrestaShopWebservice($this->ps_shop_path, $this->ps_ws_auth_key, $this->debug);
 }
 public static function requestUpdateUsuario()
 {
     try {
         $usuario = $_POST['usuario'];
         $id_empreendimento = $_POST['id_empreendimento'];
         $ReferenciaIntegracaoDao = new ReferenciaIntegracaoDao();
         $ReferenciaIntegracaoTO = new ReferenciaIntegracaoTO();
         $PrestaShopDao = new PrestaShopDao($id_empreendimento);
         $ClienteDao = new ClienteDao();
         $ClienteTO = new stdClass();
         $ReferenciaIntegracaoTO = new ReferenciaIntegracaoTO();
         $ReferenciaIntegracaoTO->sistema_integrado = 'PrestaShop';
         $ReferenciaIntegracaoTO->tabela = 'tbl_usuarios';
         $ReferenciaIntegracaoTO->id_item_referencia = $usuario['id'];
         $ReferenciaIntegracaoTO->tipo = 'usuario';
         $ReferenciaIntegracaoTO->id_empreendimento = $id_empreendimento;
         $referencia = $ReferenciaIntegracaoDao->refExists($ReferenciaIntegracaoTO, true);
         if (!$referencia) {
             self::requestSaveUsuario();
             return;
             //throw new Exception('Referencia não encontrada', 1);
         }
         $ClienteTO->nome = getKeyArr($usuario, 'firstname');
         $ClienteTO->apelido = getKeyArr($usuario, 'lastname');
         $ClienteTO->dta_nacimento = getKeyArr($usuario, 'birthday');
         $ClienteTO->email = getKeyArr($usuario, 'email');
         if (!$ClienteDao->clienteUpdate($ClienteTO, 'id=' . $referencia['id_item'])) {
             throw new Exception('Erro ao atualizar usuario', 1);
         }
         $AutenticacaoTO = new AutenticacaoTO();
         $AutenticacaoTO->id_usuario = $usuario['id'];
         $AutenticacaoTO->senha = getKeyArr($usuario, 'passwd');
         $AutenticacaoTO->login = getKeyArr($usuario, 'email');
         if (!empty($AutenticacaoTO->senha) && !empty($AutenticacaoTO->login)) {
             if (!$ClienteDao->saveAutenticacao($AutenticacaoTO)) {
                 throw new Exception('Erro ao inserir Autenticacao');
             }
         }
     } catch (Exception $e) {
         $log = new KLogger("logs/logErrorPrestaShop.txt", KLogger::DEBUG);
         $log->LogError($e->getMessage() . '- file:' . $e->getFile() . ' - line:' . $e->getLine());
         $log->LogDebug(json_encode($_POST));
         $log->LogJunp();
         Flight::halt(500, $e->getMessage());
     }
 }