Skip to content

Commit ba2a8bf

Browse files
committed
Release 1.0.5
1 parent 0ebdd4e commit ba2a8bf

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log for Sidworks Product Labels plugin
22
All notable changes to this module will be documented in this file.
33

4+
## 1.0.5 [13-01-2026]
5+
### Fixed
6+
- Caching for multiple languages on the same store
7+
48
## 1.0.4 [27-11-2025]
59
### Added
610
- 6.7 compatibility

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sidworks/sw-plugin-product-labels",
33
"description": "Sidworks product labels",
44
"type": "shopware-platform-plugin",
5-
"version": "1.0.4",
5+
"version": "1.0.5",
66
"require": {
77
"shopware/core": "~6.7.0"
88
},

src/Service/LabelStreamService.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ public function __construct(
3636

3737
public function getProductLabelStreamProducts(array $productIds, SalesChannelContext $context): array
3838
{
39+
$languageId = $context->getLanguageId();
40+
3941
// Check request-scoped cache first
40-
$requestCacheKey = $this->getCacheKey($productIds, $context->getSalesChannelId());
42+
$requestCacheKey = $this->getCacheKey($productIds, $context->getSalesChannelId(), $languageId);
4143
if (isset($this->labelCache[$requestCacheKey])) {
4244
return $this->labelCache[$requestCacheKey];
4345
}
4446

4547
// Check persistent cache
46-
$persistentCacheKey = $this->getPersistentCacheKey($productIds, $context->getSalesChannelId());
48+
$persistentCacheKey = $this->getPersistentCacheKey($productIds, $context->getSalesChannelId(), $languageId);
4749

4850
$result = $this->cache->get($persistentCacheKey, function (ItemInterface $item) use ($productIds, $context) {
4951
$item->expiresAfter(self::CACHE_TTL);
@@ -114,14 +116,15 @@ public function applyLabelsToProduct($product, array $productLabelsStreamProduct
114116
private function fetchActiveProductLabels(Context $context): iterable
115117
{
116118
$salesChannelId = $context->getSource()->getSalesChannelId();
117-
$cacheKey = "active_labels_{$salesChannelId}";
119+
$languageId = $context->getLanguageId();
120+
$cacheKey = "active_labels_{$salesChannelId}_{$languageId}";
118121

119122
if (isset($this->labelCache[$cacheKey])) {
120123
return $this->labelCache[$cacheKey];
121124
}
122125

123126
// Use persistent cache for active labels
124-
$persistentCacheKey = self::CACHE_TAG_PREFIX . '-active-labels-' . $salesChannelId;
127+
$persistentCacheKey = self::CACHE_TAG_PREFIX . '-active-labels-' . $salesChannelId . '-' . $languageId;
125128

126129
$result = $this->cache->get($persistentCacheKey, function (ItemInterface $item) use ($salesChannelId, $context) {
127130
$item->expiresAfter(self::CACHE_TTL);
@@ -197,7 +200,7 @@ private function processVariantMatches(
197200

198201
private function matchProductsByStream(string $streamId, array $productIds, SalesChannelContext $context): array
199202
{
200-
$cacheKey = $this->getStreamCacheKey($streamId, $productIds, $context->getSalesChannelId());
203+
$cacheKey = $this->getStreamCacheKey($streamId, $productIds, $context->getSalesChannelId(), $context->getLanguageId());
201204

202205
if (isset($this->streamMatchCache[$cacheKey])) {
203206
return $this->streamMatchCache[$cacheKey];
@@ -218,7 +221,7 @@ private function matchProductsByStream(string $streamId, array $productIds, Sale
218221

219222
private function matchVariantsByStream(string $streamId, array $variantIds, array $variantToParent, SalesChannelContext $context): array
220223
{
221-
$cacheKey = $this->getStreamCacheKey($streamId, $variantIds, $context->getSalesChannelId()) . '_variants';
224+
$cacheKey = $this->getStreamCacheKey($streamId, $variantIds, $context->getSalesChannelId(), $context->getLanguageId()) . '_variants';
222225

223226
if (isset($this->streamMatchCache[$cacheKey])) {
224227
return $this->streamMatchCache[$cacheKey];
@@ -250,7 +253,7 @@ private function getVariantToParentMapping(array $productIds, SalesChannelContex
250253
return [];
251254
}
252255

253-
$cacheKey = $this->getCacheKey($productIds, $context->getSalesChannelId()) . '_variants';
256+
$cacheKey = $this->getCacheKey($productIds, $context->getSalesChannelId(), $context->getLanguageId()) . '_variants';
254257

255258
if (isset($this->variantMappingCache[$cacheKey])) {
256259
return $this->variantMappingCache[$cacheKey];
@@ -295,22 +298,22 @@ public function shouldShowProductLabel(ProductLabelsEntity $productLabel): bool
295298
};
296299
}
297300

298-
private function getCacheKey(array $productIds, string $salesChannelId): string
301+
private function getCacheKey(array $productIds, string $salesChannelId, string $languageId): string
299302
{
300303
sort($productIds); // Ensure consistent ordering for cache keys
301-
return md5(implode(',', $productIds) . $salesChannelId);
304+
return md5(implode(',', $productIds) . $salesChannelId . $languageId);
302305
}
303306

304-
private function getPersistentCacheKey(array $productIds, string $salesChannelId): string
307+
private function getPersistentCacheKey(array $productIds, string $salesChannelId, string $languageId): string
305308
{
306309
sort($productIds);
307-
return self::CACHE_TAG_PREFIX . '-products-' . md5(implode(',', $productIds) . $salesChannelId);
310+
return self::CACHE_TAG_PREFIX . '-products-' . md5(implode(',', $productIds) . $salesChannelId . $languageId);
308311
}
309312

310-
private function getStreamCacheKey(string $streamId, array $productIds, string $salesChannelId): string
313+
private function getStreamCacheKey(string $streamId, array $productIds, string $salesChannelId, string $languageId): string
311314
{
312315
sort($productIds);
313-
return md5($streamId . implode(',', $productIds) . $salesChannelId);
316+
return md5($streamId . implode(',', $productIds) . $salesChannelId . $languageId);
314317
}
315318

316319
/**

0 commit comments

Comments
 (0)