/** * * @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 $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 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'); } }