Skip to content

Commit

Permalink
fix: backend article preview 'shop' cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominikrt committed Jul 26, 2024
1 parent f5256ae commit 2dec4df
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions engine/Shopware/Plugins/Default/Core/Router/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Shopware\Models\Shop\Shop;
use Shopware\Models\Shop\Template;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;

class Shopware_Plugins_Core_Router_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
Expand All @@ -53,14 +54,15 @@ public function install()
public function onRouteStartup(Enlight_Controller_EventArgs $args)
{
$request = $args->getRequest();
$response = $args->getResponse();

if (str_starts_with($request->getPathInfo(), '/backend')
|| str_starts_with($request->getPathInfo(), '/api/')
) {
return;
}

$shop = $this->getShopByRequest($request);
$shop = $this->getShopByRequest($request, $response);

if (!$shop->getHost()) {
$shop->setHost($request->getHttpHost());
Expand Down Expand Up @@ -306,7 +308,7 @@ protected function upgradeShop($request, $response)
*
* @return Shop
*/
protected function getShopByRequest(Request $request)
protected function getShopByRequest(Request $request, Response $response)
{
$repository = $this->get(ModelManager::class)->getRepository(Shop::class);

Expand All @@ -317,6 +319,7 @@ protected function getShopByRequest(Request $request)

if ($shop === null && $request->getCookie('shop') !== null) {
$shop = $repository->getActiveById($request->getCookie('shop'));
$response->headers->clearCookie('shop');
}

if ($shop && $request->getCookie('shop') !== null && $request->getPost('__shop') === null) {
Expand Down

0 comments on commit 2dec4df

Please sign in to comment.