public function appStoreConnect()

in 2.0.x-2.2.x/upload/catalog/controller/module/facebook_business.php [99:137]


    public function appStoreConnect() {
        $json = array();

        $this->load->model('module/facebook_business');

        if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['store_url']) && isset($this->request->post['username']) && isset($this->request->post['password'])) {
            if (strpos(HTTPS_SERVER, $this->request->post['store_url']) !== false && $this->model_module_facebook_business->isVerifiedAdminUser($this->request->post['username'], $this->request->post['password'])) {
                if ($this->model_module_facebook_business->isExtensionInstalled()) {
                    if ($this->config->get('facebook_fbe_v2_installed')) {
                        $json['error'] = 'Your store is already connected to a Facebook Business Page.';
                    } elseif (!$this->model_module_facebook_business->isVerifiedAdminUser($this->request->post['username'], $this->request->post['password'], 'module/facebook_business')) {
                        $json['error'] = 'OpenCart Admin user does not have the correct permissions to perform this action!';
                    }
                } elseif (!$this->model_module_facebook_business->isVerifiedAdminUser($this->request->post['username'], $this->request->post['password'], 'extension/module', true)) {
                    $json['error'] = 'OpenCart Admin user does not have the correct permissions to perform this action!';
                }

                if (!$json) {
                    $json['success'] = true;
                    $json['fbe_params'] = array(
                        'external_business_id' => HTTPS_SERVER,
                        'business_name'        => $this->config->get('config_name') ? $this->config->get('config_name') : 'My Business',
                        'feed_url'             => $this->url->link('module/facebook_business/genFeed', '', true),
                        'feed_ping_url'        => $this->url->link('module/facebook_business/genFeedPing', '', true),
                        'timezone'             => date_default_timezone_get(),
                        'currency'             => strtoupper(addslashes($this->config->get('config_currency'))),
                        'version'              => $this->model_module_facebook_business->getPluginVersion()
                    );
                }
            } else {
                $json['error'] = 'OpenCart Store verification failed!';
            }
        } else {
            $json['error'] = 'Invalid parameters provided! Please contact OpenCart support for assistance.';
        }

        $this->response->addHeader('Content-Type: application/json');
        $this->response->setOutput(json_encode($json));
    }