/** * * @param $exception Exception * * @throws Exception * @return void */ public function handleException($exception) { $this->request = new Enlight_Controller_Request_RequestHttp(); $this->response = new Enlight_Controller_Response_ResponseHttp(); if ($this->isModelException($exception)) { $path = Shopware()->Models()->getConfiguration()->getAttributeDir(); $result = $this->generateModels($path); if ($result['success'] === true) { $this->response->setRedirect($this->request->getRequestUri()); setcookie(self::redirectCookieString, true, time() + 5); $this->response->sendResponse(); exit; } else { die(sprintf("Failed to create the attribute models, please check the permissions of the '%s' directory", $path)); } } }
/** * * @param $exception \Exception * * @throws \Exception * @return void */ private function handleException($exception) { $request = new \Enlight_Controller_Request_RequestHttp(); $response = new \Enlight_Controller_Response_ResponseHttp(); if ($this->isModelException($exception)) { $generator = $this->container->get('models')->createModelGenerator(); $result = $generator->generateAttributeModels(); if ($result['success'] === true) { $response->setRedirect($request->getRequestUri()); setcookie(self::redirectCookieString, true, time() + 5); $response->sendResponse(); exit; } else { die(sprintf("Failed to create the attribute models, please check the permissions of the '%s' directory", $generator->getPath())); } } }
/** * @param \Enlight_Controller_Request_RequestHttp $request * @return \Shopware\Models\Shop\Shop */ public function getActiveByRequest($request) { /** @var $shop \Shopware\Models\Shop\Shop */ $shop = null; $host = $request->getHttpHost(); $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->getEntityManager()->detach($currentShop); if ($currentShop->getBasePath() === null) { $shop = $currentShop; } elseif (strpos($requestPath, $currentShop->getBasePath()) === 0) { $shop = $currentShop; break; } } if ($shop === null) { $builder = $this->getActiveQueryBuilder(); $builder->andWhere('shop.hosts LIKE :host') ->setParameter('host', '%' . $host . '%'); $shop = $builder->getQuery()->getOneOrNullResult(); } if ($shop !== null) { $this->fixActive($shop); } return $shop; }
/** * Refresh current users * * @param \Enlight_Controller_Request_RequestHttp $request */ public function refreshCurrentUsers($request) { $sql = 'INSERT INTO s_statistics_currentusers (`remoteaddr`, `page`, `time`, `userID`) VALUES (?, ?, NOW(), ?)'; Shopware()->Db()->query($sql, array( $request->getClientIp(false), $request->getParam('requestPage', $request->getRequestUri()), empty(Shopware()->Session()->sUserId) ? 0 : (int)Shopware()->Session()->sUserId )); }
/** * @param \Enlight_Controller_Request_RequestHttp $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; }
/** * @param Enlight_Controller_Request_RequestHttp $request * @param Enlight_Controller_Response_ResponseHttp $response */ protected function upgradeShop($request, $response) { $bootstrap = $this->Application()->Bootstrap(); $shop = $this->Application()->Shop(); $cookieKey = null; $cookieValue = null; switch (true) { case $request->getPost('sLanguage') !== null: $cookieKey = 'shop'; $cookieValue = $request->getPost('sLanguage'); break; case $request->getPost('sCurrency') !== null: $cookieKey = 'currency'; $cookieValue = $request->getPost('sCurrency'); break; case $request->getPost('__shop') !== null: $cookieKey = 'shop'; $cookieValue = $request->getPost('__shop'); break; case $request->getQuery('__shop') !== null: $cookieKey = 'shop'; $cookieValue = $request->getQuery('__shop'); break; case $request->getPost('__currency') !== null: $cookieKey = 'currency'; $cookieValue = $request->getPost('__currency'); break; case $request->getQuery('__template') !== null: $cookieKey = 'template'; $cookieValue = $request->getQuery('__template'); break; } // Redirect on shop change if ($cookieKey === 'shop') { /** @var $repository Shopware\Models\Shop\Repository */ $repository = Shopware()->Models()->getRepository('Shopware\\Models\\Shop\\Shop'); $newShop = $repository->getActiveById($cookieValue); if ($newShop !== null) { if ($newShop->getHost() !== null && $newShop->getHost() !== $shop->getHost() || $newShop->getBaseUrl() !== null && $newShop->getBaseUrl() !== $shop->getBaseUrl()) { $url = sprintf('%s://%s%s%s', $request::SCHEME_HTTP, $newShop->getHost(), $newShop->getBaseUrl(), '/'); $path = rtrim($newShop->getBasePath(), '/') . '/'; $response->setCookie($cookieKey, $cookieValue, 0, $path); $response->setRedirect($url); return; } } } // Refresh on shop change if ($cookieKey !== null && $cookieKey != 'template') { $path = rtrim($shop->getBasePath(), '/') . '/'; $response->setCookie($cookieKey, $cookieValue, 0, $path); if ($request->isPost() && $request->getQuery('__shop') === null) { $url = sprintf('%s://%s%s', $request->getScheme(), $request->getHttpHost(), $request->getRequestUri()); $response->setRedirect($url); return; } } // Upgrade currency if ($request->getCookie('currency') !== null) { $currencyValue = $request->getCookie('currency'); foreach ($shop->getCurrencies() as $currency) { if ($currencyValue == $currency->getId() || $currencyValue == $currency->getCurrency()) { $shop->setCurrency($currency); break; } } } // Start session in frontend controllers $session = Shopware()->Session(); if ($cookieKey !== null) { $session->{$cookieKey} = $cookieValue; } // Refresh basket on currency change if (isset($session->sBasketCurrency) && $shop->getCurrency()->getId() != $session->sBasketCurrency) { Shopware()->Modules()->Basket()->sRefreshBasket(); } // Upgrade template if (isset($session->template) && !empty($session->Admin)) { $repository = 'Shopware\\Models\\Shop\\Template'; $repository = Shopware()->Models()->getRepository($repository); $template = $session->template; $template = $repository->findOneBy(array('template' => $template)); if ($template !== null) { $shop->setTemplate($template); } else { unset($session->template); } } else { unset($session->template); } // Save upgrades $shop->registerResources($bootstrap); if ($request->isSecure()) { $template = $bootstrap->getResource('Template'); $template->setCompileId($template->getCompileId() . '_secure'); } }