public function saveAttributeConfiguration() { if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('GoogleShopping'), AccessManager::CREATE))) { return $response; } $message = null; $form = $this->createForm("googleshopping.attribute.configuration"); try { $data = $this->validateForm($form, 'POST')->getData(); GoogleShopping::setConfigValue('attribute_color', implode(',', $data['attribute_color'])); GoogleShopping::setConfigValue('attribute_size', implode(',', $data['attribute_size'])); return $this->generateRedirect('/admin/module/GoogleShopping'); } catch (\Exception $e) { $message = $e->getMessage(); } $this->setupFormErrorContext($this->getTranslator()->trans("GoogleShopping configuration", [], GoogleShopping::DOMAIN_NAME), $message, $form, $e); return $this->render('module-configure', array('module_code' => 'GoogleShopping')); }
public function setAuthorization() { $client = new \Google_Client(); $client->setAccessType('offline'); $client->setApplicationName(GoogleShopping::getConfigValue('application_name')); $client->setClientId(GoogleShopping::getConfigValue('client_id')); $client->setClientSecret(GoogleShopping::getConfigValue('client_secret')); $client->setRedirectUri(URL::getInstance()->absoluteUrl('/googleshopping/oauth2callback')); $client->setScopes('https://www.googleapis.com/auth/content'); $oAuthToken = GoogleShopping::getConfigValue('oauth_access_token'); $code = $this->getRequest()->query->get('code'); $redirection = '/admin/module/GoogleShopping'; //Manage redirection after auth if ($url = $this->getRequest()->query->get('redirect')) { $redirection = $url; $this->getSession()->set('google_action_url', $redirection); } if (isset($oAuthToken)) { $client->setAccessToken($oAuthToken); if ($client->isAccessTokenExpired()) { $client->refreshToken(GoogleShopping::getConfigValue('oauth_refresh_token')); $newToken = $client->getAccessToken(); GoogleShopping::setConfigValue('oauth_access_token', $newToken); } return $this->generateRedirect($redirection); } elseif (isset($code)) { $client->authenticate($code); $token = $client->getAccessToken(); $refreshToken = $client->getRefreshToken(); GoogleShopping::setConfigValue('oauth_access_token', $token); if ($refreshToken) { GoogleShopping::setConfigValue('oauth_refresh_token', $refreshToken); } return $this->generateRedirect($redirection); } else { return $this->generateRedirect($client->createAuthUrl()); } }