/** * @param string $requestUri * @param Request $request * @param Shop $shop * @return string */ private function removeShopBaseUrl($requestUri, Request $request, Shop $shop) { $url = $shop->getBaseUrl(); $path = $shop->getBasePath(); if ($request->isSecure()) { $url = $shop->getSecureBaseUrl(); $path = $shop->getSecureBasePath(); } $requestUri = $this->removePartOfUrl($requestUri, $url); $requestUri = $this->removePartOfUrl($requestUri, $path); return $requestUri; }
/** * @param \Enlight_Controller_Request_Request $request * @return \Shopware\Models\Shop\Shop */ public function getActiveByRequest($request) { /** @var $shop \Shopware\Models\Shop\Shop */ $shop = null; $host = $request->getHttpHost(); if (empty($host)) { return $shop; } $requestPath = $request->getRequestUri(); $builder = $this->getActiveQueryBuilder(); $builder->andWhere("shop.host=:host OR (shop.host IS NULL AND main.host=:host)"); if ($request->isSecure()) { $builder->orWhere("shop.secureHost=:host OR (shop.secureHost IS NULL AND main.secureHost=:host)"); } $builder->setParameter('host', $host); /** @var $shops \Shopware\Models\Shop\Shop[] */ $shops = $builder->getQuery()->getResult(); foreach ($shops as $currentShop) { $this->fixActive($currentShop); } //returns the right shop depending on the url $shop = $this->getShopByRequest($shops, $requestPath); if ($shop !== null) { return $shop; } $builder = $this->getActiveQueryBuilder(); $builder->andWhere('shop.hosts LIKE :host1 OR shop.hosts LIKE :host2 OR shop.hosts LIKE :host3')->setParameter('host1', "%\n" . $host . "\n%")->setParameter('host2', $host . "\n%")->setParameter('host3', "%\n" . $host); $shop = $builder->getQuery()->getOneOrNullResult(); if ($shop !== null) { $this->fixActive($shop); } return $shop; }