Skip to content

Commit

Permalink
FFWEB-3335: Remove unnecessary star (*) search requests
Browse files Browse the repository at this point in the history
Remove unnecessary star (*) search requests on dev env mode
  • Loading branch information
Rayn93 committed Feb 25, 2025
1 parent e31c8ce commit e9b6e55
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
### Add
- Support Proxy feature for Server Side Rendering

### Change
- Update FactFinder logo icon

### Fix
- Fix Proxy issue on PDP and for tracking requests
- Handle ClientException for SSR (invalid credentials, API issue etc.)
- Fix price slider filter closing
- Remove unnecessary star (*) search requests on dev env mode

## [v5.2.2] - 2024.10.09
### Improve
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ This is useful especially in terms of SEO because `ff-record-list` renders produ
Without SSR enabled, web crawlers could not have a chance to scan the element rendered content because it will not yet be rendered on the time of scanning.

**Note:** More information about SSR concept you can find in the article [Server Side Rendering](https://web-components.fact-finder.de/documentation/4.x/server-side-rendering) from Web Components documentation.
**Note:** If you have a problem with displaying product images or prices correctly, you probably have Field Roles set incorrectly. You can easily fix this by setting [custom fields roles](#set-custom-field-roles)

## Advanced Settings

Expand Down
25 changes: 21 additions & 4 deletions src/Config/CachedFieldRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@ class CachedFieldRoles implements FieldRolesInterface
{
private FieldRolesInterface $decorated;
private AdapterInterface $cache;
private string $kernelEnv;
private array $defaultFieldRoles;

public function __construct(FieldRolesInterface $decorated, AdapterInterface $cache)
{
$this->decorated = $decorated;
$this->cache = $cache;
public function __construct(
FieldRolesInterface $decorated,
AdapterInterface $cache,
string $kernelEnv,
array $fieldRoles,
) {
$this->decorated = $decorated;
$this->cache = $cache;
$this->kernelEnv = $kernelEnv;
$this->defaultFieldRoles = $fieldRoles;
}

public function getRoles(?string $salesChannelId): array
{
if ($this->isDevEnv()) {
return $this->defaultFieldRoles;
}

$salesChannelId = $salesChannelId ?? '';
$cacheKey = $this->getCacheKey($salesChannelId);
$item = $this->cache->getItem($cacheKey);
Expand Down Expand Up @@ -51,4 +63,9 @@ private function getCacheKey(string $salesChannelId): string
{
return sprintf('factfinder-field-roles-%s', $salesChannelId);
}

private function isDevEnv(): bool
{
return $this->kernelEnv === 'dev';
}
}
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<bind key="$cache" type="service" id="cache.object" />
<bind key="$container" type="service" id="service_container" />
<bind key="$factfinderLogger" type="service" id="monolog.logger.factfinder_channel" />
<bind key="$kernelEnv">%kernel.environment%</bind>
</defaults>

<service id="Omikron\FactFinder\Shopware6\Communication\AdapterFactory" />
Expand Down
8 changes: 5 additions & 3 deletions src/Utilites/Ssr/PriceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PriceFormatter
private SalesChannelService $channelService;
private SalesChannelContext $context;
private CurrencyFormatter $currencyFormatter;
private array $fieldRoles;
private CachedFieldRoles $fieldRolesService;
private array $defaultFieldRoles;

public function __construct(
Expand All @@ -26,7 +26,7 @@ public function __construct(
$this->channelService = $channelService;
$this->currencyFormatter = $currencyFormatter;
$this->context = $this->channelService->getSalesChannelContext();
$this->fieldRoles = $fieldRolesService->getRoles($this->context->getSalesChannelId());
$this->fieldRolesService = $fieldRolesService;
$this->defaultFieldRoles = $fieldRoles;
}

Expand Down Expand Up @@ -71,7 +71,9 @@ private function getFormattedPrice(float $price): string

private function getPriceField(): string
{
return $this->fieldRoles['price'] ?? $this->defaultFieldRoles['price'] ?? 'Price';
$fieldRoles = $this->fieldRolesService->getRoles($this->context->getSalesChannelId());

return $fieldRoles['price'] ?? $this->defaultFieldRoles['price'] ?? 'Price';
}

private function convertRecord(array $record): array
Expand Down

0 comments on commit e9b6e55

Please sign in to comment.