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 NostoAccountMetaDataIframeInterface $meta 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(NostoAccountMetaDataIframeInterface $meta, NostoAccountInterface $account = null, array $params = array())
 {
     $defaultParameters = array('lang' => strtolower($meta->getLanguageIsoCode()), 'ps_version' => $meta->getVersionPlatform(), 'nt_version' => $meta->getVersionModule(), 'product_pu' => $meta->getPreviewUrlProduct(), 'category_pu' => $meta->getPreviewUrlCategory(), 'search_pu' => $meta->getPreviewUrlSearch(), 'cart_pu' => $meta->getPreviewUrlCart(), 'front_pu' => $meta->getPreviewUrlFront(), 'shop_lang' => strtolower($meta->getLanguageIsoCodeShop()), 'shop_name' => $meta->getShopName(), 'unique_id' => $meta->getUniqueId(), 'fname' => $meta->getFirstName(), 'lname' => $meta->getLastName(), 'email' => $meta->getEmail());
     if ($account instanceof NostoAccountInterface) {
         $missingScopes = $account->getMissingTokens();
         if (!empty($missingScopes)) {
             $defaultParameters['missing_scopes'] = implode(',', $missingScopes);
         }
     }
     $queryParams = http_build_query(array_merge($defaultParameters, $params));
     if ($account !== null && $account->isConnectedToNosto()) {
         try {
             $url = $account->ssoLogin($meta) . '?' . $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}' => $meta->getPlatform()));
         }
     } else {
         $url = NostoHttpRequest::buildUri($this->getBaseUrl() . self::IFRAME_URI_INSTALL . '?' . $queryParams, array('{platform}' => $meta->getPlatform()));
     }
     return $url;
 }