Example #1
0
 /**
  * Returns the url for the account administration iframe.
  * If the passed account is null, then the url will point to the start page where a new account can be created.
  *
  * @param NostoAccountMetaSingleSignOnInterface $sso the SSO meta data.
  * @param NostoAccountMetaIframeInterface $iframe the iframe meta data.
  * @param NostoAccount|null $account the account to return the url for.
  * @param array $params additional parameters to add to the iframe url.
  * @return string the iframe url.
  * @throws NostoException if the url cannot be created.
  */
 public function getUrl(NostoAccountMetaSingleSignOnInterface $sso, NostoAccountMetaIframeInterface $iframe, NostoAccount $account = null, array $params = array())
 {
     $queryParams = http_build_query(array_merge(array('lang' => $iframe->getLanguage()->getCode(), 'ps_version' => $iframe->getVersionPlatform(), 'nt_version' => $iframe->getVersionModule(), 'product_pu' => $iframe->getPreviewUrlProduct(), 'category_pu' => $iframe->getPreviewUrlCategory(), 'search_pu' => $iframe->getPreviewUrlSearch(), 'cart_pu' => $iframe->getPreviewUrlCart(), 'front_pu' => $iframe->getPreviewUrlFront(), 'shop_lang' => $iframe->getShopLanguage()->getCode(), 'shop_name' => $iframe->getShopName(), 'unique_id' => $iframe->getUniqueId(), 'fname' => $sso->getFirstName(), 'lname' => $sso->getLastName(), 'email' => $sso->getEmail(), 'missing_scopes' => !is_null($account) && !$account->isConnectedToNosto() ? implode(',', $account->getMissingScopes()) : ''), $params));
     if ($account !== null) {
         try {
             $service = new NostoServiceAccount();
             $url = $service->sso($account, $sso);
             $url .= '?' . $queryParams;
         } catch (NostoException $e) {
             // If the SSO fails, we show a "remove account" page to the user in order to
             // allow to remove Nosto and start over.
             // The only case when this should happen is when the api token for some
             // reason is invalid, which is the case when switching between environments.
             $url = NostoHttpRequest::buildUri($this->getBaseUrl() . self::IFRAME_URI_UNINSTALL . '?' . $queryParams, array('{platform}' => $sso->getPlatform()));
         }
     } else {
         $url = NostoHttpRequest::buildUri($this->getBaseUrl() . self::IFRAME_URI_INSTALL . '?' . $queryParams, array('{platform}' => $sso->getPlatform()));
     }
     return $url;
 }
Example #2
0
 /**
  * Removes an account with associated api tokens for the store.
  *
  * @param \NostoAccount $account the account to remove.
  * @param Store $store the store.
  *
  * @return bool true on success, false otherwise.
  */
 public function deleteAccount(\NostoAccount $account, Store $store)
 {
     if ((int) $store->getId() < 1) {
         return false;
     }
     $this->_config->delete(self::XML_PATH_ACCOUNT, ScopeInterface::SCOPE_STORES, $store->getId());
     $this->_config->delete(self::XML_PATH_TOKENS, ScopeInterface::SCOPE_STORES, $store->getId());
     try {
         // Notify Nosto that the account was deleted.
         $service = new \NostoServiceAccount();
         $service->delete($account);
     } catch (\NostoException $e) {
         // Failures are logged but not shown to the user.
         $this->_logger->error($e, ['exception' => $e]);
     }
     $store->resetConfig();
     return true;
 }