public function connectAdmin($user_data, $is_reconnect = false)
 {
     if (!$this->_initHisPublicKey()) {
         return false;
     }
     $store_info = self::getAdminUrls();
     if (!$is_reconnect && !self::_needToConnect($store_info)) {
         return false;
     }
     $meta = array();
     // Connect admin panel
     $data = array('public_key' => $this->getMyPublicKey(), 'addon_version' => TWIGMO_VERSION, 'engine' => 'cscart', 'engine_version' => PRODUCT_VERSION, 'engine_meta' => PRODUCT_EDITION, 'saas_uid' => fn_twg_get_saas_uid(), 'name' => Registry::get('settings.Company.company_name'));
     if ($store_info['access_id']) {
         $meta['access_id'] = $store_info['access_id'];
     } else {
         $data = array_merge($data, fn_get_user_info($user_data['user_id']));
         $data = array_merge($data, array('email' => $user_data['email'], 'password' => $user_data['password']));
     }
     $data = array_merge($data, $store_info);
     self::_setConnectTTL();
     $response = $this->send('connect.admin', $data, $meta);
     if (!$this->responseIsOk($response) or empty($response['data']['access_id'])) {
         self::_setConnectionErrorNotification();
         return false;
     }
     $new_options = array('version' => TWIGMO_VERSION, 'admin_connection' => array('access_id' => $response['data']['access_id'], 'url' => $data['url']));
     if (!empty($user_data['email'])) {
         $new_options['email'] = $user_data['email'];
     }
     if ($store_info['access_id'] && $response['data']['access_id'] != $store_info['access_id']) {
         // access_id changed - we have to disconnect storefronts
         $customer_connections = TwigmoSettings::get('customer_connections');
         if (is_array($customer_connections)) {
             foreach ($customer_connections as $company_id => $customer_connection) {
                 $customer_connections[$company_id]['access_id'] = '';
             }
             $new_options['customer_connections'] = $customer_connections;
         }
     }
     TwigmoSettings::set($new_options);
     return true;
 }
Exemple #2
0
function fn_twg_is_on_saas()
{
    $saas_uid = fn_twg_get_saas_uid();
    return !empty($saas_uid);
}