Beispiel #1
0
 /**
  * @param Request $request
  * @param Shop $newShop
  * @return string
  */
 protected function getNewShopUrl(Request $request, Shop $newShop)
 {
     $repository = Shopware()->Models()->getRepository('Shopware\\Models\\Shop\\Shop');
     $requestShop = $repository->getActiveByRequest($request);
     // Remove baseUrl from request url
     $url = $request->getRequestUri();
     if ($requestShop && strpos($url, $requestShop->getBaseUrl()) === 0) {
         $url = substr($url, strlen($requestShop->getBaseUrl()));
     }
     $baseUrl = $request->getBaseUrl();
     if (strpos($url, $baseUrl) === 0) {
         $url = substr($url, strlen($baseUrl));
     }
     $basePath = $newShop->getBasePath();
     if (strpos($url, $basePath) === 0) {
         $url = substr($url, strlen($basePath));
     }
     $host = $newShop->getHost();
     $baseUrl = $newShop->getBaseUrl() ?: $request->getBasePath();
     if ($request->isSecure()) {
         $host = $newShop->getSecureHost() ?: $newShop->getHost();
         if ($newShop->getSecureBaseUrl()) {
             $baseUrl = $newShop->getSecureBaseUrl();
         } elseif ($newShop->getBaseUrl()) {
             $baseUrl = $newShop->getBaseUrl();
         } else {
             $baseUrl = $request->getBaseUrl();
         }
     }
     $host = trim($host, '/');
     $baseUrl = trim($baseUrl, '/');
     if (!empty($baseUrl)) {
         $baseUrl = '/' . $baseUrl;
     }
     $url = ltrim($url, '/');
     if (!empty($url)) {
         $url = '/' . $url;
     }
     //build full redirect url to allow host switches
     return sprintf('%s://%s%s%s', $request->getScheme(), $host, $baseUrl, $url);
 }