/** * Sets the shopware cache headers */ public function setCacheHeaders() { $controllerName = strtolower($this->request->getModuleName()) . '/' . strtolower($this->request->getControllerName()); $cacheControllers = $this->getCacheControllers(); if (!isset($cacheControllers[$controllerName])) { return false; } if (strpos($this->request->getPathInfo(), '/widgets/index/refreshStatistic') !== false) { return false; } if (strpos($this->request->getPathInfo(), '/captcha/index/rand/') !== false) { return false; } $allowNoCache = $this->getNoCacheTagsForController($controllerName); $noCacheCookies = $this->getNoCacheTagsFromCookie($this->request); $hasMatchingNoCacheCookie = $this->hasArrayIntersection($allowNoCache, $noCacheCookies); // Enable esi tag output $this->registerEsiRenderer(); if ($this->response->isRedirect()) { $this->response->setHeader('Cache-Control', 'private, no-cache'); return false; } if ($hasMatchingNoCacheCookie) { $this->response->setHeader('Cache-Control', 'private, no-cache'); return false; } $allowNoCacheControllers = $this->getAllowNoCacheControllers(); if (isset($allowNoCacheControllers[$controllerName]) && $this->request->getQuery('nocache') !== null) { $this->response->setHeader('Cache-Control', 'private, no-cache'); return false; } // NEVER cache a filled mini-basket if ($controllerName == 'widgets/checkout' && !empty(Shopware()->Session()->sBasketQuantity)) { $this->response->setHeader('Cache-Control', 'private, no-cache'); return false; } $cacheTime = (int) $cacheControllers[$controllerName]; $this->request->setParam('__cache', $cacheTime); $this->response->setHeader('Cache-Control', 'public, max-age=' . $cacheTime . ', s-maxage=' . $cacheTime, true); if (!empty($allowNoCache)) { $this->response->setHeader('x-shopware-allow-nocache', implode(', ', $allowNoCache)); } return true; }
/** * @param Request $request * @param Criteria $criteria * @param ShopContextInterface $context */ public function handleRequest(Request $request, Criteria $criteria, ShopContextInterface $context) { $requestedCategoryId = $request->getParam('sCategory', $request->getParam('categoryId', false)); if (!$requestedCategoryId) { return; } $closestIdWithRules = $this->databaseAdapter->fetchClosestCategoryIdWithRule($requestedCategoryId); if (!$closestIdWithRules) { return; } $this->enabled = true; if ($request->sSort && $request->sSort != self::REQUEST_VALUE) { return; } $request->setParam('sSort', self::REQUEST_VALUE); $rules = $this->ruleHydrator->createRuleVos($this->databaseAdapter->fetchRawData($closestIdWithRules)); $criteria->resetSorting(); $criteria->addSorting(new DefaultSorting($rules)); }
/** * @param Enlight_Controller_Request_RequestHttp $request */ protected function fixRequest($request) { $aliases = array('sViewport' => 'controller', 'sAction' => 'action'); foreach ($aliases as $key => $alias) { if (($value = $request->getParam($key)) !== null) { $request->setParam($alias, $value); $request->setAlias($key, $alias); } } $request->setQuery($request->getUserParams() + $request->getQuery()); }
/** * Sets the shopware cache headers */ public function setCacheHeaders() { $controllerName = $this->request->getModuleName() . '/' . $this->request->getControllerName(); if(isset($this->cacheControllers[$controllerName])) { // Enable esi tag output $this->registerEsiRenderer(); } if ((isset($this->allowNoCacheControllers[$controllerName]) && $this->request->getQuery('nocache') !== null) || $this->response->isRedirect() || (!$this->request->getParam('rewriteUrl') && isset($this->controllerOptions[$controllerName])) ) { $this->response->setHeader('Cache-Control', 'private, no-cache'); } elseif (isset($this->cacheControllers[$controllerName])) { $cacheTime = (int)$this->cacheControllers[$controllerName]; $this->request->setParam('__cache', $cacheTime); $this->response->setHeader('Cache-Control', 'public, max-age=' . $cacheTime . ', s-maxage=' . $cacheTime); } $shopId = Shopware()->Shop()->getId(); $allowNoCache = array(); if(!empty($this->Config()->admin)) { $allowNoCache[] = 'admin-' . $shopId; } if (isset($this->allowNoCacheControllers[$controllerName])) { $allowNoCache[] = $this->allowNoCacheControllers[$controllerName] . '-' . $shopId; } if(!empty($allowNoCache)) { $this->response->setHeader('x-shopware-allow-nocache', implode(', ', $allowNoCache)); } }