Skip to content

Commit

Permalink
Fix pages provider
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Oct 11, 2024
1 parent e1a81c6 commit dcbffe1
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
1 change: 0 additions & 1 deletion config/feed_routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
->controller(['webgriffe_sylius_clerk_plugin.controller.feed', '__invoke'])
->methods(['GET'])
->requirements([
'channelCode' => '\d+',
'localeCode' => '^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$',
'resourceValue' => class_exists(EnumRequirement::class) ? new EnumRequirement(Resource::class) : 'products|categories|orders|customers|pages',
])
Expand Down
5 changes: 5 additions & 0 deletions config/services/generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
->args([
service('webgriffe_sylius_clerk_plugin.provider.products'),
service('serializer'),
service('webgriffe_sylius_clerk_plugin.logger'),
'products',
])
;
Expand All @@ -39,6 +40,7 @@
->args([
service('webgriffe_sylius_clerk_plugin.provider.categories'),
service('serializer'),
service('webgriffe_sylius_clerk_plugin.logger'),
'categories',
])
;
Expand All @@ -47,6 +49,7 @@
->args([
service('webgriffe_sylius_clerk_plugin.provider.orders'),
service('serializer'),
service('webgriffe_sylius_clerk_plugin.logger'),
'orders',
])
;
Expand All @@ -55,6 +58,7 @@
->args([
service('webgriffe_sylius_clerk_plugin.provider.customers'),
service('serializer'),
service('webgriffe_sylius_clerk_plugin.logger'),
'customers',
])
;
Expand All @@ -63,6 +67,7 @@
->args([
service('webgriffe_sylius_clerk_plugin.provider.pages'),
service('serializer'),
service('webgriffe_sylius_clerk_plugin.logger'),
'pages',
])
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public function generate(
/** @var object[] $feedObjects */
$feedObjects = $this->resourceProvider->provide($channel, $localeCode, $modifiedAfter, $limit, $offset);

$this->logger->debug(
sprintf(
'Found %d objects for the %s feed',
count($feedObjects),
$this->resource->value,
),
);

$payload = [];
foreach ($feedObjects as $feedObject) {
try {
Expand Down
19 changes: 5 additions & 14 deletions src/DataSyncInfrastructure/Provider/PagesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* url: string,
* title: string,
* text: string,
* image?: string,
* }>
* }&array<string, mixed>>
*/
final readonly class PagesProvider implements ResourceProviderInterface
{
Expand All @@ -28,8 +27,7 @@
* routeParameters: array,
* title: string,
* text: string,
* image?: string,
* }> $pages
* }&array<string, mixed>> $pages
*/
public function __construct(
private UrlGeneratorInterface $urlGenerator,
Expand All @@ -47,16 +45,10 @@ public function provide(
$pagesData = [];
foreach ($this->pages as $page) {
$pageData = [
'id' => $page['id'],
'type' => $page['type'],
'url' => $this->getPageUrl($page, $channel, $localeCode),
'title' => $page['title'],
'text' => $page['text'],
];
if (array_key_exists('image', $page)) {
$pageData['image'] = $page['image'];
}
$pagesData[] = $pageData;
unset($page['routeName'], $page['routeParameters']);
$pagesData[] = array_merge($page, $pageData);
}

return $pagesData;
Expand All @@ -70,8 +62,7 @@ public function provide(
* routeParameters: array,
* title: string,
* text: string,
* image?: string,
* } $page
* }&array<string, mixed> $page
*/
public function getPageUrl(array $page, ChannelInterface $channel, string $localeCode): string
{
Expand Down
3 changes: 0 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('text')
->isRequired()
->end()
->scalarNode('image')
->defaultNull()
->end()
->end()
->end()
->end()
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/WebgriffeSyliusClerkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function load(array $configs, ContainerBuilder $container): void
$apiKeysProviderServiceDefinition->setArgument('$storesConfiguration', $config['stores']);

$feedController = $container->getDefinition('webgriffe_sylius_clerk_plugin.controller.feed');
$feedController->setArgument('$isTokenAuthenticationEnabled', $config['storage_feed_path']);
$feedController->setArgument('$isTokenAuthenticationEnabled', $config['token_authentication_enabled']);

$generateFeedCommand = $container->getDefinition('webgriffe_sylius_clerk.command.generate_feed');
$generateFeedCommand->setArgument('$storagePath', $config['storage_feed_path']);
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ MAILER_DSN=null://null
MESSENGER_TRANSPORT_DSN=doctrine://default
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
###< symfony/messenger ###

WEBGRIFFE_SYLIUS_CLERK_PLUGIN_TOKEN_AUTHENTICATION_ENABLED=true
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ webgriffe_sylius_clerk:
storage_feed_path: '%kernel.project_dir%/public/feed/clerk.io'
image_type: 'main'
image_filter_to_apply: 'sylius_medium'
token_authentication_enabled: true
token_authentication_enabled: '%env(bool:WEBGRIFFE_SYLIUS_CLERK_PLUGIN_TOKEN_AUTHENTICATION_ENABLED)%'
stores:
- channel_code: WEB-US
public_api_key: public-key
Expand All @@ -19,4 +19,4 @@ webgriffe_sylius_clerk:
routeParameters: []
title: 'Homepage'
text: 'Welcome to our store!'
image: null

0 comments on commit dcbffe1

Please sign in to comment.