Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "netlogix/neos-content",
"description": "This plugin enables Shopware templates to be designed with an Enterprise CMS.",
"version": "0.1.48",
"version": "0.1.49",
"type": "shopware-platform-plugin",
"license": "MIT",
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function load(
if ($cacheInvalidationDto->getType() === CacheInvalidationDto::TYPE_ALL) {
$this->cacheInvalidationService->invalidateNeosCmsLayoutCaches([], $context);
$this->cacheInvalidationService->invalidateNavigationCaches();
$this->cacheInvalidationService->invalidateNeosPageCaches();
return new JsonResponse(['status' => 'Neos Content Cache invalidated']);
}

Expand All @@ -43,6 +44,7 @@ public function load(
} elseif ($cacheInvalidationDto->getType() === CacheInvalidationDto::TYPE_NAVIGATION)
{
$this->cacheInvalidationService->invalidateNavigationCaches();
$this->cacheInvalidationService->invalidateNeosPageCaches($cacheInvalidationDto->getData() ?? []);
}

return new JsonResponse(['status' => 'Neos Content Cache invalidated']);
Expand Down
2 changes: 2 additions & 0 deletions src/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use nlxNeosContent\Service\ConfigService;
use nlxNeosContent\Storefront\Controller\NeosPageController;
use Shopware\Core\PlatformRequest;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated;
Expand Down Expand Up @@ -71,6 +72,7 @@ protected function matchNeosPath(string $pathinfo): array
'neos' => 1,
'_routeScope' => ['storefront'],
'_controller' => NeosPageController::class . '::index',
PlatformRequest::ATTRIBUTE_HTTP_CACHE => true,
];
}

Expand Down
17 changes: 17 additions & 0 deletions src/Service/CachingInvalidationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


use nlxNeosContent\Neos\Endpoint\CachedNeosPageTreeLoader;
use nlxNeosContent\Storefront\Controller\NeosPageController;
use Shopware\Core\Content\Category\SalesChannel\NavigationRoute;
use Shopware\Core\Framework\Adapter\Cache\CacheInvalidator;
use Shopware\Core\Framework\Context;
Expand Down Expand Up @@ -54,4 +55,20 @@ public function invalidateNavigationCaches(): void
$this->cacheInvalidator->invalidateExpired();
$this->cacheInvalidator->invalidate(['nlxNeosContent']);
}

public function invalidateNeosPageCaches(array $identifiers = []): void
{
if (empty($identifiers)) {
$this->cacheInvalidator->invalidate([NeosPageController::CACHE_TAG_ALL]);

return;
}

$tags = array_map(
fn (string $identifier) => NeosPageController::getCacheTagFromIdentifier($identifier),
$identifiers
);

$this->cacheInvalidator->invalidate($tags);
}
}
24 changes: 19 additions & 5 deletions src/Storefront/Controller/NeosPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use nlxNeosContent\Service\ResolverContextService;
use Shopware\Core\Content\Category\CategoryDefinition;
use Shopware\Core\Content\Cms\CmsPageEntity;
use Shopware\Core\Framework\Adapter\Cache\CacheTagCollector;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Shopware\Storefront\Page\GenericPageLoader;
Expand All @@ -20,12 +21,16 @@

class NeosPageController extends StorefrontController
{
public const CACHE_TAG_ALL = 'nlx-cbp-page';
public const CACHE_TAG_PREFIX = 'nlx-cbp-page-';

function __construct(
private readonly ContentExchangeService $contentExchangeService,
private readonly ResolverContextService $resolverContextService,
private readonly NeosPageTreeService $neosPageTreeService,
#[Autowire(service: GenericPageLoader::class)]
private readonly GenericPageLoaderInterface $genericPageLoader,
private readonly CacheTagCollector $cacheTagCollector,
) {
}

Expand Down Expand Up @@ -57,11 +62,7 @@ function index(Request $request, SalesChannelContext $salesChannelContext): Resp

$treeItem = $this->neosPageTreeService->findNodeIdentifierForRequestAndContext($request, $salesChannelContext);
//Setting NavigationId so the navigation js can display the active page
$identifier = str_replace(
'-',
'',
$treeItem->identifier
);
$identifier = self::sanitizeNodeIdentifier($treeItem->identifier);
$request = $this->container->get('request_stack')->getCurrentRequest();
$request->attributes->set('navigationId', $identifier);
$request->attributes->set('_route', 'frontend.navigation.page');
Expand All @@ -74,10 +75,23 @@ function index(Request $request, SalesChannelContext $salesChannelContext): Resp
$page->getMetaInformation()->setMetaTitle($treeItem->label);
//TODO add missing Metadata

//Adding two cache tags, so we can invalidate a specific cached page or all of them
$this->cacheTagCollector->addTag(self::getCacheTagFromIdentifier($treeItem->identifier), self::CACHE_TAG_ALL);
return $this->renderStorefront('@Storefront/storefront/page/neosPage.html.twig', [
'page' => $page,
'cmsPage' => $cmsPage,
'landingPage' => []
]);
}

public static function sanitizeNodeIdentifier(string $identifier): string
{
return str_replace('-', '', $identifier);
}

public static function getCacheTagFromIdentifier(string $identifier): string
{
$identifier = self::sanitizeNodeIdentifier($identifier);
return self::CACHE_TAG_PREFIX . $identifier;
}
}